darkleton Posted September 22, 2010 Share Posted September 22, 2010 I have a script for installing software remotely to PC's. So far you can get a list of all pc's and select multiple ones which saves them to an array and displays them in a listbox. what i then need to do is run a set of commands for each pc listed. previously i only had the script run on one remote pc, so it runs, completes that command then moves on. now i need it to run on multiple machines and only move on when all have completed. The transfer function is below, and where it has $destinationpcname, that would have to be replaced with each entry in the array. The problem is, i'm new to arrays (have only got this far by reading as much help files as i can) so dont know how to make it run the same function on each pc listed in the array, and only continue when all complete. any help would be greatly appreciated! thanks Mike expandcollapse popupFunc BitsTransfer() $destinationpcname = GUICtrlRead($destinationpcinput) $destinationpcpath = "\\" & $destinationpcname & "\C$\Temp\" $jobfilename = GUICtrlRead($localzipfileinput) $jobname = $jobfilename IniWrite(@ScriptDir & "\" & $jobname & ".ini","PC","Remote-PC",$destinationpcname) IniWrite(@ScriptDir & "\" & $jobname & ".ini","JOB","JobName",$jobname) IniWrite(@ScriptDir & "\" & $jobname & ".ini","ZIP","FileName",$localzipfilename) IniWrite(@ScriptDir & "\" & $jobname & ".ini","MSI","FileName",$localmsifilename) IniWrite(@ScriptDir & "\" & $jobname & ".ini","MSI","FolderName",$localmsifolder & "\") RunWait(@ComSpec & " /c bitsadmin /create /upload " & $jobname, @ScriptDir, @SW_HIDE) Sleep(200) RunWait(@ComSpec & ' /c bitsadmin /addfile ' & $jobname & ' ' & $destinationpcpath & $localzipfilename & '.zip ' & '"' & @ScriptDir & "\" & $localzipfilename & '.zip"', @ScriptDir, @SW_HIDE) Sleep(200) RunWait(@ComSpec & ' /c bitsadmin /setpriority ' & $jobname & " HIGH", @ScriptDir, @SW_HIDE) Sleep(200) RunWait(@ComSpec & " /c bitsadmin /resume " & $jobname, @ScriptDir, @SW_HIDE) Sleep(200) While 1 RunWait(@ComSpec & " /c bitsadmin /getstate " & $jobname & " > state.txt", @ScriptDir, @SW_HIDE) $jobstatefile = FileOpen( @ScriptDir & "\state.txt", 0) $jobstate = FileReadLine($jobstatefile, 6) FileClose($jobstatefile) If $jobstate = "CONNECTING" Then ContinueLoop EndIf If $jobstate = "TRANSFERRED" Then RunWait(@ComSpec & " /c bitsadmin /complete " & $jobname, @ScriptDir, @SW_HIDE) FileClose($jobstatefile) FileDelete($jobstatefile) ExitLoop EndIf If $jobstate = "SUSPENDED" OR $jobstate = "TRANSIENT_ERROR" OR $jobstate = "ERROR" Then MsgBox(0,"","There has been an error in sending. Please try again") Exit EndIf WEnd EndFunc PS - the bits i need primarily are the runwait commands and jobstate checks. the ini writes are more for my reference Link to comment Share on other sites More sharing options...
Tankbuster Posted September 22, 2010 Share Posted September 22, 2010 (edited) Maybe I'm wrong, but is this... Dim $aArrayOfComputer[3] $aArrayOfComputer[0]="PC1" $aArrayOfComputer[1]="PC2" $aArrayOfComputer[2]="PC3" FOR $destinationpcname IN $aArrayOfComputer BitTransfer($destinationpcname ) NEXT //actually your function but here replaced with a simple MsgBox func BitTransfer($destinationpcname ) msgbox(0,"destinationpcname",$destinationpcname,2) EndFunc ...what you search for? Obviously the FOR/Next loops through your Array (here just a simple defined array) and your code needs a little update like Func BitsTransfer($destinationpcname) $jobfilename = GUICtrlRead($localzipfileinput) $jobname = $jobfilename ..... ... .. or missed I something in your question? Edited September 22, 2010 by Tankbuster Link to comment Share on other sites More sharing options...
darkleton Posted September 22, 2010 Author Share Posted September 22, 2010 thanks for the reply. i have a listbox populated with all pc's on a domain. you select however many you want and click ok. that selection then fills an array which i want this part of the script to work through. the problem is the number of pc's selected can be anything, its up to you how many you click. so i assume i would need to use ubound to count them from reading the ubound help? because the selection is random, i can't hardcode what the array entries are, one day it could be pc-1 to pc-6, the next it could be pc-1 and laptop-12, etc. so i need a way of the script reading all the array and working through it, without me having to specifically name the pc's in the array (if that makes sense) i know i could do the for > next code to have it systematically work through the list, its making it read the list im sticking on. sorry if your reply answered it, i'm trying to mess about with arrays to see if i can get it working Link to comment Share on other sites More sharing options...
Sticky Posted September 22, 2010 Share Posted September 22, 2010 thanks for the reply. i have a listbox populated with all pc's on a domain. you select however many you want and click ok. that selection then fills an array which i want this part of the script to work through. the problem is the number of pc's selected can be anything, its up to you how many you click. so i assume i would need to use ubound to count them from reading the ubound help? because the selection is random, i can't hardcode what the array entries are, one day it could be pc-1 to pc-6, the next it could be pc-1 and laptop-12, etc. so i need a way of the script reading all the array and working through it, without me having to specifically name the pc's in the array (if that makes sense) i know i could do the for > next code to have it systematically work through the list, its making it read the list im sticking on. sorry if your reply answered it, i'm trying to mess about with arrays to see if i can get it working If you already have the code worked out to find each pc that has been selected, couldn't you do your remote commands right at each point that a pc is found to be selected and skip the whole need for writing to an array and going back through it? As for building an array, you can create a new array: #include<Array.au3> Dim $array[1] $array[1] = 0 Then use: _ArrayAdd($array, $pcSelected) $array += 1 everytime you find one selected. Be sure to include Array.au3 as it contains the _ArrayAdd function. Once you're done building the array, you can iterate through it using its $array[0] value. For $i = 1 To $array[0] $array[$i] Next Link to comment Share on other sites More sharing options...
darkleton Posted September 22, 2010 Author Share Posted September 22, 2010 and it would help if i wasn't such an idiot! i just realised that just prior to that i'd done arraytostring for something else so it wasn't an array i was working on! i've now got it back to the array, and doing what i was expecting, so i just need to get it to work through each PC with that function, so will look at the example you gave of func($destinationpcname). thanks again Link to comment Share on other sites More sharing options...
Tankbuster Posted September 22, 2010 Share Posted September 22, 2010 thanks for the reply.i have a listbox populated with all pc's on a domain. you select however many you want and click ok. that selection then fills an array which i want this part of the script to work through. the problem is the number of pc's selected can be anything, its up to you how many you click. so i assume i would need to use ubound to count them from reading the ubound help?...Mmmh, are you referring to the question on "How to enable Multi Select in ListView"? and how to work with these values?Than take a short look to the example of : _GUICtrlListView_GetSelectedIndices and so you get all INDICES and this is actually the line and now with _GUICtrlListView_GetItem you could continue. Link to comment Share on other sites More sharing options...
darkleton Posted September 23, 2010 Author Share Posted September 23, 2010 tankbuster: thank you very much, once i'd read through a bit more documentation i realised that your first post was indeed what i was looking for, thanks! Link to comment Share on other sites More sharing options...
Tankbuster Posted September 23, 2010 Share Posted September 23, 2010 You're welcome. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now