public class ProcessShowInfo
{
[DllImport("CoreDll.dll", SetLastError = true)]
private extern static
int CreateProcess(String imageName,
String cmdLine,
IntPtr lpProcessAttributes,
IntPtr lpThreadAttributes,
Int32 boolInheritHandles,
Int32 dwCreationFlags,
IntPtr lpEnvironment,
IntPtr lpszCurrentDir,
byte[] si,
ProcessInfo pi);
public class ProcessInfo
{
public IntPtr hProcess;
public IntPtr hThread;
public Int32 ProcessId;
public Int32 ThreadId;
}
public static bool CreateProcess(String ExeName, String CmdLine, ProcessInfo pi)
{
if (pi == null)
pi = new ProcessInfo();
byte[] si = new byte[128];
CreateProcess(ExeName, CmdLine, IntPtr.Zero, IntPtr.Zero, 0, 0, IntPtr.Zero, IntPtr.Zero, si, pi);
return true;
}
}
===========================
调用
string progPath = "//存储卡//Program Files//SetUphx_chq-mobile//hx_chq-mobile.exe";//文件路径
StartSystem.ProcessShowInfo.ProcessInfo pi = new StartSystem.ProcessShowInfo.ProcessInfo();
ProcessShowInfo.CreateProcess(progPath, "", pi);
if (pi.hProcess.ToString().Equals("0") || pi.ProcessId.ToString().Equals("0"))
{
MessageBox.Show("打开失败,请查看是否安装!");
}
else
{
MessageBox.Show("打开成功!")
}