我正在尝试从.NET服务中以不同的用户启动.NET应用程序。这个想法是在Windows中创建一个沙盒托管应用程序。在服务中,我通过编程方式在Windows中创建了用户,为该用户创建了一个文件夹,并从服务器下载主机.exe到该文件夹中。然后我使用System.Diagnostics.Process运行主机.exe。以下是该进程的StartInfo:
_process = new Process
{
StartInfo =
{
Arguments = " -debug",
FileName = instanceDirectory + "host.exe",
WorkingDirectory = instanceDirectory,
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardOutput = true,
RedirectStandardInput = true,
UserName = Helpers.GetUserNameForInstance(_hostid),
Password = _hostpass,
Domain = ""
},
EnableRaisingEvents = true
};
当我将服务作为SERVICE运行时,进程会立即崩溃,并以错误代码-1073741502结束。但是,当我将服务作为在Windows服务中指定的相同用户交互式地在控制台中运行时,一切都可以正常工作。只有在作为SERVICE运行服务时才会出现这种情况,而不是直接在控制台中运行。
任何帮助都将非常感激。这已经让我头疼很长时间了,这是最后的选择:(