从ASP.Net页面运行批处理文件
发布时间:2020-12-16 03:54:42 所属栏目:asp.Net 来源:网络整理
导读:我正试图通过ASP.Net页面在服务器上运行批处理文件,这让我发疯了.当我运行下面的代码时,没什么好开心的 – 我可以从一些日志语句中看到这段代码运行,但我传递给函数的.bat文件永远不会运行. 有谁能告诉我我做错了什么? public void ExecuteCommand(string b
我正试图通过ASP.Net页面在服务器上运行批处理文件,这让我发疯了.当我运行下面的代码时,没什么好开心的 – 我可以从一些日志语句中看到这段代码运行,但我传递给函数的.bat文件永远不会运行.
有谁能告诉我我做错了什么? public void ExecuteCommand(string batchFileLocation) { Process p = new Process(); // Create secure password string prePassword = "myadminpwd"; SecureString passwordSecure = new SecureString(); char[] passwordChars = prePassword.ToCharArray(); foreach (char c in passwordChars) { passwordSecure.AppendChar(c); } // Set up the parameters to the process p.StartInfo.FileName = @"C:WindowsSystem32cmd.exe"; p.StartInfo.Arguments = @" /C " + batchFileLocation; p.StartInfo.LoadUserProfile = true; p.StartInfo.UserName = "admin"; p.StartInfo.Password = passwordSecure; p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = true; // Run the process and wait for it to complete p.Start(); p.WaitForExit(); } 在服务器上的“应用程序”事件查看器日志中,每次尝试运行时,都会出现以下问题:
UPDATE 以下代码工作正常(它运行批处理文件): Process p = new Process(); p.StartInfo.FileName = batchFileLocation; p.StartInfo.WorkingDirectory = Path.GetDirectoryName(batchFileLocation); p.StartInfo.UseShellExecute = false; // Run the process and wait for it to complete p.Start(); p.WaitForExit(); 然而,这不是(当我尝试以特定用户身份运行时): Process p = new Process(); // Create secure password string prePassword = "adminpassword"; SecureString passwordSecure = new SecureString(); char[] passwordChars = prePassword.ToCharArray(); foreach (char c in passwordChars) { passwordSecure.AppendChar(c); } p.StartInfo.FileName = batchFileLocation; p.StartInfo.WorkingDirectory = Path.GetDirectoryName(batchFileLocation); p.StartInfo.UseShellExecute = false; p.StartInfo.UserName = "admin"; p.StartInfo.Password = passwordSecure; // Run the process and wait for it to complete p.Start(); p.WaitForExit(); 解决方法
一个关于“Faulting应用程序cmd.exe”的小谷歌指向我
IIS forum.
除非您使用CreateProcessWithLogon方法,否则您似乎无法在IIS下的后台创建新进程. (我没有测试过这个). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 是否可以将XDocument作为参数传递给ASP.NET
- asp.net-mvc – ASP.NET MVC内联Razor变量
- asp.net – AntFarm反模式 – 避免的策略,解毒帮助治愈
- asp.net-mvc – 如何在ASP.net控制器操作中访问整个查询字符
- asp.net-core-mvc – 使用asp.net核心的google身份验证器
- ASP.Net添加控件“无法获取[控件]的内部内容,因为内容不是文
- asp.net – Server.Transfer throws执行子请求时出错 如何解
- ASP.NET MVC3 – 您如何处理探测请求?
- asp.net-mvc – NET 3.5 – MVC PetShop应用程序?
- 谈基于.net平台开发中的模式窗体
推荐文章
站长推荐
- 适用于ASP.NET Core 2的MultipartFormDataStream
- asp.net-mvc-4 – 哪个machineKey配置更好?
- asp.net-mvc – ASP.NET MVC – Typesafe Html.T
- asp.net-mvc – NHibernate和上下文实体
- asp.net-mvc – 如何防止HttpUnauthorizedResult
- asp.net-mvc – 如何在MVC中创建通用视图模型?
- asp.net – 如何在运行时设置ObjectDataSource选
- asp.net – “Aspnetdb”数据库中的所有表用于什
- asp.net-mvc – ASP.NET MVC JsonResult返回500
- ASP.NET标识 – 强制使用安全戳重新登录
热点阅读