本文介绍了使用C#脚本为cmd for iisreset的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 大家好, 我想使用c#从我当地的iisreset远程机器。 iisreset< servername> / start正在从命令提示符开始工作但是当我使用c#代码中的相同脚本时它无法正常工作。 这是附加的代码: System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); //startInfo.WindowStyle = System .Diagnostics.ProcessWindowStyle.Hidden; startInfo.FileName =cmd.exe; startInfo.Arguments =/ c iisreset< servername> / start; process.StartInfo = startInfo; process.Start(); Anyhelp将非常感激。 b $ b 我尝试了什么: 我试过修改startinfo.arguements to: startInfo.Arguments =iisreset< servername> / start; Hi guys,I want to iisreset a remote machine from my local using c#.iisreset <servername> /start is working from command prompt but when i am using the same script from c# code it is not working.Here is the code attached:System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); //startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.FileName = "cmd.exe"; startInfo.Arguments = "/c iisreset <servername> /start"; process.StartInfo = startInfo; process.Start();Anyhelp would be really appreciated.What I have tried:I have tried modifying startinfo.arguements to: startInfo.Arguments = "iisreset <servername> /start";推荐答案 我刚创建了一个测试应用程序&使用下面的代码可以正常工作; I just created a test app & it works fine using the below code;Process proc = new Process();ProcessStartInfo sinfo = new ProcessStartInfo();sinfo.FileName = "cmd.exe";// note: the double slashes are to escape the \ charactersinfo.Arguments = "/c c:\\windows\\system32\\iisreset.exe myservername /start";proc.StartInfo = sinfo;proc.Start(); 可能阻止它工作的东西; a)本地机器上没有安装IISRESET b)你需要包含完整路径 - 你打开的命令提示符可能不包括iisreset它的路径 c)命令提示符不是远程机器上的本地管理员 - 本地机器上需要提升命令提示 简短的回答是,你需要调试&测试。如果你摆脱了你的论点&只需打开命令提示符,你真的可以运行命令吗? 亲切的问候Things that may stop it working;a) IISRESET is not installed on the local machineb) You need to include the full path - the command prompt that you open may not include iisreset it it's pathc) The command prompt is not a local admin on the remote machine - an elevated command prompt is required on the local machineShort answer is, you need to debug & test. If you get rid of your arguments & just open the command prompt, can you actually run the command?Kind Regards 这篇关于使用C#脚本为cmd for iisreset的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-29 23:26