1、引入Cjwdev.WindowsApi.dll
2、代码实现
var appStartpath = @"D:\Project\third.exe";
int _currentAquariusProcessID;
/*appStartpath设置为全路径地址*/
IntPtr userTokenHandle = IntPtr.Zero;
ApiDefinitions.WTSQueryUserToken(ApiDefinitions.WTSGetActiveConsoleSessionId(), ref userTokenHandle);
ApiDefinitions.PROCESS_INFORMATION procinfo = new ApiDefinitions.PROCESS_INFORMATION();
ApiDefinitions.STARTUPINFO startinfo = new ApiDefinitions.STARTUPINFO();
startinfo.cb = (uint)System.Runtime.InteropServices.Marshal.SizeOf(startinfo);
try
{
ApiDefinitions.CreateProcessAsUser(userTokenHandle, appStartpath, "", IntPtr.Zero, IntPtr.Zero, false, 0, IntPtr.Zero, null, ref startinfo, out procinfo);
if (userTokenHandle != IntPtr.Zero)
ApiDefinitions.CloseHandle(userTokenHandle);
_currentAquariusProcessID = (int)procinfo.dwProcessId;
return true;
}
catch (Exception ex)
{
return false;
}