0

1. How to delete a registry value using a registry file?

I have learned that I can add a registry value to Windows registry with this command in a batch file.

regedit "path\Reg File Name.reg"

The registry file contains:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
"Title"="Path"

This is working.

But nothing happens when I want to delete the registry value Title with a registry file containing following:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
"Title"="Path" =-

=- does nothing. How to fix this? What I'm doing wrong?


2. How to run the batch file hidden in background without a visible console window after user log on?

I have done this:

I created a batch file with:

wscript.exe "path\Script.vbs" "path\My File.bat"

And the VB script file contains:

CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False

This is working. I'm clicking my start.bat and it starts My File.bat invisible in background.

But it is not working on adding the file Start.bat to Autostart folder in Windows start menu. When the system boots and I log in, batch file is really run and also the VB script, but My File.bat is not executed.

I mean everything is working beside my batch file which should run in background.

Mofi
  • 46,139
  • 17
  • 80
  • 143
MrJW
  • 165
  • 2
  • 9

1 Answers1

2

The registry file must be as follows for deletion of a registry value.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
"Title"=-

This registry file just deletes the value with name Title under registry key HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run.

Regedit has an option to run silently: /s

So the following command line imports the content of the registry file into Windows registry without showing a message for the user, except the used user account does not have administrator privileges required on usage of regedit.

%SystemRoot%\regedit.exe /s "path\Reg File Name.reg"

If the registry file contains just data to remove a key or a value, nothing is imported and just the keys/values are removed silently.

A better solution for deleting just a single value than using regedit with a registry file is the usage of command reg.

%SystemRoot%\system32\reg.exe delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "Title" /f

Run the command reg /? in a command prompt window to get help on command reg and reg delete /? for help on how to delete a registry value or key.

The advantage of using command reg in comparison to regedit is that the command does not require administrator privileges on modifying something under HKCU while the usage of regedit requires administrator privileges even for modifications in current user registry.

Mofi
  • 46,139
  • 17
  • 80
  • 143