Hello, how can I do it better instead of adding a lot of duplicate same command for the purpose? I have a command: REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0000" /v PnPCapabilities /t REG_DWORD /d 00000024 /f Where 0000 I am currently using a number up to 0020 as you can see here: My goal is to have the PnPCapabilities value added in those places and set to a DWORD value of 24. This sets the network adapter in device manager under power management to uncheck "allow the computer to turn off this device to save power": My problem is that I currently have the same REG ADD command duplicated 20 times with numbers from 0000 to 0020 so that some setting hits the right key value in the registry and correctly sets this value for the network card I'm running on. Also, the problem is that it has to work for my current Intel(R) Ethernet Connection (2) I218-V NIC name but always for any system and PC/Laptop where I will apply my script with settings for this purpose. Why am I using 20 duplicate REG ADD values from 0000 to 0024? Because during the installation of drivers for the network card, virtualbox and others, the network card is not always fixed under a fixed number, e.g. 0000 and after each installation of the system and various drivers, and depending on whether it is a LAN or WLAN card and how many of them are system, this causes the PnPCapabilities value to be in a random location. How can I make PnPCapabilities be added and set to DWORD 24 only in those places where it is really needed, so that I don't need to add numbers in the range 0000 -> 0020 or more where they are not needed? As you can see in the screenshot, there are 24 items in the registry and I didn't think that setting the bar of duplicate values so high would turn out to be smaller than they really can exist in the registry. This shows that my way works poorly and is wrong. If someone suggest me a better working way, it will be a relief for me from the pain that is currently going on with the REG ADD duplication: Perhaps something that will first check if the REG_SZ value named DriverDesc is in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318} in numbers from 0000 to 0050, e.g. to be sure. And then PnPCapabilities set to a DWORD value of 24 only in those places where REG_SZ named DriverDesc was found and detected ?
I guess someone better than me in batch (almost anyone actually) will explain it in detail, but, for starters, take a look at the FOR /L batch command.
I secretly believe he's saving me @abbodi1406 because very often I get help from him for me, but of course if someone else is able to help me, I will be grateful to everyone and respect will belong to him If I manage to find a way for the network card, I will also be able to apply it to the graphics card for the video super resolution parameter which is in the nvidia control panel and improves the quality of displayed materials on a computer with a compatible video player. This is specifically about HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000\_User_Global_VAL_SuperResolution where 0000 is again the place of the device / driver order and I can't add it rigidly to 0000 because there can be two cards in latpop and it can already be, for example, in 0001. And in a desktop computer you can have, for example, Intel + two cards in SLI or something similar and then there will be 3 numbers, i.e. 0000 / 0001 / 0002 and then again I would have to duplicate REG ADD to always hit the right hardware and driver order in the system.
Code: for /L %%i in (0,1,9) do REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\000%%i" /v PnPCapabilities /t REG_DWORD /d 24 /f for /L %%i in (10,1,20) do REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\00%%i" /v PnPCapabilities /t REG_DWORD /d 24 /f
Thanks! I'm not sure. I need to use two lines for /L %%i in (0,1,9 and for /L %%i in (10,1,20) one after the other? What does it look like exactly? This will search from 0 to 20? If it is 24 will it also find that value and add it or will the limit be 20? Thanks in advance for any additional explanations.
So the value should always be 24. I misinterpreted it. It was not about the value of 24, but about the number of positions, i.e. 0000 up to 0024, etc As you can see, it inserted 21 items: I have 12 items of network adapters from device manager: Is there a chance to improve REG ADD Z FOR so that it adds only as many items as it detects in the device manager physically and not one more? So for me it should only search and add REG ADD 12 times. Btw. And can we make FOR ignore everything that has "WAN Miniport" and "VirtualBox" in the name This would only focus on the real used LAN/WLAN cards in the system instead of the virtual ones, etc. This would add an entry once or twice when there are wlan and lan cards together except for the exceptions when someone has multiple lan/wlan but then it would add just a bit more. But not as many as 21 items.
Code: @echo off set "key=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}" for /L %%i in (0,1,9) do call :Add 0%%i for /L %%i in (10,1,20) do call :Add %%i pause exit /b :Add REG QUERY "%key%\00%1" 2>nul && REG ADD "%key%\00%1" /v PnPCapabilities /t REG_DWORD /d 24 /f exit /b
I checked this just for a test and unfortunately it still adds a minimum of 20 items. I entered 15 to see the changes and as you can see 15 also appeared for item 0020 where there really is no network card and its settings: Is there anything else I can do to make it only consider current network cards? @Dark Dinosaur Can you suggest something? hmm
The two lines are necessary because of handling of leading zeros. 0 to 9 needs 3 and 10 to 20 needs only two. 100 to 999 would then need one and 1000 to 9999 none, but more than 20 is probably overkill.
Now I know why it's working badly for me now. My old script added 20 duplicate REG ADDs from 0000 to 0020 That's why I have so many subkeys in the system, even empty ones the new commands even search for empty subkeys where a PnPCapabilities value is already present. Can we do something to make it ignore empty subkeys where there is no REG_SZ value named DriverDesc ? Or make it ignore names like "WAN Miniport" and "VirtualBox" to avoid adding values for PnPCapabilities there.
we can use regex ... and add 0-unlimited ... regex match ... 0-X .. do ... i did use regex for stuff etc. its kinda fun. Code: Regex time ..... echo $$I|findstr /r "^[0-9]$" echo $$I|findstr /r "^[1-9][0-9]$" same code with regex ... Code: @cls @echo off set "key=HKLM\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}" for /L %%i in (0,1,20) do ( echo %%i|>nul findstr /r "^[0-9]$" && (echo REG QUERY "%key%\000%%i") && REG ADD "%key%\000%%i" /v PnPCapabilities /t REG_DWORD /d 24 /f echo %%i|>nul findstr /r "^[1-9][0-9]$" && (echo REG QUERY "%key%\00%%i") && REG ADD "%key%\00%%i" /v PnPCapabilities /t REG_DWORD /d 24 /f )
I tried this and it also creates new values in the registry that are empty and unnecessary: So far my favorite way is this because it is the shortest, i.e. it has only 2 straight lines one under the other: for /L %%i in (0,1,9) do REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\000%%i" /v PnPCapabilities /t REG_DWORD /d 24 /f for /L %%i in (10,1,20) do REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\00%%i" /v PnPCapabilities /t REG_DWORD /d 24 /f But it also creates unnecessary new empty registry entries where it is not needed. Can we modify these two lines for \L from REG ADD so that it also searches first if there is a DriverDesc and based on this, if it does not exist, it will not add any empty entry of type 0016 as in the screenshot above where I showed it. And if DriverDesc exists it will check its name and if it is Intel or Realtek or something similar it will add PnPCapabilities with value 24 to the registry. But if it doesn't find DriverDesc then PnPCapabilities won't show up as an empty registry entry in 0016 etc where no network card is physically assigned. Also, could it ignore names like "WAN Miniport" and "VirtualBox" and "Hyper-V" in DriverDesc so that if it finds them it will also ignore that and not add PnPCapabilities? Step-by-step description of how the script works: 1. It looks in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318} what numbers ( 0000, 0001 etc ) are currently in it. 2. Searches for "DriverDesc" in all found numbers ( 0000, 0001 etc ) a total of 21 pieces, i.e. from 0000 and 0001 to 0020: a) didn't find "DriverDesc" = does nothing / doesn't add PnPCapabilities b) found "DriverDesc" = goes to point 3. below: 3. Checks what is the name in "DriverDesc" and: a) if name in "DriverDesc" does not contain words/names etc "WAN Miniport" and "VirtualBox" and "Hyper-V" = add PnPCapabilities with value 24 b) if the name in "DriverDesc" contains anything from the words / names "WAN Miniport" and "VirtualBox" and "Hyper-V" = does nothing / does not add PnPCapabilities Can someone make something like this and show me what it would look like? That would be the best solution.
My previous post is long so I decided to make a new one but I am asking the moderators to merge my two posts if they feel it necessary. I tried to do something with CHAT GPT and here are the results: Code No. 1 - Adds PnPCapabilities to the registry correctly and does it only where there are current key values such as 0001 / 0015, so it does not add new empty values unnecessarily, e.g. 0016 which in my registry does not have any network card and device assigned: setlocal enabledelayedexpansion set start=0 set end=20 for /L %%i in (%start%,1,%end%) do ( set key=000%%i set key=!key:~-4! reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\!key!" /v DriverDesc 2>nul | find "DriverDesc" >nul if not errorlevel 1 ( reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\!key!" /v PnPCapabilities /t REG_DWORD /d 24 /f ) ) Code No. 2 - I added an argument here using CHAT GPT so that if it finds in DriverDesc names like "WAN Miniport" /c:"VirtualBox" /c:"Hyper-V" /c:"Microsoft Kernel" then it will not add PnPCapabilities to the registry, but if are different then it will add PnPCapabilities correctly: setlocal enabledelayedexpansion set start=0 set end=20 for /L %%i in (%start%,1,%end%) do ( set key=000%%i set key=!key:~-4! reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\!key!" /v DriverDesc 2>nul | findstr /i /c:"WAN Miniport" /c:"VirtualBox" /c:"Hyper-V" /c:"Microsoft Kernel" >nul && ( echo DriverDesc zawiera niedozwoloną nazwę w kluczu !key! ) || ( reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\!key!" /v DriverDesc 2>nul | findstr /i /c:"WAN Miniport" /c:"VirtualBox" /c:"Hyper-V" /c:"Microsoft Kernel" >nul || ( reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\!key!" /v PnPCapabilities /t REG_DWORD /d 24 /f echo Dodano wartość do klucza !key! ) ) ) And everything works fine, but code 1 doesn't create new unnecessary numbers like 0016 in the registry if it doesn't already exist for me. And code no. 2 makes that after each use I get empty additional digits in which there is only PnPCapabilities, even though there is nothing inside and it did not exist before and there is no DriverDesc. Can anyone of you help me edit this to fix it, i.e. code no.2 so that it does not create new empty entries if they did not exist in the registry before? If any of you know a solution, thank you in advance for your help. @abbodi1406 @Dark Dinosaur @Carlos Detweiller
@(\_/)^(\_/) Can you point me to exactly what the code should look like when updated after using pwsh tut?? Unfortunately, I don't know how to do it myself.
anyway ... almost anything you can do with CMD you can do this also with PWSH ... so REG query ... FIND ... FINDSTR ... I'm sure you will find a way to search for what you look for and it is much faster ...... believe me . !!!