为什么这是
ProcessStartInfo myProcess = new ProcessStartInfo(path);
myProcess.UserName = username;
myProcess.Password = MakeSecureString(password);
myProcess.UseShellExecute = false;
Process.Start(myProcess);工作,但是
ProcessStartInfo myProcess = new ProcessStartInfo();
myProcess.FileName = Path.GetFileName(path);
myProcess.WorkingDirectory = Path.GetDirectoryName(path);
myProcess.UserName = username;
myProcess.Password = MakeSecureString(password);
myProcess.UseShellExecute = false;
Process.Start(myProcess);不是。
我想使用第二个问题,因为这个问题:https://stackoverflow.com/a/2621943/1306186
我经常得到一个没有发现异常的文件..。有什么想法吗?
编辑:
路径是例如@"C:\Users\User\Desktop\ConsoleApplication2.exe"
发布于 2012-09-16 20:16:48
这一点是错的
myProcess.FileName = Path.GetFileName(path);这应该是
myProcess.FileName = path;传入C:\SomeDir\SomeApp.exe,您所拥有的代码将文件名设置为SomeApp.exe,但它找不到。幸运的是,在某些情况下(例如,你的应用程序和你想要运行的应用程序在同一个文件夹中),你可能会在部署时得到一个有趣的信息。
发布于 2012-09-16 20:16:34
我将尝试使用Path.GetFullPath()而不是简单的Path.GetFileName(),因为构造函数在使用string参数时用完整的路径初始化FileName。
https://stackoverflow.com/questions/12450294
复制相似问题