0

I want to restart services which is located to a different server using ASP classic, but it's not working on my end.

I have a 2 batch files that will stop and start multiple services in another remote server:

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:

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. But still doesn't work for me.

What am I missing something to solve this problem?

Please help! Thanks!

carl
  • 103
  • 1
  • 12

3 Answers3

1

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:

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!

carl
  • 103
  • 1
  • 12
0

Make sure you have given your .bat files permissions to be executed by the same as the Application Pool user.

If you're getting any errors and haven't mentioned them, then please do so.

Control Freak
  • 12,107
  • 25
  • 83
  • 138
  • actually, i'm not receiving any error message, it's just nothing is happening unlike if I manually execute the batch file. By the way, I already put the permission align to the app pool user, still no luck :( – carl Sep 25 '14 at 06:40
  • Look here http://stackoverflow.com/questions/5644689/how-to-execute-a-bat-file-from-a-classic-asp-page-on-the-server and here http://stackoverflow.com/questions/14886183/batch-file-execution-asp-classic – Control Freak Sep 25 '14 at 06:49
0

Beeing able to run .BAT file from an a web site is a very risky operation. 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.

SylvainL
  • 3,868
  • 3
  • 17
  • 24
  • thanks for reminding. anyway, the .bat file will be executed when the page receives a timeout. there's no button or anything that can be hit by user provided on our site to execute the .bat file :) – carl Sep 29 '14 at 08:47
  • Maybe but just the fact of given the web server the required permission to execute a .bat file is scaring by itself. If a hacker get some control over your web server and is able to write some files on the server, this would be one of the first things that he/her will check out. Don't forget that the hacking of a machine is often a multi-step process; especially for a server than for a desktop. – SylvainL Sep 29 '14 at 09:06