8

I'd like to know if it is possible to shut down a Windows Server 2003 box, without have to log into the machine via remote desktop.

The server is on my network, I know the IP address and host name, as well the Administrator password.

I want to shutdown by simply double clicking a shortcut or executing a script.

How do I do this?

Saajid Ismail
  • 317
  • 3
  • 7
  • 18

4 Answers4

16

Remote shutdown...

  • Using your domain account credentials (if your user account has local admin rights on the target machine):
    shutdown /s /f /t 30 /m \\SERVER-NAME
  • Using the remote machine's local administrator account (psexec will prompt you for the password):
    psexec \\SERVER-NAME -e -h -u SERVER-NAME\administrator shutdown /s /f /t 30
  • Using a different domain account:
    psexec \\SERVER-NAME -e -h -u DOMAIN-NAME\username shutdown /s /f /t 30

Shutdown parameters explained...

  • /s = shutdown (substitute /r if you want to reboot)
  • /f = force (don't let running programs or active user sessions interfere with the reboot)
  • /t 30 = give logged in users a 30-second warning (substitute any integer, 0 is an acceptable value)
  • /m \\SERVER-NAME = specify name of remote machine to reboot

PsExec parameters explained...

  • -e = do not load user profile (user profile is unnecessary for shutdown command)
  • -h = run task with elevated privileges (only makes a difference on Vista/Win7/Server2008)
  • -u SERVER-NAME\administrator = log in as local administrator on SERVER-NAME
  • shutdown /s /f /t 30 = i

Batch file example, using local admin account... (paste into Notepad as rsla.bat)

  • @echo off
    REM rsla.bat - remote shutdown as local administrator
    REM This script is freeware authored by Miles Erickson, 7/2010.
    REM Requires PsExec.exe to be available in %PATH% (c:\windows\system32 is one option)
    REM Cannot be used to restart a domain controller (domain controllers do not have local admin accounts)
    IF (%1)==() GOTO instructions
    IF (%1)==(/?) GOTO instructions
    psexec \\\\%1 -e -h -u %1\\administrator shutdown /s /f /t 30
    GOTO end
    :instructions
    ECHO Usage: rsla SERVER-NAME    (you will be prompted for a password)
    :end
    

Links...

John Gardeniers
  • 27,458
  • 12
  • 55
  • 109
Skyhawk
  • 14,200
  • 4
  • 53
  • 95
  • very thorough. I am modding this up as well. Also check out [this guy's page of batch files using different utilities](http://www.robvanderwoude.com/shutdown.php). He is very thorough as well. This guy's page is a resource managing Winboxen should bookmark. I run into every time I need something useful, complicated, or both. – songei2f Jul 21 '10 at 23:32
9

If you didn't need to specify credentials, you could use the SHUTDOWN command. If you do need to specify credentials (your login doesn't have permissions, or the computer isn't on the domain), you can use the PSSHUTDOWN utility to do this.

K. Brian Kelley
  • 9,034
  • 32
  • 33
3

Local account:

cmd /k wmic /node:"targetcomputerhostname" /user:"AdministratororWhatever" os where primary=true call reboot

AD account with local admin privileges:

cmd /k wmic /node:"targetcomputerhostname" /user:"DomainAccountWithAdminPrivs@fqdn" os where primary=true call reboot

This is easily portable as a batch file. Keep in mind you will need the proper remote exceptioins. If psshutdown works, this ought to work as well without installing any external software (not to dis SysInternals tools, the one thing Windows I swear by).

songei2f
  • 1,934
  • 1
  • 20
  • 30
  • Hmmm... You do like WMIC! ;) – joeqwerty Jul 21 '10 at 16:59
  • In some cases, WMIC is very valuable. In this case - not so much. – MDMarra Jul 21 '10 at 20:47
  • Extremely ugly, unintuitive and hard to remember. Doesn't really have a lot going for it, does it? – John Gardeniers Jul 21 '10 at 21:44
  • Say what you want, but is a) pre-installed on XP and b) allows me to avoid using UAC and/or runas when one of my domain accounts is different from the logon session on my computer. Judging by the fact that I got 0 votes, I guess beauty is more important than pragmatism for some. If I had my guess, judging by parameters available, shutdown and things like PsShutdown use the same API calls as WMIC to accomplish it anyway. But hey, I digress. – songei2f Jul 21 '10 at 23:30
  • +1. One man's trash is another man's treasure. Your method gets the job done, which was the point of the question "How can I do this". – joeqwerty Jul 22 '10 at 00:56
  • Looks very useful. I will have to try this out! – Skyhawk Jul 22 '10 at 15:43
1

Powershell:

$cred = get-credential Domain\AdminAccount
(gwmi -co %Computername% Win32_OperatingSystem -cr $cred).Shutdown()
Chris S
  • 77,945
  • 11
  • 124
  • 216