Connecting to and remotely restarting via command line

There are circumstances where you will need to connect to another computer and restart it through command line. For the sake of saving you pages of fruitless Google searches, here’s how to do just that.

You’ll need to enable network discovery, turn on public folder sharing, as well as file and printer sharing. Also, check the firewall to ensure that it is either off (no recommended) or allowing remote shutdown commands (and possibly others) through. Chances are you already have this done though, but you’re still getting that Access is denied error.

That’s because even though you have all of your commands and credentials correct, there are still a few more settings that need to be changed.

You’ll need to run secpol.msc and change two settings in the Local Security Policy

Expand Local Policies and then select Security Options and find the policy “Network Access: Sharing and security model for local account.” This setting will need to changed to Classic if it isn’t already. If this setting isn’t changed, all remote logins via command line are logged on as guests.

Next, under User Rights Assignment find the policy “Force shutdown from a remote system” and ensure that the account you’re using (or the group it is a member of) is added to this policy.

For good measure, ensure that RPC is set to automatic in services.

Once all of these settings are enforced, run the following commands and you should be good to go. It shouldn’t be necessary, though it could potentially fix a problem if you run the command prompt as an administrator.

net use \\ComputerNameOrIpAddress\ipc$ /user:Username Password
shutdown -r -f -m \\ComputerNameOrIpAddress
net use \\ComputerNameOrIpAddress /delete

While using the computer name is easy, if you have a static IP address, you should always opt for using the IP address to ensure you get a good connection every time.

The -r will issue the restart command, and -f will force any programs closed. If you don’t use -f, it will likely hang and not restart, and you won’t be able to issue another restart command until the first one clears. Using -m indicates that you’re issuing the command to another computer. Additionally, you can change the timer from a default of 30 seconds by atting a -t at the end of the shutdown command followed by the number of seconds you want it to wait.

The third command is important in that it ensures that the connection is closed out immediately afterwards. This helps to prevent future connection issues.

To make it all easy, throw it in a batch file.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: