首页 新闻 会员 周边

跪求C#Windows服务在Windows server 2012 r2上调用外部程序,在线等,挺急的

0
悬赏园豆:10 [已关闭问题] 关闭于 2018-11-19 11:24

以下代码是服务启动外部程序的方法,在Windows10上可以正常启用,在服务器上无法正常启动,未获取到异常,无Windows错误日志。
try
{
string appStartPath = this.VPNInstallPosition + "\.exe";
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)Marshal.SizeOf(startInfo);
ApiDefinitions.CreateProcessAsUser(
userTokenHandle,
appStartPath,
"",
IntPtr.Zero,
IntPtr.Zero,
false,
0,
IntPtr.Zero,
null,
ref startInfo,
out procInfo);
if (userTokenHandle != IntPtr.Zero)
ApiDefinitions.CloseHandle(userTokenHandle);
_GetProcessError = "无法判断程序是否已打开,只能判断打开程序无错误";
return true;
}
catch (Exception ex)
{
_GetProcessError = "打开程序进程失败," + ex.Message.Replace("\n", "").Replace("\r", "");
return false;
}

陪你葬忆拾荒的主页 陪你葬忆拾荒 | 菜鸟二级 | 园豆:204
提问于:2018-11-13 15:10
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册