当我尝试运行此功能时,它会在进程启动时不断崩溃。
public static void MapDestinationToSource (string destination, string source)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process ();
// set the file to execute
proc.StartInfo.FileName = "mklink";
proc.StartInfo.Arguments = $"/D \"{source}\" \"{destination}\"";
// Redirect the output stream of the child process.
proc.StartInfo.UseShellExecute = true;
//proc.StartInfo.RedirectStandardOutput = true;
// start the process
proc.Start ();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
string output = proc.StandardOutput.ReadToEnd ();
proc.WaitForExit ();
}
例外:
System.ComponentModel.Win32Exception occurred
HResult=0x80004005
Message=The system cannot find the file specified
Source=System
StackTrace:
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at GameCloud.StorageLibrary.MapDestinationToSource(String destination, String source) in D:\Development\code\sample\server\ClientAgent\ClientAgent\StorageLibrary.cs:line 130
at GameCloud.Program.Main(String[] args) in D:\Development\code\sample\server\ClientAgent\ClientAgent\Program.cs:line 135
当我在命令行上执行命令时,它可以工作。但它没有在代码中。我已经设置了安全策略以允许当前用户在没有提升访问权限的情况下执行 mklink 命令。