So I am writing one of my first large batch scripts and part of the script needs to create several keys in the registry. The problem I am having is that a redundant subordinate key is being created in the path and I am not sure how to solve it. Also of note is that this only occurs on certain systems and is not always the case.
Here is the command I am using:
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Riedel\ARTIST SNMP Agent" /v "MasterSnmpAgentIpAddr" /t REG_SZ /d "127.0.0.1:705"
When I look in the registry to see the result, here is the path that it is placed in:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Wow6432Node\Riedel\ARTIST SNMP Agent
I've tried a few methods of creating registry keys, but they yield the same results. Any thoughts or help would be appreciated. Thanks!
Wow6432Node is for the 32bit programs in 64bit OS. So you should better use the reg add switch /reg:
try this for 32bit entries
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Riedel\ARTIST SNMP Agent" /v "MasterSnmpAgentIpAddr" /t REG_SZ /d "127.0.0.1:705" /reg:32
and for 64bit
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Riedel\ARTIST SNMP Agent" /v "MasterSnmpAgentIpAddr" /t REG_SZ /d "127.0.0.1:705" /reg:64
Related
How can I change this registry key in my batch file?
HKEY_LOCAL_MACHINE\SOFTWARE\CONFIGURATION
Name Type Data
Default REG_SZ ServerA
That is an example regkey, but the result I am looking for is the same. I would like to change the "ServerA" to "ServerB"
Would this be the correct syntax?
reg add "hkey_local_machine\software\configurations" /t REG_SZ /v Default /d ServerB
And is there also a way to run this with command priveleges?
I need to add a subkey in the registry of Windows 10 with a .bat script, but the results are not what is expected. Code does produce a result, but creates an incorrect entry. I need a subkey named EnableLinkedConnections that is of the type: REG_DWORD with a data value of 1
I have already written a .bat to add entries which are correct, but trying to add another in a different registry folder creates an incorrect entry.
#echo off
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\" /f /v "EnableLinkedConnections" /t REG_DWORD d/ 0x1
pause
This creates a folder outside of the System folder, but still in the Policies folder named:
System" /f /v EnableLinkedConnections /t REG_DWORD d/ 0x1
which is not correct. I expected a subkey entry of type REG_DWORD.
Seems that its having an issue with backslashes maybe, but the other .bat I wrote does not do this, so a bit stumped. Any pointers welcome.
I want to add this new registry entry via cmd/batch file to run CMD always as administrator. I know I can add it by navigating to the mentioned path in the command. But I want to add it in one of my batch files. And I think to add string value I need to modify my cmd. I am missing something here :-
reg.exe ADD \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers /t REG_SZ "C:\\WINDOWS\\system32\\cmd.exe"="RUNASADMIN" /f
Can anyone help me with this please?
The command line to use in a batch file executed by 64-bit cmd.exe on Windows x64 or 32-bit cmd.exe executed on Windows x86 running under elevated environment of a local administrator is:
%SystemRoot%\System32\reg.exe ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /f /t REG_SZ /v "C:\WINDOWS\system32\cmd.exe" /d "RUNASADMIN"
Open a command prompt window and run reg /? and next reg add /? for help on used command REG for adding a string value to Windows registry.
I have a batch file with two reg add commands in it. Both seem to work but one will show in the registry for about 5 seconds and then disappears. I have tried all the formatting styles and cannot get the one to stick. Here are the two reg adds I'm using:
reg add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v CrashPlanTray /t REG_SZ /d C:\Users\%USERNAME%\AppData\Local\Programs\CrashPlan\electron\CrashPlanDesktop.exe --menubar --desktop=false --user.install
and
reg add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v CrashPlanServiceUser /t REG_SZ /d C:\Users\%USERNAME%\AppData\Local\Programs\CrashPlan\CrashPlanService.vbs
It is the first one CrashPlanTray that will not stick.
I have tried it adding the \ before the data value and at the end of the data value. It will add it to the registry but then after a few seconds it disappers.
reg add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v CrashPlanTray /t REG_SZ /d "\"C:\Users\%USERNAME%\AppData\Local\Programs\CrashPlan\electron\CrashPlanDesktop.exe\" --menubar --desktop=false --user.install
I have been trouble shooting and working with this for days now. I can get it to work and stick from a command window but once I put it in the batch file it no longer sticks. I could use some expert help in figuring out why it won't stick in the registry?
On the first reg add, try this:
reg add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v CrashPlanTray /t REG_SZ /d "\"%localappdata%\Programs\CrashPlan\electron\CrashPlanDesktop.exe\" --menubar --desktop=false --user.install"
Take special note of the double quotes (beginning and end) enclosing the full string to registry, as well as the escaped ones enclosing the path ( I shortened the above path for demonstration purpose:
"\"%localappdata%\..\CrashPlanDesktop.exe\" --menubar --desktop=false --user.install"
Finally, also notice we can use %localappdata% instead of C:\users\%username%\..
First thing I'd do is because the locations use environment variables is to use REG_EXPAND_SZ, instead of REG_SZ.
I'd use backslashes to then escape any internal doublequotes and protect the locations, as they could contain things like spaces.
I'd set the common strings as values at the top to make it easier to modify and shorten the lines somewhat, and would also probably use carets, ^ to shorten the lines still further for readability.
Finally, if you're wanting to run a VBScript from the registry run key, you should really be running it from either WScript.exe or CScript.exe. My example below uses WSCript, but you can replace that with CScript and any required options as needed.
#Set "Key=HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
#Set "Loc=%%LocalAppData%%\Programs\CrashPlan"
#Reg Add "%Key%" /V "CrashPlanTray" /T REG_EXPAND_SZ /D^
"\"%Loc%\electron\CrashPlanDesktop.exe\" --menubar --desktop=false --user.install" /F>Nul
#Reg Add "%Key%" /V "CrashPlanServiceUser" /T REG_EXPAND_SZ /D^
"WScript \"%Loc%\CrashPlanService.vbs\"" /F>Nul
I don't know exactly what has changed but after completely uninstalling and reinstalling CrashPlan, all is working again. I can now run the batch files to disable and re-enable it they are now working correctly. Your efforts were not wasted as I am using snippets of the things you suggested in my revised batch files and it makes them much cleaner to read and work with. Thank you for your help and patience.
One of my troubleshooting steps is to clear the PendingFileRenameOperations registry value to avoid rebooting a server.
What I would like to do is clear this through a batch file, I don't want to delete it, just clear it.
It's the following registry value
HKEY_LOCAL_MACHINE/SOFTWARE/Session Manager/PendingFileRenameOperations
The command
%SystemRoot%\System32\reg.exe add "HKLM\System\CurrentControlSet\Control\Session Manager" /v PendingFileRenameOperations /t REG_MULTI_SZ /d "" /f
replaces current value of multi-string value PendingFileRenameOperations with an empty string.
The path you wrote in the question does not exist on my Windows 7 x64 machine.
For details on command reg open a command prompt window and run there first reg /? and second reg add /?
But why clearing this registry value used to delete or replace (usually update) files after reboot before Windows loads drivers and starts processes and applications should avoid rebooting a Windows server is beyond my understanding.
Some software just checks for the key existence and doesn't care if its blank,So For deleting Key,Use My Way :
reg delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager" /v PendingFileRenameOperations /f