none
RunOnce for all existing AND new user

    Pergunta

  • 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/


    • Editado Parvez Akkas segunda-feira, 23 de abril de 2012 18:23
    segunda-feira, 23 de abril de 2012 18:18

Todas as Respostas

  • 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/

    segunda-feira, 23 de abril de 2012 19:30
  • 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)


    • Editado Braeden.Saxon segunda-feira, 19 de junho de 2017 22:22 Typo
    terça-feira, 23 de junho de 2015 09:49
  • 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.

    quinta-feira, 22 de outubro de 2015 18:52
  • 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

    quarta-feira, 13 de dezembro de 2017 22:13
  • 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?

    • Editado Eddga terça-feira, 26 de junho de 2018 17:47
    terça-feira, 26 de junho de 2018 17:45
  • 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.

    • Editado MZ6569 terça-feira, 17 de julho de 2018 18:34 Add info
    terça-feira, 17 de julho de 2018 18:34