我可以使用这段代码启动小程序:
if (File.Exists(content[1]))
{
Process process = new Process();
try
{
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = content[1];
process.StartInfo.CreateNoWindow = true;
process.Start();
SuccessMessage("Successfully launched " + content[0]);
//System.Diagnostics.Process.Start(content[1]);
}
catch (Exception e)
{
ErrorMessage("Couldn't start the process!");
ErrorMessage(e.Message);
}
}
content[1] 包含文件的路径。
例如,我可以启动 VLC,但无法使用此代码启动 Visual Studio。为什么?
请您参考如下方法:
我试着运行你的代码,但遇到了同样的问题。 我得到的异常(exception)是:
C:\Users\MyUsername\Documents\Visual Studio 2012\Projects\ConsoleApplication20\Consol
eApplication20\bin\Debug>ConsoleApplication20.exe
Couldn't start the process!System.ComponentModel.Win32Exception (0x80004005): The requested operation requires elevation
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at ConsoleApplication20.Program.Main(String[] args) in c:\Users\MyUsername\Documen
ts\Visual Studio 2012\Projects\ConsoleApplication20\ConsoleApplication20\Program .cs:line 24
这是因为我的 Visual Studio 处于高完整性级别,您可以阅读 here 当我以管理员身份执行该过程时(右键单击->以管理员身份运行),该过程开始了。进程无法在不请求提升的情况下启动具有更高完整性级别的其他进程。
