none
RunOnce for all existing AND new user

    Question

  • Hi,

    I need to add some registry entries under HKEY_CURRENT_USER and this is only required Once for all users (existing and new).

    I used the following registry entry to run a command line that will import my predefined registry settings from a .reg file into HKEY_CURRENT_USER

     - HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce

    This works fine, but it only works for 1 user that logs in after rebooting the computer. I need this to happen for all existing users AND new users.

    I tried using the following registry entry to run the command line for importing my custom reg entries

    - HKEY_USERS\.DEFAULT\Software\Microsoft\Wiindows\CurrentVersion\RunOnce

    I thought the above would take care of running my command line once for all the new user that logs in. I tried multiple times, but this isn't seem to be working. Deleted the test user profile from the computer but after logging in as a new user, it turns out that my command line isn't being executed.

    And, this doesn't solve my problem of running the my command line for all existing users.

    Can you please advise? If you need more info, please let me know.

    Thanks,


    Pman
    http://www.pmansLab.com/


    Monday, April 23, 2012 6:18 PM

All replies

  • Shortly after posting this, I found part of my solution in the following link:

    http://ss64.org/viewtopic.php?id=377

    Basically the following script will add my commands into the default profile hive that is loaded temporarily

    REG LOAD HKU\TEMP "C:\Documents and Settings\Default User\NTUSER.DAT"
    REG ADD HKU\TEMP\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /v myValue/d "regedit /s \"C:\\Program Files\\Common Files\\myregistry.reg\"" /f
    REG UNLOAD HKU\TEMP

    So, that takes care of any new user logging into the computer. I need to do the same thing for all existing users on the computer. Is there any easier way of doing this besides going through each user profiles?


    Pman
    http://www.pmansLab.com/

    Monday, April 23, 2012 7:30 PM
  • Want to know how I did it?

    I use a for loop to execute a command for all user directories that contain a NTUSER.DAT. See below

    FOR /D %%D IN ("C:\Users\*") DO IF EXIST "%%D\NTUSER.DAT" REG LOAD HKU\TEMP "%%D\NTUSER.DAT" && (REG ADD HKU\TEMP\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /v value /t REG_SZ /d data /f & REG UNLOAD HKU\TEMP)


    Tuesday, June 23, 2015 9:49 AM
  • Your script is helpful except for one thing... I believe each instance should be "ntuser.dat" not "ntusers.dat". I almost gave up using it until I saw that typo. Thanks.

    Thursday, October 22, 2015 6:52 PM
  • REG LOAD HKU\TEMP "C:\Users\Default\ntuser.dat"
    REG ADD HKU\TEMP\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /v NewRegKey /t REG_SZ /d "C:\Scripts\Script1.bat" /f
    REG UNLOAD HKU\TEMP

    this method works like a charm. never fails

    Wednesday, December 13, 2017 10:13 PM
  • REG LOAD HKU\TEMP "C:\Users\Default\ntuser.dat"
    REG ADD HKU\TEMP\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /v NewRegKey /t REG_SZ /d "C:\Scripts\Script1.bat" /f
    REG UNLOAD HKU\TEMP

    this method works like a charm. never fails

    Sorry for grave digging a post that already dug the thread. But doesn't your solution only do the trick for new users?

    • Edited by Eddga Tuesday, June 26, 2018 5:47 PM
    Tuesday, June 26, 2018 5:45 PM
  • Yes, it does only apply to newly create user accounts.

    If you want to apply to all currently create user accounts as well as all new users, I'd recommend using PSADT (powershell app deployment toolkit). There is a commandlet in there to do just that.

    [scriptblock]$HKCURegistrySettings = {
        Set-RegistryKey -Key 'HKEY_CURRENT_USER\SOFTWARE\Classes\AppX4hxtad77fbk3jkkeerkrm0ze94wjf3s9' -Name 'NoOpenWith' -Value '""'-Type String -ContinueOnError:$True
    }
    Invoke-HKCURegistrySettingsForAllUsers -RegistrySettings $HKCURegistrySettings

    Works great for needing to write a few one-liners to the current user as well as default user.

    The alternatives are Group Policy or Active Setup. And Active Setup can get messy - depending on how much you use it.

    • Edited by MZ6569 Tuesday, July 17, 2018 6:34 PM Add info
    Tuesday, July 17, 2018 6:34 PM