Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WOL integration in a VBsript

Status
Not open for further replies.

cippall

IS-IT--Management
Feb 3, 2009
5
AU
Hi, i'm new in this field. I'm working on a HTA script using VBscripting to manage our renderfarm. When first runs creates 2 .ini files computers.ini and mac.ini wich can be edit after generation. When script starts it displays a column with the IP of the Pc from computers.ini and a button for StartSystems. This way i can select what pc i want to wakeup, 2,3 or all. I need help with finishing my script to do a wake-up-on-lan using wol.exe (commandline app) that is copied in windows root directory or it's in the same folder as the HTA script.

Here is what i've got :

Sub Window_Onload
window.resizeto 660,370

ForReading = 1
ForWriting = 2
strComputersFile = "computers.ini"
strMACFile="Mac.ini"
'*** Check computers available.. if no file, create file

Set objFSO = CreateObject("Scripting.FileSystemObject")
if objFSO.FileExists(strComputersFile) Then
Set objFile = objFSO.OpenTextFile(strComputersFile, ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
Set objOption = Document.createElement("OPTION")
objOption.Text = strLine
objOption.Value = strLine
AvailableComputers.Add(objOption)
Loop
objFile.Close
Else
objFSO.CreateTextFile(strComputersFile)
Set objFile = objFSO.OpenTextFile(strComputersFile, ForWriting)

objFile.WriteLine "192.168.0.1"
objFile.WriteLine "192.168.0.2"
objFile.WriteLine "192.168.0.3"
objFile.WriteLine "192.168.0.4"
objFile.WriteLine "192.168.0.5"
objFile.WriteLine "192.168.0.6"
objFile.WriteLine "192.168.0.7"
objFile.WriteLine "192.168.0.8"

objFile.Close

Set objFile = objFSO.OpenTextFile(strComputersFile, ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
Set objOption = Document.createElement("OPTION")
objOption.Text = strLine
objOption.Value = strLine
AvailableComputers.Add(objOption)
Loop
objFile.Close
End If


'*** Check MAC available.. if no file, create file

Set objFSO = CreateObject("Scripting.FileSystemObject")
if objFSO.FileExists(strMACFile) Then
Set objFile = objFSO.OpenTextFile(strMACFile, ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
Set objOption = Document.createElement("OPTION")
objOption.Text = strLine
objOption.Value = strLine
Loop
objFile.Close
Else
objFSO.CreateTextFile(strMACFile)
Set objFile = objFSO.OpenTextFile(strMACFile, ForWriting)

objFile.WriteLine "MAC1"
objFile.WriteLine "MAC2"
objFile.WriteLine "MAC3"
objFile.WriteLine "MAC4"
objFile.WriteLine "MAC5"
objFile.WriteLine "MAC6"
objFile.WriteLine "MAC7"
objFile.WriteLine "MAC8"

objFile.Close

Set objFile = objFSO.OpenTextFile(strMACFile, ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
Set objOption = Document.createElement("OPTION")
objOption.Text = strLine
objOption.Value = strLine
Loop
objFile.Close
End If

End Sub


Sub StartSystems
For i = 0 to (AvailableComputers.Options.Length - 1)
If (AvailableComputers.Options(i).Selected) Then
strComputer = AvailableComputers.Options(i).Value

HERE IS THE PROBLEM, I DON'T KNOW HOW TO FINISH THIS. FOR THE SELECTED COMPUTERS I MUST ASSOCIATE THE MAC FROM THE SECOND INI(MAC.INI) AND CREATE THE SCRIPT THAT RUNS "WOL MAC"

strHost = "."
Set objWMIService = GetObject _
("winmgmts:\\" & strHost & "\root\cimv2:Win32_Process")

error = objWMIService.Create("wol" & strMAC)

End If
Next
End Sub

Hope you understand what my problem is.


 
The part in red is what you need to modify. Replace the period with either the PC name or the IP Address of the remote system. That will let you bind to the remote system (assuming it is powered on).

Code:
 strHost = [red]"."[/red]
        Set objWMIService = GetObject _
           ("winmgmts:\\" & strHost & "\root\cimv2:Win32_Process")

        error = objWMIService.Create("wol" & strMAC)

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Thx for your answer but is not helping me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top