Avatar of aehare70
aehare70
Flag 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.

VB ScriptPowershellC#

Avatar of undefined
Last Comment
aehare70

8/22/2022 - Mon
josika

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

aehare70

ASKER
Error: Unexpected 'Next'
Code: 800A041F
josika

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

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
aehare70

ASKER
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
josika

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

aehare70

ASKER
I get this from the echo (see attached image).
usbenu-echo.jpg
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
aehare70

ASKER
My mistake, I had changed the list file when testing another method.  Retesting.
josika

If you want it to read colon or comma delimited server names that is possible as well.
aehare70

ASKER
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?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
josika

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
josika

Hello aehare70,

Any updates on this?

Thanks.
aehare70

ASKER
Thanks for the support!