c#.net实现Smartphone,PocketPC进程启动

using System;
using System.Runtime.InteropServices;
using System.Text;

namespace RDP
{
 /// <summary>
 /// Utility class for launch programs and files.
 /// </summary>
 public class ShellExecute
 {
    public static void Start(string fileName, string parameters)
    {
      int nSize;
      SHELLEXECUTEEX see;
      IntPtr pFile;
      IntPtr pParams;

      see = new SHELLEXECUTEEX();

      nSize = fileName.Length * 2 + 2;
      pFile = localAlloc(MemoryAllocFlags.LPtr, nSize);
      Marshal.Copy(Encoding.Unicode.GetBytes(fileName), 0, pFile, nSize - 2);

      nSize = parameters.Length * 2 + 2;
      pParams = localAlloc(MemoryAllocFlags.LPtr, nSize);
      Marshal.Copy(Encoding.Unicode.GetBytes(parameters), 0, pParams, nSize - 2);
   
      see.lpFile = pFile;
      see.lpParameters = pParams;
   
      ShellExecuteEx(see);

      LocalFree(pFile);
      LocalFree(pParams);
      //return see.hProcess;
    }

    public static void Start(string fileName)
    {
      Start(fileName, "");
    }

    private static IntPtr localAlloc(MemoryAllocFlags uFlags, int uBytes)
    {
      const int GMEM_FIXED = 0x0000;
      const int LMEM_ZEROINIT  = 0x0040;
      const int LPTR = (GMEM_FIXED | LMEM_ZEROINIT);

      IntPtr ptr = LocalAlloc(LPTR, (uint)uBytes);
      if (ptr == IntPtr.Zero)
        throw new Exception("Out of memory!");
      return ptr;
    }

    private enum MemoryAllocFlags : int
    {
      Fixed   = 0x00,
      ZeroInit = 0x40,
      LPtr     = ZeroInit | Fixed
    }

    #region APIs
    [DllImport("coredll.dll")]
    private static extern IntPtr LocalAlloc(uint uFlags, uint Bytes);

    [DllImport("coredll")]
    private static extern IntPtr LocalFree(IntPtr hMem);

    [DllImport("coredll")]
    private extern static int ShellExecuteEx( SHELLEXECUTEEX ex );

    private class SHELLEXECUTEEX
    {
      public UInt32 cbSize  = 60;
      public UInt32 fMask   = 0;
      public IntPtr hwnd   = IntPtr.Zero;
      public IntPtr lpVerb  = IntPtr.Zero;
      public IntPtr lpFile  = IntPtr.Zero;
      public IntPtr lpParameters = IntPtr.Zero;
      public IntPtr lpDirectory = IntPtr.Zero;
      public int nShow   = 0;
      public IntPtr hInstApp  = IntPtr.Zero;
      public IntPtr lpIDList  = IntPtr.Zero;
      public IntPtr lpClass  = IntPtr.Zero;
      public IntPtr hkeyClass  = IntPtr.Zero;
      public UInt32 dwHotKey  = 0;
      public IntPtr hIcon   = IntPtr.Zero;
      public IntPtr hProcess  = IntPtr.Zero;
    }
    #endregion
  }
}
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值