#74278 - 2003-04-01 05:36 PM
Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Before I post this in the UDF forum, I'd like to solicit comments on this function.
This function uses the RunOnceExProcess to execute tasks using the iernonce.dll. I don't know what version dependencies are required for this to work with iernonce.dll so if anyone has any insight into that it would be helpful.
A sample is included in the code below. Once you run the sample, I think you'll see the potential that this script has.
Break On
$nul=SetOption("Explicit","ON")
Dim $
fnRunOnceEx("z001","Waiting for wordpad to close","wordpad.exe") fnRunOnceEx("100","Waiting for notepad to close","notepad.exe") @ERROR " : " @SERROR ? Shell "rundll32.exe iernonce.dll,RunOnceExProcess"
;Get $
Function fnRunOnceEx($sCMDKey,$sTitle,$sCMD,Optional $sComputer) Dim $sRunKey,$lIndex,$sExKey,$nul $sRunKey="HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnceEx" If $sComputer $sRunKey = "\\"+$sComputer+"\"+$sRunKey EndIf If KeyExist($sRunKey+"\"+$sCMDKey) ; If $sCMDKey exists and does not equal the title, the function exits assuming that ; the coder is incorrectly attempting to overwrite an existing key. If Not ReadValue($sRunKey+"\"+$sCMDKey,"")=$sTitle Exit 6 EndIf ; Enumerate the values in the $sCMDKey, if a match is found for $sCMD the function ; exits assuming the coder is duplicating a command. $lIndex=0 $sExKey=EnumValue($sRunKey+"\"+$sCMDKey,$lIndex) Do If ReadValue($sRunKey+"\"+$sCMDKey,$lIndex)=$sCMD Exit 1152 EndIf $lIndex=$lIndex+1 $sExKey=EnumValue($sRunKey+"\"+$sCMDKey,$lIndex) Until @ERROR ; After evaluating that the $sCMD does not already exist it is ok to write the $sCMD font> ; to the registry. $nul=WriteValue($sRunKey+"\"+$sCMDKey,$lIndex,$sCMD,REG_SZ) Exit @ERROR Else If Not AddKey($sRunKey+"\"+$sCMDKey)=0 Exit @ERROR EndIf $nul=WriteValue($sRunKey+"\"+$sCMDKey,"",$sTitle,REG_SZ) If @ERROR Exit @ERROR EndIf $nul=WriteValue($sRunKey+"\"+$sCMDKey,"1",$sCMD,REG_SZ) Exit @ERROR EndIf EndFunction
[ 02. April 2003, 17:45: Message edited by: Chris S. ]
|
|
Top
|
|
|
|
#74285 - 2003-04-02 03:55 PM
Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
|
|
Top
|
|
|
|
#74286 - 2003-04-02 04:00 PM
Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
|
|
Top
|
|
|
|
#74287 - 2003-04-02 04:15 PM
Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
|
Breaker
Hey THIS is FUN
   
Registered: 2001-06-15
Posts: 268
Loc: Yorkshire, England
|
|
|
Top
|
|
|
|
#74289 - 2003-04-02 04:49 PM
Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
can you toss in optional $computer so it can be used against remote computers.
what about if the user that is execing this doesn't have admin... could it write to hkcu?
$localgr= '\\'+ @wksta +'\administrators','\\'+ @wksta +'\power users' $admin = 0 + @inwin + ingroup($localgr) - 1 if $admin $key='hklm' else $key='hkcu' endif [ 02. April 2003, 16:53: Message edited by: Radimus ]
|
|
Top
|
|
|
|
#74295 - 2003-04-02 10:06 PM
Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
OK.. what about this.
copy '\\server\share\folder\hotfix1' '\\'+$computer+'\c$$\temp\hotfix1' copy '\\server\share\folder\hotfix2' '\\'+$computer+'\c$$\temp\hotfix2'
fnRunOnceEx("001","Installing hotfix 1","c:\temp\hotfix1\some.exe",$computer) fnRunOnceEx("002","Installing hotfix 2","c:\temp\hotfix2\some.exe",$computer) fnRunOnceEx("003","cleaning up hotfix 1","cmd /c rd c:\temp\hotfix1\",$computer) fnRunOnceEx("004","cleaning up hotfix 2","cmd /c rd c:\temp\hotfix2\",$computer)
Does this exec under system context, or user context upon reboot
or does it even auto exec on restart, or do you have to call Shell "rundll32.exe iernonce.dll,RunOnceExProcess" [ 02. April 2003, 22:08: Message edited by: Radimus ]
|
|
Top
|
|
|
|
#74297 - 2003-04-03 03:19 AM
Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
So you could potentially have this run as the logon script...
This might be a solution for all those win9x machines and the cancel button issue they have
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1376 anonymous users online.
|
|
|