Re: searching synchronously or asynchronously

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: David Wang [Msft] (someone_at_online.microsoft.com)
Date: 04/13/04


Date: Mon, 12 Apr 2004 21:06:32 -0700

Assuming you have a file called computers.txt which has the name of each
computer on a single line.

On the CMD commandline, run:
FOR /F %A IN ( computers.txt ) DO START CSCRIPT script.vbs %A

This will loop through computers.txt, one line at a time, read the name of
the computer stored within it, and call script.vbs with the name of the
computer and immediately return to the loop, which can immediately call
script.vbs on the next computer.

-- 
//David
IIS
This posting is provided "AS IS" with no warranties, and confers no rights.
//
"Jeff Giroux" <dabungis@msn.com> wrote in message
news:uE$t7sPIEHA.2656@TK2MSFTNGP11.phx.gbl...
Hi,
I have the below script.  It's suppose to go through each computer I set to
strComputer.  I use the command line to start the script with arguments for
each PC.  Example.
1. Open CMD...
2. Run "script.vbs" [computer1] [computer2] so on.
The script goes through one computer at a time finding the modified date of
each profile.  If it's old enough it deletes it.  Here's my question.  How
can I make the script run on all computers at the same time?  Right now, it
connects to [computer1] then it searches for all profiles and deletes, then
it goes to [computer2] and does the same thing.  This is find for only a
couple computers.  But I have a room of 32 PCs that needs this done every
other week.
Is there a way to run the script, connect to all computers in the command
line argument, and work each computer.  This way, it would finish all 32 in
the time it takes just one.  My computer is just searching the network
sending the commands.  The 32 remote computers are the actual ones doing the
deleting.
Script:
CurrentDate = Date
DaysOld = 7
strComputer = "."
NetPath = "c:\documents and settings\networkservice"
AdminPath = "c:\documents and settings\administrator"
LocalPath = "c:\documents and settings\localservice"
AllPath = "c:\documents and settings\all users"
DefUsrPath = "c:\documents and settings\default user"
objComputers = Wscript.Argument
Set oShell = CreateObject("Wscript.Shell")
For Each RemoteCPU in colComputers
  strComputer = RemoteCPU
  Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  Set colSubfolders = objWMIService.ExecQuery _
      ("Associators of {Win32_Directory.Name='c:\documents and settings'} "
_
          & "Where AssocClass = Win32_Subdirectory " _
              & "ResultRole = PartComponent")
  For Each objFolder in colSubfolders
    fName = objFolder.Name
    If fName <> NetPath and fName <> LocalPath and _
           fName <> AllPath and fName <> DefUsrPath and _
           fName <> AdminPath Then
      DelFolder objFolder
    End If
 Next
Next
Sub DelFolder (objFolder)
  FolderDate = objFolder.LastModified
  ConversionDate = CDate(Mid(FolderDate, 5, 2) & "/" & _
     Mid(FolderDate, 7, 2) & "/" & Left(FolderDate, 4))
  DayDiff = DateDiff("d", ConversionDate, CurrentDate)
  If DayDiff > DaysOld Then
    objFolder.Delete
  End If
End Sub


Relevant Pages

  • Re: Testing for loops
    ... I tried this while loop ... > path to a binary than to just specifiy the executable name. ... Try timing a script written ... command in vi, or the abbrev mode in emacs. ...
    (comp.unix.shell)
  • Re: probleme with read command in a loop
    ... >I made a script to remove accentuated characters from a series of file name ... Because the standard input (file descriptor 0) is redirected within ... the loop since your loop is at the end of a pipe-line. ... is the output of the find command from the previous pipe. ...
    (comp.unix.shell)
  • Re: Strange errors
    ... script, or at another point in the loop. ... you can do classin the command window at that ... why does the same exact code not ...
    (comp.soft-sys.matlab)
  • Re: unix pipes to perl scripts
    ... > the loop accepts the piped files but it also interferes with my STDIN! ... The STDIN of your pp script is redirected from the keyboard to the ... STDOUT of the ls command. ...
    (comp.lang.perl.misc)
  • Re: mv xrags and cp
    ... This command is good ... This will fail if there are filenames containing whitespaces. ... If you want do it with a loop use a while loop: ... do_something_with_file $fname ...
    (Ubuntu)