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
        ; 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. ]