Process myProcess = new Process();
ProcessStartInfo remoteAdmin =
new ProcessStartInfo(Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\iisreset.exe /restart");
remoteAdmin.UserName = username;
remoteAdmin.Password = pwd;
remoteAdmin.Domain = domain;
myProcess.StartInfo = remoteAdmin;
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.Start(); --- ERROR HERE
Can not find the file specified.
但是当我尝试通过 cmd 在本地计算机上运行 iisreset 时,它正在运行。
最佳答案
除非我遗漏了什么,(Environment.GetFolderPath(Environment.SpecialFolder.System)
将取回本地机器(运行代码的地方)特殊文件夹。所以它期待文件 C:\Windows\System\iisreset.exe
位于您的机器上。我能看到的解决此问题的唯一方法是删除 C:\
并取而代之添加设备名称 \\DeviceName\C$\
,然后添加文件路径。这是假设特殊文件夹系统位于您的计算机和远程计算机上的同一位置。
获取远程机器系统目录的唯一其他方法是通过 WMI 或通过读取 reg 条目获取它。
所以如果使用 WMI:
"SELECT * FROM Win32_OperatingSystem"
完成后,您需要自己从中构建文件夹字符串。
关于c# - 远程机器上的 iisreset (C#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6675255/