I am running an application on linux machine. By giving the ip address of a windows machine as input, the application must shutdown the windows machine. If the machines run the same OS it is very easy but I'm confused how to do it in cross OS.
-
net, secpol.msc, ssh are all the tools used by programmers and by putting up as a cron job, this is indeed a question related to software tools primarily used by programmers. I don't understand why this questions is off-topic. – ganesshkumar Dec 19 '22 at 16:55
9 Answers
There may be more setup to do, especially for Windows Vista, Windows 7 and further windows versions, to allow remote shutdown:
Part A) On the Windows machine:
1) Add a remote shutdown security policy:
run
secpol.msc
in the program tree, open
Security Settings
>Local Policies
>User rights Assignment
Find the entry
Force shutdown from a remote system
Edit the entry, add the windows user account that will be used for shutdown (ex: nouknouk)
2) Add registry keys to disable UAC remote restrictions:
Run
regedit.exe
as AdministratorFind
HKLM/SOFTWARE/Microsoft/Windows/CurrentVersion/Policies/System
Create a new registry
DWORD(32)
value namedLocalAccountTokenFilterPolicy
and then assign it the value1
3) Start remote registry service:
Open
cmd.exe
as AdministratorExecute the two following commands:
sc config RemoteRegistry start= auto
sc start RemoteRegistry
Part B) On the Linux machine:
1) install the package samba-common
:
It depends on your Linux distribution, but for Debian and derivated (Ubuntu, Linux Mint, ...), the apt-get command can be executed like that:
apt-get install samba-common
2) To actually shutdown your Windows machine from the Linux one, run the following command:
net rpc shutdown -f -t 0 -C 'message' -U userName%password -I xxx.yyy.zzz.ttt
Where:
-f
means force shutting down all applications (may be mandatory)-t 0
is the delay before doing it (0 means 'right now').-U user%password
is the local user and his password on the windows machine (the one that has been allowed to do remote shutdown in part A).-I
is the IP address of the windows machine to shutdown.
-
1Hi, I have tried everything to make this work from my raspberrie pi 2 to windows 8 PC but I cannot get passed the "Connection failed: NT_STATUS_ACCESS_DENIED" error. – tfonias74 Jul 29 '16 at 11:16
-
-
@tfonias74 you have to check the Windows Firewall, see the answer from @PCatinean and allow ``Remote Service Management`` there. – Phann Oct 04 '21 at 14:16
Command to shutdown windows system from linux -:
$ net rpc -S <ip address> -U <username>%<password> shutdown -t 1 -f
This command can be issued from bash or even set in cron job to shutdown the computer at a specific time and this command is shipped with many distros by default.

- 1,317
- 1
- 16
- 35
-
4
-
2You many need to configure windows and linux properly for this solution to work. Look at nouknouk's answer if net command is not available or if it doesn't work – ndemou Jan 17 '16 at 20:44
It's important to note that the above solution will not work if the username in question does not have a password set (at least that's how it was in my case).
For windows 10 (and below maybe, did not check) users one must go to the firewall settings and enable "Remote Service Management" for the linux box to be able to connect via rpc.

- 76
- 2
It depends on your infrastructure -- how you authenticate to the Windows machines, whether you can configure them yourself, etc. If it were me, I'd put Cygwin on the Windows boxes, then ssh
to them and run shutdown -h
. There are surely other ways to do it, of course.

- 80,601
- 10
- 150
- 186
You need a way to launch a shell on the Windows box so you can run th shutdown command built in to Windows.
You can install Cygwin for this, then install an SSH daemon in Windows. Once that's running, your Linux box can run commands on the Windows box just as if it were another Linux machine.
Here are some instructions for setting up Cygwin's sshd in Windows.

- 45,319
- 8
- 65
- 104
Also don't forget to add an inbound rule for RPC in Windows firewall allowing port 445.

- 21
- 3
Option 1: Install SSH server on windows. Login to this server from any box and call shutdown command. We use Interix(Microsoft's unix like environment). It comes with a telnet server- allows to invoke windows commands from other machines..
Another option: If you samba installed on windows it can connect to windows and call windows commands
net rpc SHUTDOWN ...
Another option: try rdesktop to the windows machine with shutdown command ( I use it for running windows batch script which has shutdown in it, not sure if you can directly call shutodwn)

- 18,003
- 15
- 89
- 143
Use telnet command in Linux
, make sure telnet is enabled in Windows system

- 18,735
- 7
- 49
- 73

- 11,847
- 8
- 35
- 46
-
WARNING: This is almost always A BAD ADVICE. A telnet server running in your server is almost always a bad idea (if you've been under a rock for the last 20 years please note that the telnet protocol sends user names and passwords in clear text over your network). – ndemou Jan 17 '16 at 20:55