none
RunOnce for all existing AND new user

    질문

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


    • 편집됨 Parvez Akkas 2012년 4월 23일 월요일 오후 6:23
    2012년 4월 23일 월요일 오후 6:18

모든 응답

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

    2012년 4월 23일 월요일 오후 7: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)


    • 편집됨 Braeden.Saxon 2017년 6월 19일 월요일 오후 10:22 Typo
    2015년 6월 23일 화요일 오전 9: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.

    2015년 10월 22일 목요일 오후 6: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

    2017년 12월 13일 수요일 오후 10: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?

    • 편집됨 Eddga 2018년 6월 26일 화요일 오후 5:47
    2018년 6월 26일 화요일 오후 5: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.

    • 편집됨 MZ6569 2018년 7월 17일 화요일 오후 6:34 Add info
    2018년 7월 17일 화요일 오후 6:34