Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.NET page on Win 2003 intranet to remotely reboot another server

Status
Not open for further replies.

tunasushi

IS-IT--Management
Dec 8, 2003
7
0
0
US
I posted this to the ASP forum, but there's no reason an ASP.NET solution shouldn't work, so I'll restate here.

I have two Windows 2003 servers, a primary that runs both a database and intranet, and a secondary that runs terminal services for a custom 3rd party application that accesses the database on the primary server.

Every once in a while, the 3rd party app ceases to operate normally, and it will not function until the terminal server is rebooted. This invariably happens when there is no one around to restart the terminal server.

What I'd like to do is to give my intranet users the ability to reboot the terminal server from a web page. I've created a form on an ASP page that attempts to run a batch file upon submittal. The batch file contains the SHUTDOWN command ("[tt]c:\windows\system32\shutdown.exe -r -m \\ts-server -t 30 -f[/tt]"), but I can't get the VBScript inside the web page to execute the batch file. The batch file itself executes properly if run from the command line. This could easily be replaced with ASP.NET and appropriate commands, but I don't know where to start.

I've received several errors upon several attempts with ASP. My most recent error is:

[tt][tab]Microsoft VBScript runtime error '800a0046'
[tab]Permission denied
[tab]/reboot.asp, line 31[/tt]

Line 31 is the [tt]wshell.run[/tt] below:
Code:
set wshell = CreateObject("WScript.Shell") 
wshell.run "c:\inetpub\[URL unfurl="true"]wwwroot\reboot.bat"[/URL] 
set wshell = nothing

I tried to set security on reboot.asp as follows:

IIS Manager > reboot.asp Properties > File Security > Authentication and access control > Edit > use administrator account for anonymous access

This also produces the same error detailed above.

I also tried setting the IUSR account with Read and Execute rights for [tt]reboot.bat[/tt], [tt]reboot.asp[/tt], [tt]shutdown.exe[/tt] and [tt]cmd.exe[/tt].

I'm not even sure if this is the best approach, but has anyone had success or attempted to do this themselves? Any guidance or advice is appreciated.
 
Assuming you have the appropiate security permissions to access the other server, you could kick off a new process that pointed at the batch file. Here's an example on how to start a new process.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
this is a service issue, not directly an asp.net issue. all asp.net will do is request the command be exeucted.

to execute a bat file I have used [tt]System.Diagnostics.Process.Start("my.bat").WaitForExit();[/tt]
I have run this from a simple console application. I would assume you need to use Windows Authentication and Impersonation. You may also need to implement Delegation between the server and remote machine. (Maybe, not sure though.)

As a test create a bat file to do something simple. (copy a file [foo.txt to bar.txt] or display a popup on the server, something). make sure the bat file executes properly. from there add more complex commands and remote server calls to see what breaks. It may be that administrative rights are required to reboot the server.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top