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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trigger a server reboot from an intranet ASP page

Status
Not open for further replies.

tunasushi

IS-IT--Management
Dec 8, 2003
7
US
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 a batch file. The batch file contains the SHUTDOWN command ("c:\windows\system32\shutdown.exe -s -m \\ts-server -t 30 -f"), 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.

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.
 
You didnt mention what happens when it fails... if it is a permissions issue them maybe try using the IIS Admin tool to let that one page run in the security context of an account with local admin privilages... might also try using the WShell to run the shutdown directly... also maybe download the PSTools because I think it has a fancy shutdown tool with more options.
 
I've received several errors upon several attempts. My most recent error is:

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

Line 31 is the wshell.run below:

set wshell = CreateObject("WScript.Shell")
wshell.run "c:\inetpub\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 reboot.bat, reboot.asp, shutdown.exe and cmd.exe.
 
I found an answer:

Code:
Dim Connection, WQL, SystemClass, System, Locator
Set Locator = CreateObject("WbemScripting.SWbemLocator")
Set Connection = Locator.ConnectServer("ts-server", "root\cimv2", "user account", "password")
WQL = "Select Name From Win32_OperatingSystem"
Set SystemClass = Connection.ExecQuery(WQL)
For Each System In SystemClass
   System.Win32ShutDown ( x )
Next

Substitute [tt]x[/tt] as follows:
[tt] 0 Log Off
4 Forced Log Off
1 Shutdown
5 Forced Shutdown
2 Reboot
6 Forced Reboot
8 Power Off
12 Forced Power Off[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top