[AccessD] For Trainee BOFH's

MartyConnelly martyconnelly at shaw.ca
Thu Nov 18 19:50:59 CST 2004


 Those of you working on your BOFH certification might find this piece 
of code useful
Or if you really want to get all those users out of your database so you 
can work on it.
Or if you really want to renew a dhcp lease.

You can run from vbs or Access VBA

Here's a way to reboot a list of systems with a single keystroke. 
Replace the contents of the code between "Else" and "End if" statements 
in the  script below  that (renews DHCP leases on all computers) with 
the following:

 Set colOperatingSystems = objWMIService.ExecQuery("Select * from 
Win32_OperatingSystem")
 objTextFile.WriteLine(strComputer & " is rebooting.")
 For Each objOperatingSystem in colOperatingSystems
   ObjOperatingSystem.Reboot()
Next


'computer.txt' is a file that contains a list of all network machine names
' well aside from your own.

RebootFile = "computers.txt"
LogFile = "results.txt"

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(RebootFile, 1, True)
Set objTextFile = fso.OpenTextFile(LogFile, 2, True)

On Error resume next
Do While f.AtEndOfLine <> True
 strComputer = f.ReadLine
Set objWMIService = GetObject("winmgmts:" & 
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
If Err.Number <> 0 Then
 objTextFile.WriteLine(intCount & ". " & strComputer & " is not 
responding.")
 Err.Clear
Else
Set objNetworkSettings =  
objWMIService.Get("Win32_NetworkAdapterConfiguration")
 objNetworkSettings.RenewDHCPLeaseAll()
 objTextFile.WriteLine(strComputer & " has been renewed.")
End If
Loop

-- 
Marty Connelly
Victoria, B.C.
Canada






More information about the AccessD mailing list