Jump to content

Using RunOnceEx for logon scripts


Recommended Posts

I have been playing around on my test network and making some improvements (aesthetic and functional).

Normally in my domains logon scripts I have a main script that calls smaller "function" scripts. This way I keep my code organized and easy to edit.

While perusing the Unattended setup page for some silent installer info I saw the section on RunOnceEX and thought to myself why cant I use this to make my logon scripts more user friendly and pretty". Well, it was actually easier than I thought. Here is what I did.

As I said before my logon script is composed of a "main" script and 3 "function" scripts. All are simple because I am redesigning my network at the moment and adding new features. Here is what my GlobalLogon.cmd used to look like.

@echo off
::
:: This is the core logon script for the test.net domain.
:: It launches all other logon scripts.
::

:START
::
:: Start of Script. Sets Variables.
::

SET logpath=\\test.net\NETLOGON

:CALLS
::
:: Logon sub-scripts are called here.
::

START "Setting default command prompt path to drive root" /I /WAIT %logpath%\Cmd.cmd
START "Mapping network drives" /I /WAIT %logpath%\MapDrives.cmd
START "Adding BGinfo information to your background" /I /WAIT %logpath%\BGinfo.cmd

:PAUSE
::
:: Pause for debugging (disabled by default)
::

::pause

:END
::
:: End of script
::

EXIT

Using some information from http://unattended.msfn.org/unattended.xp/view/web/31/ I converted the central 3 calls to REG ADD entries. Normally the computer will wait until it restarts to run registry values added here so I had to find a way to manually launch the RunOnceEX process.

the solution is to add your values to the registry and use this line of code.

rundll32.exe iernonce.dll,RunOnceExProcess

I still wanted the functions to be run in their own .cmd scripts. So I just used the RunOnceEX to launch these command separately like I was doing in my original. This was however, quite ugly, and the whole point of this was to neaten up the look of things. So I found a small window hiding program called Hidec.exe and added it in to each line.

Here is my new improved GlobalLogon.cmd

@echo off
::
:: This is the core logon script for the test.net domain.
:: It launches all other logon scripts.
::

:START
::
:: Start of Script. Sets Variables.
::

SET logpath=\\test.net\NETLOGON
SET KEY=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx

:RUNONCE
::
:: Adds items to Runonce to be used for the logon script
::

REG ADD %KEY% /V TITLE /D "Running Logon Scripts" /f

REG ADD %KEY%\005 /VE /D "Setting default command prompt path to drive root" /f
REG ADD %KEY%\005 /V 1 /D "%logpath%\hidec /w %logpath%\Cmd.cmd" /f

REG ADD %KEY%\010 /VE /D "Mapping network drives" /f
REG ADD %KEY%\010 /V 1 /D "%logpath%\hidec /w %logpath%\MapDrives.cmd" /f

REG ADD %KEY%\015 /VE /D "Adding BGinfo information to your background" /f
REG ADD %KEY%\015 /V 1 /D "%logpath%\hidec /w %logpath%\BGinfo.cmd" /f

rundll32.exe iernonce.dll,RunOnceExProcess

:PAUSE
::
:: Pause for debugging (disabled by default)
::

::pause

:END
::
:: End of script
::

EXIT

Works like a charm. Hope this is helpful to some people.

I attached a .jpg for those of you who want to see the results.

Link to comment
Share on other sites


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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...