【发布时间】:2018-10-24 19:31:25
【问题描述】:
当我尝试运行此功能时,它会在进程启动时不断崩溃。
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 命令。
【问题讨论】:
-
您可能应该使用完整路径,而不仅仅是文件名...
-
@ZoharPeled,我在 Windows 文件夹中找不到 mklink。有人说该命令位于 Windows 终端命令提示符内。所以它没有二进制文件。
-
@mjwills,我相信它与此不同。但与此相同:stackoverflow.com/questions/15621294/…
-
另见bartdesmet.net/blogs/bart/archive/2006/10/24/Windows-Vista-2D00-Creating-symbolic-links-with-C_2300_.aspx。