Wednesday, January 17, 2007

Restart Server Remotely

Do you want to give permission to other people to restart your server remotely? All they can do is to restart the server - nothing else. Here is how you do it:

  • Create a local user in the server
  • Create a local group in the server, and assign the new user to this group
  • Add the user to the built-in Remote Desktop Users group
  • Assign the new group to the local policy to be able to login through Terminal Service and Shutdown the server
  • Create a reboot VBScript - call it r.vbs

Option Explicit
Dim Reboot
Dim Cancel
Dim objShellSet

objShell = WScript.CreateObject("Wscript.Shell")
Reboot = msgBox("You are about to reboot the server now. Click YES to confirm or NO to cancel", 4, "Confirm Reboot Server")

If Reboot = 6 Then
objShell.Run "cmd /c C:\windows\system32\shutdown -r -f -t 30", 0, True

Cancel = msgBox("To cancel the reboot, Click YES now", 4, "Cancel Reboot")

If Cancel = 6 Then
objShell.Run "cmd /c C:\windows\system32\shutdown -a", 0, True
End If
End If

  • Create a wrapper batch file - call it a.cmd

@echo off
cscript r.vbs

  • Assign the new user environment properties to run the a.cmd when they login through terminal service

No comments: