简体   繁体   English

在ASP Classic页面中执行.Bat文件

[英]Execute a .Bat file within ASP Classic page

I want to restart services which is located to a different server using ASP classic, but it's not working on my end. 我想使用ASP Classic重新启动位于其他服务器上的服务,但最终无法正常工作。

I have a 2 batch files that will stop and start multiple services in another remote server: 我有2个批处理文件,这些文件将停止并启动另一个远程服务器中的多个服务:

sc \\<machine address> stop service1
sc \\<machine address> stop service2

sc \\<machine address> start service1
sc \\<machine address> start service2

And I will call it from my ASP classic code which is done like this: 我将通过我的ASP经典代码来调用它,如下所示:

dim wshell
set wshell = CreateObject("WScript.Shell") 
wshell.run "c:\folder1\stopService.bat" 
wshell.run "c:\folder1\startService.bat" 
set wshell = nothing 

With these codes, It still doesn't work. 有了这些代码,它仍然不起作用。 I've read a solution similar to this problem to change the ApplicationPool to LocalSystem and to give enough permission to the file. 我已经阅读了与该问题类似的解决方案,以将ApplicationPool更改为LocalSystem并为文件提供足够的权限。 But still doesn't work for me. 但是仍然对我不起作用。

What am I missing something to solve this problem? 我缺少解决该问题的东西吗?

Please help! 请帮忙! Thanks! 谢谢!

I was able to fix my problem on how to restart multiple services located in another server: 我能够解决有关如何重新启动位于另一台服务器上的多个服务的问题:

I made my batch file like this, calling another batch file in the server where my service is located: 我将我的批处理文件做成这样,在我的服务所在的服务器中调用另一个批处理文件:

cmdkey.exe /add:<machine_ipAddress> /user:<domain>\<username>/pass:<password> 
psexec.exe \\<machine_ipAddress>   "C:\batch.bat"
cmdkey.exe /delete:<machine_ipAddress> 

here is what batch.bat look like: 这是batch.bat的样子:

cmd /c "net stop "service1" & net stop "service2" & net start "service1" & net start "service2"" 

This may be not the most efficient solution, but surely it works :) 这可能不是最有效的解决方案,但可以肯定地起作用:)

Thanks! 谢谢!

Make sure you have given your .bat files permissions to be executed by the same as the Application Pool user. 确保您已授予.bat文件权限,使其可以由“应用程序池”用户执行。

If you're getting any errors and haven't mentioned them, then please do so. 如果您遇到任何错误并且没有提及它们,请这样做。

Beeing able to run .BAT file from an a web site is a very risky operation. Beeing能够从网站运行.BAT文件是非常冒险的操作。 Hackers love this type of things and don't think that no hacker will ever be interested in busting into your company's network. 黑客喜欢这种类型的东西,并且认为没有黑客会对闯入您公司的网络感兴趣。 You should look for an alternate way of doing thing. 您应该寻找一种替代的做事方式。 For example, you could have a process on the remote server that looks at regular interval for some value in some database and have your page change this value for stopping or restarting the services. 例如,您可以在远程服务器上有一个进程,该进程定期查看某些数据库中的某个值,并使页面更改此值以停止或重新启动服务。

Another way would be to use one of the many applications available applications for getting a remote desktop. 另一种方法是使用许多可用应用程序中的一个来获取远程桌面。

In all cases, think twice before starting to use a web site as a remote controler for any server on your network. 在所有情况下,在开始使用网站作为网络上任何服务器的远程控制之前,请三思而后行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM