Trying to change values in the registry through scripting

Discussion in 'Programming/Html' started by WhiteLightning, Feb 13, 2020.

  1. WhiteLightning

    WhiteLightning Don Illuminati Staff Member

    Messages:
    28,212
    Likes Received:
    1,137
    GPU:
    GTX1070 iChillx4
    Hello!

    another brain breaker for me! i am trying to change some key values through scripting.
    the thing is the path needs to have a wildcard in it.

    the real path is:

    HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0001\Ndi\Params\*FlowControl

    keyname = Default
    type = REG_SZ
    data 3

    Basicly i would like to change the data (is 3 now) to 0 , where {4d36e972-e325-11ce-bfc1-08002be10318} is the wildcard, so can be changed with every value.

    i have tried many things, like

    Code:
    FOR /F "tokens=8 delims=-" %G IN ('reg query HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class" ^| find "*FlowControl" ^| find /v "Default"') DO reg add HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\%G\0000\Ndi\Params\*FlowControl /v Default /t REG_SZ /d 0 /f
    
    but it gives the error "G\0000\Ndi\Params\*FlowControl was unexpected at this time."


    Does anyone have a clue what I am doing wrong here ? ive been trying for about 2hrs now, and i am really lost.
     
  2. mbk1969

    mbk1969 Ancient Guru

    Messages:
    8,579
    Likes Received:
    5,477
    GPU:
    GeForce GTX 1070
    Ain`t your script misses one double quote at the beginning of registry path HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class?

    Corrected one
    Code:
    FOR /F "tokens=8 delims=-" %G IN ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class" ^| find "*FlowControl" ^| find /v "Default"') DO reg add HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\%G\0000\Ndi\Params\*FlowControl /v Default /t REG_SZ /d 0 /f
    
     
    WhiteLightning likes this.
  3. mbk1969

    mbk1969 Ancient Guru

    Messages:
    8,579
    Likes Received:
    5,477
    GPU:
    GeForce GTX 1070
    And second thought - try to replace "%G" with "%%G".
     
  4. WhiteLightning

    WhiteLightning Don Illuminati Staff Member

    Messages:
    28,212
    Likes Received:
    1,137
    GPU:
    GTX1070 iChillx4
    Thanks for the reply. It doesnt give any error this time, although it stays at its value 3 after i refresh in regedit.
    could it be it is protected because the folder if you call it that has a * in its name ? *Flowcontrol
     

  5. mbk1969

    mbk1969 Ancient Guru

    Messages:
    8,579
    Likes Received:
    5,477
    GPU:
    GeForce GTX 1070
    You can debug your script just by echoing the results on the screen
    Code:
    FOR /F "tokens=8 delims=-" %%G IN ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class" ^| find "*FlowControl" ^| find /v "Default"') DO echo '%%G'
    
    As for protection, you can check the security properties in regedit.
     
  6. WhiteLightning

    WhiteLightning Don Illuminati Staff Member

    Messages:
    28,212
    Likes Received:
    1,137
    GPU:
    GTX1070 iChillx4
    ah damn , its giving the error %%G was unexpected at this time. with the debug line.
     
  7. mbk1969

    mbk1969 Ancient Guru

    Messages:
    8,579
    Likes Received:
    5,477
    GPU:
    GeForce GTX 1070
    Btw, what are '^' characters for?
     
  8. WhiteLightning

    WhiteLightning Don Illuminati Staff Member

    Messages:
    28,212
    Likes Received:
    1,137
    GPU:
    GTX1070 iChillx4
    I really dont know. It was in one of the examples i picked up from the net.

    removing it , so its just | gives the same result btw. I have also tried with just %g instead of %%g.
     
  9. mbk1969

    mbk1969 Ancient Guru

    Messages:
    8,579
    Likes Received:
    5,477
    GPU:
    GeForce GTX 1070
    When you use FOR from command line you should use "%G", when in script - "%%G".

    And the '^' is used to escape the pipeline '|' in commands written in the string inside the IN.

    I have tried
    reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class"
    and it returns only GUIDs.
    PS If you are trying to get registry values under all registry keys there, then you should find proper command.
     
  10. WhiteLightning

    WhiteLightning Don Illuminati Staff Member

    Messages:
    28,212
    Likes Received:
    1,137
    GPU:
    GTX1070 iChillx4
    the problem is the key is "default" under a subfolder (*FlowControl*).

    if i search for default, all gui's will be named. thats why i needed a wildcard to search for the *flowcontrol folder and look for a key called Default in there.
     

  11. mbk1969

    mbk1969 Ancient Guru

    Messages:
    8,579
    Likes Received:
    5,477
    GPU:
    GeForce GTX 1070
    You will not find subkeys of values by
    reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class"

    It will list all keys under the "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class".

    Btw, you can use short form "HKLM" instead of "HKEY_LOCAL_MACHINE".
     
  12. WhiteLightning

    WhiteLightning Don Illuminati Staff Member

    Messages:
    28,212
    Likes Received:
    1,137
    GPU:
    GTX1070 iChillx4
    oh well i will try again tomorrow. this thing made me really tired lol

    thanks for the help and explanations so far though!
     
  13. mbk1969

    mbk1969 Ancient Guru

    Messages:
    8,579
    Likes Received:
    5,477
    GPU:
    GeForce GTX 1070
    You can list all keys and subkeys and values with this command
    reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class" /s
     
  14. mbk1969

    mbk1969 Ancient Guru

    Messages:
    8,579
    Likes Received:
    5,477
    GPU:
    GeForce GTX 1070
    And another "btw" - we can do it in PowerShell script. (Whatever we want, PowerShell is at our service!)
     

Share This Page