Page 1 of 2 12>
Topic Options
#74278 - 2003-04-01 05:36 PM Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
Chris S. Offline
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
        ; 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
#74279 - 2003-04-01 06:12 PM Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
What is the difference between this UDF and e.g. RunOnce() - Writes a run-once event into the registry . What are the advantages of RunOnceEx. Also, you'll need to check for admin privileges as you write to HKLM.
_________________________
There are two types of vessels, submarines and targets.

Top
#74280 - 2003-04-01 06:14 PM Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
The difference is the GUI that is displayed by the OS while the tasks are running.
Top
#74281 - 2003-04-01 06:17 PM Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Ah, just checked it out. It requires the Windows Desktop Update (see Syntax for the RunOnceEx Registry Key )

[ 01. April 2003, 18:18: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#74282 - 2003-04-01 06:21 PM Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Thanks for that link. Basically, the same dependencies as GUICopy (I think). I'll have to test that.
Top
#74283 - 2003-04-01 06:27 PM Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Updated example script. This runs a little cleaner (e.g. no cmd window is needed). The example also demonstrates that the cmds are not executed by order entered, but rather in alphabetical order.
Top
#74284 - 2003-04-02 03:52 PM Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Anymore comments? Good? Bad? Indifferent?
Top
#74285 - 2003-04-02 03:55 PM Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Indifferent [Wink]

No, honestly just not recognized yet [Razz]
_________________________



Top
#74286 - 2003-04-02 04:00 PM Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Just ran this (On NT WKSTA) and my humble opinion is :

[Eek!] [Eek!] [Eek!] [Eek!] [Eek!]

Why don't you go and post this GEM! over at the Library forum ?
_________________________



Top
#74287 - 2003-04-02 04:15 PM Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
Breaker Offline
Hey THIS is FUN
*****

Registered: 2001-06-15
Posts: 268
Loc: Yorkshire, England
I like it. Lots. [Smile] [Big Grin] [Razz] [Cool] [Roll Eyes]

Certainly gets my vote. Besides, isn't Microsoft encouraging the use of the RunOnceEx key so that they can begin to eradicate the lowly RunOnce key from future versions?
_________________________
================================================
Breaker


Top
#74288 - 2003-04-02 04:23 PM Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
I'll play with it as soon as I'll find time. I already have a nice little use for this. Already looking forward to this.

[ 02. April 2003, 16:56: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#74289 - 2003-04-02 04:49 PM Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
Radimus Moderator Offline
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 ]
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#74290 - 2003-04-02 05:47 PM Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Updated beta function. Now with more descriptive error codes. Added optional computer. If user doesn't have rights to write to registry the exit code will indicate so.
Top
#74291 - 2003-04-02 05:50 PM Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
RunOnceEx doesn't seem to be in the HKCU hive. I'm really busy right now and can't test and see if it will work from HKCU if added. Anyone?
Top
#74292 - 2003-04-02 05:54 PM Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Ok, I lied. I did have time. And...it does work from HKCU.
Top
#74293 - 2003-04-02 09:37 PM Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Hmmmm.. Chris, cool deal.

Now, what about ideas/suggestions for usage?

Why do you guys think this would/could be good for in production usage?

Top
#74294 - 2003-04-02 09:45 PM Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Well, I'm going to use it as part of my Sysprep process. In my sysprep process, there is a portion where the tech can select additional applications to install that aren't part of the standard image (CD burner software, telnet client, Iomega software, etc.). This will set these applications to run (in unattended mode) and still provide a "task list" of where they are in the installation process.

Basically, one could use it anywhere they wanted to show a task-based progress list. It is "designed" to be run during startup, but since the RunOnceEx process can be started with RunDLL32 it can be started whenever the coder wants. Basically a simple GUI that doesn't require third-party DLL's (sorry Shawn).

Top
#74295 - 2003-04-02 10:06 PM Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
Radimus Moderator Offline
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 ]
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#74296 - 2003-04-03 02:32 AM Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
It'll definitely run at startup. Actually, it runs right after login and before explorer starts. As far as the system context, I think it runs as user.
Top
#74297 - 2003-04-03 03:19 AM Re: Beta Function: fnRunOnceEx() - Uses the RunOnceExProcess to execute tasks
Radimus Moderator Offline
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
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
Page 1 of 2 12>


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 675 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.072 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org