Link to home
Create AccountLog in
Avatar of aehare70
aehare70Flag for United States of America

asked on

Read List, Execute Command, Wait For Command To Complete, Loop

I have a list of workstations listed in an ini file.  I need to connect to each workstation, run a command on each workstation, then disconnect from that workstation. and loop, until the list is complete.

ini file: wkslist.ini
example list:
w100000
w100001
w100002

Connect to each workstation;  UNC  path connection \\w10000
using a set of domain credentials (e.h. Username and Password) stored in variables.

Run the command: usbview /remote \\%workstation% /shtml usbview_%workstation%.html

Wait for the command above to complete before continuing and

Then Disconnect from the workstation

Loop until the list is complete.


I would prefer VBS, but can work with Powershell or C# if needed.

Avatar of josika
josika
Flag of United States of America image

Try this out:


Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")
Set oFile = oFSO.OpenTextFile("c:\wklist.ini")
Do Until oFile.AtEndOfStream
	MachineName = oFile.ReadLine
	oShell.Run("usbview /remote \\" & MachineName & " /shtml usbview_" & MachineName & ".html"), 0, True
Next

Open in new window

Avatar of aehare70

ASKER

Error: Unexpected 'Next'
Code: 800A041F
Oops, meant 'Loop'

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")
Set oFile = oFSO.OpenTextFile("c:\wklist.ini")
Do Until oFile.AtEndOfStream
        MachineName = oFile.ReadLine
        oShell.Run("usbview /remote \\" & MachineName & " /shtml usbview_" & MachineName & ".html"), 0, True
Loop

Open in new window

changed paths to reflect full path.. and nothing.  No .html files created, just runs and nothing.


Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")
Set oFile = oFSO.OpenTextFile("c:\temp\wkslist.ini")
Do Until oFile.AtEndOfStream
        MachineName = oFile.ReadLine
        oShell.Run("c:\temp\usbview.exe /remote \\" & MachineName & " /shtml usbview_" & MachineName & ".html"), 0, True

Loop
Added an echo so you can make sure the command it is running looks proper.  Also, added the c:\temp path to the html output:


Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")
Set oFile = oFSO.OpenTextFile("c:\temp\wkslist.ini")
Do Until oFile.AtEndOfStream
	MachineName = oFile.ReadLine
	strCommand = "c:\temp\usbview.exe /remote \\" & MachineName & " /shtml c:\temp\usbview_" & MachineName & ".html"
	WScript.Echo strCommand
	oShell.Run strCommand, 0, True
Loop

Open in new window

I get this from the echo (see attached image).
usbenu-echo.jpg
My mistake, I had changed the list file when testing another method.  Retesting.
If you want it to read colon or comma delimited server names that is possible as well.
If I needed the code to be portable.. what needs to be changed so the script will run from any drive, any directory?  So it basically looks in the location the .vbs resides?
ASKER CERTIFIED SOLUTION
Avatar of josika
josika
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Hello aehare70,

Any updates on this?

Thanks.
Thanks for the support!