WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Asynchronously run another WinBatch Script Against a List of Workstations

 Keywords:  

; Name: ProcessList.wbt
; Purpose: Asynchronously run another WinBatch script against a list of workstations
; Benefit: Provides major parallel processing so that a large list can be processed in a short time
; Author: Les Ferch
; 2009-05-19: Version 1.0

IntControl(12,5,0,0,0) ; Terminate silently

Title = FileRoot(IntControl(1004,0,0,0,0)) ; Get title from script name
BoxTitle(Title) ; Set window title

AddExtender("WWPRC44I.DLL") ; Process extender

; Verify workstation list exists
DirChange(DirScript())
WksFile = "Workstations.txt"
Terminate(!FileExist(WksFile),Title,"File not found: ":WksFile)

; Take script from command line or prompt
Script = ""
If Param0>0 Then Script = Param1
Else Script = AskFilename("Select script to run for each machine in the list","","wbt|*.wbt",Script,1)

Terminate(!FileExist(Script),Title,"File not found: ":Script)

MaxProc = 50 ; Maximum number of simultaneous WinBatch processes allowed
TimeOut = 5 ; Number of seconds to wait when MaxProc has been reached before checking again

BoxOpen("Processing...","")

Data = FileGet("Workstations.txt")
Data = StrReplace(Data,@CRLF,@LF)
aData = Arrayize(Data,@LF)
Count = ArrInfo(aData,1)
Last = Count - 1

; Run script for each workstation in list with up to MaxProc running at same time
For i = 0 To Last
   Machine = StrTrim(aData[i])
   If Machine=="" Then Continue
   BoxText(i + 1:@TAB:Machine)
   While i>=MaxProc
      ProcList = tListProc()
      WBCount = StrCnt(ProcList,"winbatch|",1,-1,0)
      If WBCount<MaxProc Then Break
      TimeDelay(TimeOut) ; Allow time for some processes to complete
   EndWhile
   Run(Script,Machine)
Next
; Name: SetKernelDump.wbt
; Purpose: Sample script to be called by ProcessList.wbt
; Details:
; Author: Les Ferch
; 2009-05-19: Version 1.0

IntControl(12,5,0,0,0) ; Terminate silently

BoxTitle(FileRoot(IntControl(1004,0,0,0,0)))

If Param0==0 Then Exit
Workstation = Param1

; Create folders to hold results
DirChange(DirScript())
DirMake("PingFail")
DirMake("ConFail")
DirMake("OK")

; Add Win32 Network and WinInet extenders
AddExtender("WWWNT34i.DLL")
AddExtender("WWINT44i.DLL")

PingTimeOut = 1 ; seconds

; ID and PW to use to connect
ID = "local\administrator"
PW = "xxxxxxxx"

; If ping and connect OK, do work, otherwise log error
OK = iPing(Workstation,PingTimeOut)
If OK
   ErrMode = ErrorMode(@OFF)
   wntAddDrive(ID,PW,"\\":Workstation:"\ipc$",@NONE,@FALSE)
   OK = wntCancelCon("\\":Workstation:"\ipc$",@FALSE,@TRUE)
   ErrorMode(ErrMode)
   If OK
      ErrMode = ErrorMode(@OFF)
      wntAddDrive(ID,PW,"\\":Workstation:"\ipc$",@NONE,@FALSE)
      GoSub DoWork
      wntCancelCon("\\":Workstation:"\ipc$",@FALSE,@TRUE)
      ErrorMode(ErrMode)
   Else
      FilePut("ConFail\":Workstation,"")
   EndIf
Else
   FilePut("PingFail\":Workstation,"")
EndIf

Exit

; Replace this code with whetever you want to do or check on each workstation
; In this example, the old CrashDumpEnabled value is read and a new value set
:DoWork
CrashDumpValue = "System\CurrentControlSet\Control\CrashControl[CrashDumpEnabled]"
hReg = RegConnect(Workstation,@REGMACHINE )
Current = RegQueryDword(hReg,CrashDumpValue) ; Get old value
Result = RegSetDword(hReg,CrashDumpValue,2) ; Set new value
RegCloseKey(hReg)
FilePut("OK\":Workstation,Current:",":Result) ; Log old value and result of new value set attempt
Return


Article ID:   W18236
Filename:   Asynchronously Run a WinBatch Script Against a List of Workstations.txt
File Created: 2009:05:28:14:34:48
Last Updated: 2009:05:28:14:34:48