Jump to content
MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. ×

Runonce for all users?


Recommended Posts

Is there a way of having a registry key to run once for all users,

e.g. every time a user logs onto a pc for the first time it runs a batch file?

fred bloggs logs in, a batch file runs and the next time he logs in it doesnt kick in again,

john smith logs in on the same computer for the first time and it kicks in the run once to run the batch file?

Cheers

superblades

Link to post
Share on other sites

HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce

When an entry is applied when no one is logged on, the entry goes to the HKU\.DEFAULT part of the registry. This allows for the RunOnce operation for each account as each logon happens. An ideal time is from Cmdlines.txt to add the entry into this registry key.

Edited by MHz
Link to post
Share on other sites
HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce

When an entry is applied when no one is logged on, the entry goes to the HKU\.DEFAULT part of the registry. This allows for the RunOnce operation for each account as each logon happens. An ideal time is from Cmdlines.txt to add the entry into this registry key.

So i have to run : HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce from Cmdlines.txt ?

Link to post
Share on other sites
So i have to run : HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce from Cmdlines.txt ?

You add an entry into HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce which will runonce for each user account. This is only achieved when no one is logged on. Cmdlines.txt is a good time to add the entry into registry.

btw, run was not mentioned. Hopefully, this explaination is easier to understand. :)

Link to post
Share on other sites
@MHz:

Can you make an example of running a .cmd script from the registry RunOnce?

Thank you in advance.

This is a basic example:

Within your $OEM$ directory, you will need Cmdlines.txt, UserRunOnce.cmd and FirstLogon.cmd.

Cmdlines.txt:

[COMMANDS]
"UserRunOnce.cmd"

UserRunOnce.cmd:

REM ~ Execute this from Cmdlines.txt within the same directory.
REM ~ Requirement is also FirstLogon in same directory.

@echo off
Copy /y FirstLogon.cmd %SystemRoot%
Attrib +RSH %SystemRoot%\FirstLogon.cmd
Reg Add HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce /v FirstLogon /d FirstLogon.cmd /f

FirstLogon.cmd:

@echo off
echo this is a test of runonce execution of a cmdfile
pause

1. Cmdlines.txt will execute at T12 and execute UserRunOnce.cmd.

2. UserRunOnce.cmd will copy FirstLogon.cmd to the Windows directory and will hide it with attributes. An entry will be added to the HKCU Runonce key which will execute for each account upon first logon (even accounts created later).

3. FirstLogon.cmd has only test code but you can add cleanup commands or other suitable commands for your needs.

:)

To simply test, just put UserRunOnce.cmd and FirstLogon.cmd on your desktop and execute UserRunOnce.cmd. Log off and logon. When entering the desktop, you should see FirstLogon.cmd execute from the Windows Directory. Test OK. Go to Run and type del %systemroot%\firstlogon.cmd to remove the file from your Windows directory.

Do note: The HKCU RunOnce entry will be redirected to the default user part of the registry when no one is logged on.

Edited by MHz
Link to post
Share on other sites
  • 1 year later...
  • 1 month later...
So i have to run : HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce from Cmdlines.txt ?

You add an entry into HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce which will runonce for each user account. This is only achieved when no one is logged on. Cmdlines.txt is a good time to add the entry into registry.

btw, run was not mentioned. Hopefully, this explaination is easier to understand. :)

Hi there!

I'm searching for the RunOnce Key for every new and every existing user on a machine. After an installation there has to be some user-specific work to be done.

So, I found this post. Great so far! :thumbup

But here's the problem: Mhz wrote "This is only achieved when no one is logged on.". How do I achieve this? In a XP-new-installation I'm using cmdlines-txt for this, but how to when the computer ist ready installed?

Thanks a lot,

BangBang

Link to post
Share on other sites
So i have to run : HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce from Cmdlines.txt ?

You add an entry into HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce which will runonce for each user account. This is only achieved when no one is logged on. Cmdlines.txt is a good time to add the entry into registry.

btw, run was not mentioned. Hopefully, this explaination is easier to understand. :)

Hi there!

I'm searching for the RunOnce Key for every new and every existing user on a machine. After an installation there has to be some user-specific work to be done.

So, I found this post. Great so far! :thumbup

But here's the problem: Mhz wrote "This is only achieved when no one is logged on.". How do I achieve this? In a XP-new-installation I'm using cmdlines-txt for this, but how to when the computer ist ready installed?

Thanks a lot,

BangBang

I believe you will need to change the above example (HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce) to HKU\.default\Software\Microsoft\Windows\CurrentVersion\RunOnce and run it whilst logged into your regular profile or user account.

Try it and see!

Link to post
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...