Knowledgebase / FAQ - ip-connect GmbH
Knowledgeroot - Version:
Menü verstecken Menü ausklappen Menü neuladen Menü einklappen
Menü schliessen
  1.    (Zuletzt geändert von rsch an 01.08.2009 01:15:29)

You can also shutdown a windows box if you have samba installed.

"net rpc SHUTDOWN -C "some comment here" -f -I x.x.x.x -U user_name%password"

As long as the user you supplied has rights to shutdown the system it will work.

I wrote a bash script that scans our network and turns off all our system that are left on over night. If you are interested.


wks=(`nmap -sL --dns-servers 10.x.x.x,10.x.x.x 10.x.x.x/22, 10.x.x.x.x/23 grep FQDN|cut -d" " -f2 |grep -v -f serverlist`)

for (( i=0; i < "${#wks[@]}"; i++)); do
net rpc SHUTDOWN -C "This system was left on after hours and is being shutdown" -f -I "${wks[$i]}" -U user_name%password


Basically what the script does is scans the network(s) with nmap, pipes it though grep and cut to get the FQDN. Then "grep -v -f serverlist" is an exclude list of server I don't want shutdown. From there it puts the workstations into an array and turns off each system.

Hope it helps

verschieben [Oben]

  2.    (Zuletzt geändert von rsch an 01.08.2009 01:16:24)

#!/usr/bin/env python

import win32api
import win32con
import win32netcon
import win32security
import win32wnet

def shutdown(host=None, user=None, passwrd=None, msg=None, timeout=0, force=1,
""" Shuts down a remote computer, requires NT-BASED OS. """

# Create an initial connection if a username & password is given.
connected = 0
if user and passwrd:
win32wnet.WNetAddConnection2(win32netcon.RESOURCET YPE_ANY, None,
''.join([r'\\', host]), None, user,
# Don't fail on error, it might just work without the connection.
connected = 1
# We need the remote shutdown or shutdown privileges.
p1 = win32security.LookupPrivilegeValue(host, win32con.SE_SHUTDOWN_NAME)
p2 = win32security.LookupPrivilegeValue(host,
newstate = [(p1, win32con.SE_PRIVILEGE_ENABLED),
(p2, win32con.SE_PRIVILEGE_ENABLED)]
# Grab the token and adjust its privileges.
htoken = win32security.OpenProcessToken(win32api.GetCurrent Process(),
win32security.AdjustTokenPrivileges(htoken, False, newstate)
win32api.InitiateSystemShutdown(host, msg, timeout, force, reboot)
# Release the previous connection.
if connected:
win32wnet.WNetCancelConnection2(''.join([r'\\', host]), 0, 0)

if __name__ == '__main__':
# Immediate shutdown.
shutdown('salespc1', 'admin', 'secret', None, 0)
# Delayed shutdown 30 secs.
shutdown('salespc1', 'admin', 'secret', 'Maintenance Shutdown', 30)
# Reboot
shutdown('salespc1', 'admin', 'secret', None, 0, reboot=1)
# Shutdown the local pc
shutdown(None, 'admin', 'secret', None, 0)

verschieben [Oben]