Chimaera Posted February 29, 2012 Share Posted February 29, 2012 (edited) Hi all Ive got this scenario of a case that i need to run 3 diff arrays in like below Case @OSVersion = "WIN_VISTA" ; =========================== Global $aManual[4] = [3, "item 1", "item 2", "item 3"] For $d = 1 To $aManual[0] ; running a shellexecutewait here Sleep(100) Next Global $aAuto[3] = [2, "item 4", "item 5"] For $e = 1 To $aAuto[0] ; running a shellexecutewait here Sleep(100) Next Global $aAutoDelay[4] = [3, "item 6", "item 7", "item 8"] For $f = 1 To $aAutoDelay[0] ; running a shellexecutewait here Sleep(100) Next The items within the arrays are completly different Is there a way to make this more compact? Like just one shellexecute? if you get what i mean Thanks for any help Edit typo Edited February 29, 2012 by Chimaera If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
water Posted February 29, 2012 Share Posted February 29, 2012 Write and call a function and pass the array and the information for shellexecute as parameters. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Chimaera Posted February 29, 2012 Author Share Posted February 29, 2012 (edited) sorry i don't understand my shellexecute looks like this for each of the elements ShellExecuteWait('sc.exe', 'config "' & $aManual[$d] & '" start= demand', "", "", @SW_HIDE) btw each shellexecute has a different command Edited February 29, 2012 by Chimaera If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
water Posted February 29, 2012 Share Posted February 29, 2012 (edited) I was thinking of something like that: Global $aManual[4] = [3, "item 1", "item 2", "item 3"] Global $aAuto[3] = [2, "item 4", "item 5"] Global $aAutoDelay[4] = [3, "item 6", "item 7", "item 8"] Select Case @OSVersion = "WIN_VISTA" _Process($aManual, "delayed-auto") _Process($aAuto, "auto") _Process($aAutoDelay, "demand") EndSelect Func _Process(ByRef $aArray, $sStart) For $d = 1 To $aArray[0] ShellExecuteWait('sc.exe', 'config "' & $aArray[$d] & '" start= ' & $sStart, "", "", @SW_HIDE) Sleep(100) Next EndFunc ;==>_Process Edited February 29, 2012 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Chimaera Posted February 29, 2012 Author Share Posted February 29, 2012 Unfortunately like i mentioned the 3 different arrays set 3 different actions to be performed so i cant use the same shellexecutewait I was kinda thinking of one command fits all type of scenario, but looking at it again im still going to need 3 shellexecutes to make it do three tasks Is it possible to load all the array data in one array? If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
water Posted February 29, 2012 Share Posted February 29, 2012 (edited) Then pass the "actions" to be shellexecuted as parameter to the function. Can you give an example of the 3 different shellexecutes? Edited February 29, 2012 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Chimaera Posted February 29, 2012 Author Share Posted February 29, 2012 Hmm ok here's the info ShellExecuteWait('sc.exe', 'config "' & $aAutoDelay[$f] & '" start= delayed-auto', "", "", @SW_HIDE) ; the only piece that changes is this bit like below start= delayed-auto start= auto start= demand If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
water Posted February 29, 2012 Share Posted February 29, 2012 I changed the code in post accordingly. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Chimaera Posted February 29, 2012 Author Share Posted February 29, 2012 Global $aManual[4] = [3, "item 1", "item 2", "item 3"] Global $aAuto[3] = [2, "item 4", "item 5"] Global $aAutoDelay[4] = [3, "item 6", "item 7", "item 8"] Select Case @OSVersion = "WIN_VISTA" _Process($aManual, "demand") _Process($aAuto, "auto") _Process($aAutoDelay, "delayed-auto") EndSelect Func _Process(ByRef $aArray, $sStart) For $d = 1 To $aArray[0] ShellExecuteWait('sc.exe', 'config "' & $aArray[$d] & '" start= ' & $sStart, "", "", @SW_HIDE) Sleep(100) Next EndFunc ;==>_Process Ok thx for that I get that you have created a func with 2 replaceable entries for the array name and the setting Now the bit im confused about is the ByRef isnt that to do with modifying a global on the fly? Is it for rereading the global as the next cycle happens? If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
water Posted February 29, 2012 Share Posted February 29, 2012 (edited) If you specify a parameter without "ByRef" the content is copied and passed to the function. The function only accesses the local copy. You need additonal cycles to copy the data and more RAM. The local copy of the data is destroyed when you end the function. ByRef just passes a pointer to the data. That's faster and uses less memory. Additional advantage: If you alter the data in the func the changed data is available in the main code. Edited February 29, 2012 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
BrewManNH Posted February 29, 2012 Share Posted February 29, 2012 One reason to pass an array using ByRef is in case the array is a large one, ByRef doesn't copy the data to a new array so it's faster and doesn't eat up as many resources (memory). If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Chimaera Posted February 29, 2012 Author Share Posted February 29, 2012 Aah ok so its more of a look here for the info kind of pointer and reuse what it finds Right ill have a play around with it and see what else i can break Thx for the pointers guys If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
kylomas Posted February 29, 2012 Share Posted February 29, 2012 chimaera, The following code watches what is starting and ending on my PC and based on a control array takes some action. Look particularly at the array "$a_watchlist". Maybe this will give you some ideas. expandcollapse popup#RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=..IconsSyslog.ico #AutoIt3Wrapper_Outfile_x64=..EXEsyslog.exe #AutoIt3Wrapper_UseUpx=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <array.au3> #include <date.au3> #include <string.au3> #include <process.au3> #Include <APIConstants.au3> #Include <WinAPIEx.au3> #Include <guiconstantsEx.au3> ;HotKeySet("{ESC}", "fini") Global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc"), $f_COMError = False init() #cs watchlist structure n,0 = process to watch for n,1 = program to run n,2 = program to run parm #1 n,3 = this slot intentionally left blank n,4 = run program when process starts n,5 = run program when process ends #ce local $a_watchlist[20][6] $a_watchlist[0][0] = "iexplore.exe" $a_watchlist[0][1] = "c:program filesccleanerccleaner64.exe" $a_watchlist[0][2] = "/auto" $a_watchlist[0][3] = "" $a_watchlist[0][4] = false $a_watchlist[0][5] = true $a_watchlist[1][0] = "wlmail.exe" $a_watchlist[1][1] = "c:program filesccleanerccleaner64.exe" $a_watchlist[1][2] = "/auto" $a_watchlist[1][3] = "" $a_watchlist[1][4] = false $a_watchlist[1][5] = true $a_watchlist[2][0] = "outlook.exe" $a_watchlist[2][1] = "c:program filesccleanerccleaner64.exe" $a_watchlist[2][2] = "/auto" $a_watchlist[2][3] = "" $a_watchlist[2][4] = false $a_watchlist[2][5] = true local $a_curractive, $a_prevactive = processlist() while guigetmsg() <> $gui_event_close $a_curractive = processlist() checkstarts() checkends() $a_prevactive = $a_curractive sleep(1000) wend func checkstarts() local $hit for $i = 1 to $a_curractive[0][0] $hit = false for $j = 1 to $a_prevactive[0][0] if $a_curractive[$i][0] = $a_prevactive[$j][0] and $a_curractive[$i][1] = $a_prevactive[$j][1] then $hit = True exitloop endif next if $hit = false then ; got something new, log it and check to see if we are watching for it lf(' ' & @computername & stringformat("[%-10.10s]",getuser($a_curractive[$i][1])) & ' ' & $a_curractive[$i][0] & ' / ' & $a_curractive[$i][1] & ' Started') for $k = 0 to ubound($a_watchlist,1) - 1 if $a_curractive[$i][0] = $a_watchlist[$k][0] then ;yes, we are watching for it, now what to do??? if $a_watchlist[$k][4] then shellexecute($a_watchlist[$k][1],$a_watchlist[$k][2]) lf(" Event: " & @username & @tab & $a_watchlist[$k][1] & $a_watchlist[$k][2] & " initiated by program start [" & $a_curractive[$i][0] & ']') endif EndIf next endif next endfunc func checkends() local $hit for $i = 1 to $a_prevactive[0][0] $hit = false for $j = 1 to $a_curractive[0][0] if $a_prevactive[$i][0] = $a_curractive[$j][0] and $a_prevactive[$i][1] = $a_curractive[$j][1] then $hit = True exitloop endif next if $hit = false then ; something ended, log it and see if we are watching for it lf(' ' & @computername & stringformat("[%-10.10s]",getuser($a_prevactive[$i][1])) & ' ' & $a_prevactive[$i][0] & ' / ' & $a_prevactive[$i][1] & ' Ended') for $k = 0 to ubound($a_watchlist,1) - 1 if $a_prevactive[$i][0] = $a_watchlist[$k][0] then ;yes, we are watching for it, now what to do??? if $a_watchlist[$k][5] then shellexecute($a_watchlist[$k][1],$a_watchlist[$k][2]) lf(" Event: " & @username & @tab & $a_watchlist[$k][1] & $a_watchlist[$k][2] & " initiated by program stop [" & $a_prevactive[$i][0] & ']') endif EndIf next endif next endfunc Func lf($le) Local $file $file = FileOpen('c:tmpsyslog', 1) If $file = -1 Then MsgBox(0,"Watcher Error", "Error Unable to open log file") exit EndIf FileWriteLine($file, @year & '-' & _ stringformat("%02s",@MON) & '-' & _ stringformat("%02s",@mday) & ' ' & _ stringformat("%02s",@hour) & ':' & _ stringformat("%02s",@min) & ':' & _ stringformat("%02s",@sec) & _ $le) FileClose($file) EndFunc func init() lf(_stringrepeat('==*==',20)) lf(' ') lf(' Starting SYSLOG') lf(' ') lf(_stringrepeat('==*==',20)) lf(' ') lf(' Options: ') lf(' ') lf(' Syslog started on ' & @computername & ' at ' & _Now() & ' by ' & @username) lf(' ') lf(' Currently Running Processes:') lf(' ') lf(' ' & stringformat("%-15s",'Computer Name') & ' ' & _ stringformat("%-15s",'User Name') & ' ' & _ stringformat("%-25s",'Process Name') & ' ' & _ stringformat("%-7s",'PID') & ' ' & _ stringformat("%-25s",'Start Date') & ' ' & _ stringformat("%-25s",'Parent Name') & ' ' & _ stringformat("%-10s",'Parent PID')) lf(' ' & _stringrepeat("-",15) & ' ' & _ _stringrepeat("-",15) & ' ' & _ _stringrepeat("-",25) & ' ' & _ _stringrepeat("-",7) & ' ' & _ _stringrepeat("-",25) & ' ' & _ _stringrepeat("-",25) & ' ' & _ _stringrepeat("-",10)) local $tasks = _pl() for $i = 0 to ubound($tasks) - 1 lf(' ' & stringformat("%-15s",@computername) & ' ' & _ stringformat("%-15s",$tasks[$i][5]) & ' ' & _ stringformat("%-25.25s",$tasks[$i][1]) & ' ' & _ stringformat("%-7s",$tasks[$i][2]) & ' ' & _ stringformat("%-25.25s",$tasks[$i][0]) & ' ' & _ stringformat("%-25.25s",$tasks[$i][4]) & ' ' & _ stringformat("%-10s",$tasks[$i][3])) next lf(' ') endfunc func _PL() local $wbemFlagReturnImmediately = 0x10 local $wbemFlagForwardOnly = 0x20 local $colItems = "" local $strComputer = "localhost" local $list[1000][45], $i = 1, $x $objWMIService = ObjGet("winmgmts:" & $strComputer & "") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process") ;, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) if isobj($colItems) then redim $list[$colitems.count + 1][6] If IsObj($colItems) then For $objItem In $colItems $list[$i][0] = WMIDateStringToDate($objItem.CreationDate) $list[$i][1] = $objItem.Name $list[$i][2] = $objItem.ProcessId $list[$i][3] = $objItem.ParentProcessId $list[$i][4] = _processgetname($list[$i][3]) $list[$i][5] = getuser($list[$i][2]) $i += 1 Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_Process" ) Endif return $list endfunc Func WMIDateStringToDate($dtmDate) Return (StringMid($dtmDate, 5, 2) & "/" & _ StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _ & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2)) EndFunc Func MyErrFunc() Local $HexNumber=hex($oMyError.number,8) Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _ "Number is: " & $HexNumber & @CRLF & _ "WinDescription is: " & $oMyError.windescription & @CRLF & _ "Source is: " & $oMyError.source & @CRLF & _ "ScriptLine is: " & $oMyError.scriptline) $f_COMError = True; Endfunc func getuser($pid) ; big "up" to ptrex for this routine !!! local $hToken, $Data, $aAdjust ; Enable "SeDebugPrivilege" privilege for obtain full access rights to another processes $hToken = _WinAPI_OpenProcessToken(BitOR($TOKEN_ADJUST_PRIVILEGES, $TOKEN_QUERY)) _WinAPI_AdjustTokenPrivileges($hToken, $SE_DEBUG_NAME, $SE_PRIVILEGE_ENABLED, $aAdjust) ; Retrieve user names for all processes the system If Not (@error Or @extended) Then $Data = _WinAPI_GetProcessUser($pid) If IsArray($Data) Then return $Data[0] Else return '' EndIf EndIf ; Enable SeDebugPrivilege privilege by default _WinAPI_AdjustTokenPrivileges($hToken, $aAdjust, 0, $aAdjust) _WinAPI_CloseHandle($hToken) endfunc func fini() Exit endfunc func dbg() lf(' *** Debugging *** ' & @crlf) lf(' Curractive ubound = ' & ubound($a_curractive) & @crlf) lf(' Prevactive ubound = ' & ubound($a_prevactive) & @crlf) for $i = 0 to ubound($a_curractive) - 1 lf(' ' & $i & ' - ' & $a_curractive[$i][0] & $a_curractive[$i][1] & @crlf) next for $i = 0 to ubound($a_prevactive) - 1 lf(' ' & $i & ' - ' & $a_prevactive[$i][0] & $a_prevactive[$i][1] & @crlf) next endfunc Good Luck, kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill 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