[Q:] VBS Script for import to registry

Discussion in 'Windows 8' started by moderate, Oct 31, 2014.

  1. moderate

    moderate MDL Guru

    Aug 31, 2009
    2,636
    2,143
    90
    #1 moderate, Oct 31, 2014
    Last edited by a moderator: Apr 20, 2017
    Hello,

    I need to import something like this to registry:

    Code:
    [HKEY_USERS\S-1-5-21-916612875-1494325352-2862801814-1001\Control Panel\Keyboard]
    "InitialKeyboardIndicators"="2"
    
    However the number "916612875-1494325352-2862801814-1001" is different in each Windows installation.

    So I need the hint from somebody for VBS script, which will retrieve the correct number from the registry 1st and then do the import.

    Thanks. :)
     
  2. abbodi1406

    abbodi1406 MDL KB0000001

    Feb 19, 2011
    7,547
    23,981
    240
    #2 abbodi1406, Oct 31, 2014
    Last edited by a moderator: Apr 20, 2017
    Code:
    [hkey_users\s-1-5-21-916612875-1494325352-2862801814-1001] = [hkey_current_user]
    
     
  3. moderate

    moderate MDL Guru

    Aug 31, 2009
    2,636
    2,143
    90
    #3 moderate, Oct 31, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Yep, but when I try to import to HKCU, the values are generally synced to S-1-5-21-xxx after the reboot and for example in this particular case the reboot also clears the value in HKCU before it is synced to S-1-5-21-xxx.
     
  4. abbodi1406

    abbodi1406 MDL KB0000001

    Feb 19, 2011
    7,547
    23,981
    240
  5. HALIKUS

    HALIKUS MDL Addicted

    Jul 29, 2009
    527
    369
    30
    #5 HALIKUS, Oct 31, 2014
    Last edited by a moderator: Apr 20, 2017
    You mention the value clears after the reboot. Is this because you are running it in a setupcomplete.cmd? If so, i have some tricks that may help. The problem is HKCU values don't stick after the reboot. However, the old "RunOnceEx" trick works and i use it to run a firstlogon from setupcomplete.cmd after the first reboot that basically just runs HKCU reg entries. I use a different non-cmd way, but in cmd form i think its...

    Code:
    :RunOnceEx
    SET KEY=HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnceEx
    REG DELETE %KEY% /f
    cls
    Echo. & Echo Add RunonceEX & Echo.
    REG ADD %KEY% /f
    REG ADD %KEY% /V TITLE /D "RunOnceEx Applications" /f
    REG ADD %KEY% /V Flags /t REG_DWORD /d "20" /f
    
    if %PROCESSOR_ARCHITECTURE% == x86 (
    If Exist %windir%\setup\Firstlogon\Firstlogon.exe REG ADD %KEY%\0010 /VE /D "Run Firstlogon.exe" /f
    If Exist %windir%\setup\Firstlogon\Firstlogon.exe REG ADD %KEY%\0010 /V 1 /D "%windir%\setup\Firstlogon\Firstlogon.exe" /f
    ) else (
    If Exist %windir%\setup\Firstlogon\Firstlogon_x64.exe REG ADD %KEY%\0010 /VE /D "Run Firstlogon_x64.exe" /f
    If Exist %windir%\setup\Firstlogon\Firstlogon_x64.exe REG ADD %KEY%\0010 /V 1 /D "%windir%\setup\Firstlogon\Firstlogon_x64.exe" /f
    )
    rundll32.exe iernonce.dll,RunOnceExProcess
    goto :eof
    
    As for the changing value, i love figuring out tricks like this. If it were me, i would do something along the lines of retrieving the value with maybe a stdout, and then on the fly writing a reg file from scratch with a >null regfile.reg type trick, and then run reg import to the created .reg file. This can be done with the runonce trick above, or by having a cmd in the startup folder in the start menu that runs the reg and self deletes. I know how to do all this easy enough with autoit but not sure with vbs or cmd.
     
  6. Mr Jinje

    Mr Jinje MDL Expert

    Aug 19, 2009
    1,773
    1,080
    60
    #6 Mr Jinje, Nov 1, 2014
    Last edited by a moderator: Apr 20, 2017