I am needing to create a task to delete a particular HKEY Current User key, however the character { is not being allowed. unfortunately, its the key that has to be removed. Here is a snippet of the part that fails…
createfile until endfile
Windows Registry Editor Version 5.00
[-HKEY_CURRENT_USER\Software\Classes\CLSID{AB8902B4-09CA-4bb6-B78D-A8F59079A8D5}]
endfile
move __createfile c:\Temp\Powelik.reg
waithidden C:\Temp\RunAsCurrentUser.exe -s regedt32 /s c:\Temp\Powelik.reg
Having the { in the line is causing it to fail and not sure how to be able to include it.
Note of course given that you are attempting to remove a registry value from HKCU, there can be challenges. Leveraging RunAsCurrentUser can help, but an alternate approach is to dynamically build a .reg file that will allow you to remove the specified key from any/all users defined under HKU. This has the advantage of being able to address multiple user configurations at once (if they exist), and does not require a user to be logged in.
I have a similar task for this when I was doing our Splunk deployment that uses the action script without the need to use the appendfile or createfile. I had the uninstall command run from the key within the registry that already has the curly brackets in the name. The way I did it was to do this:
dos "MsiExec.exe /X{name of key whose (name of it contains "7988114D-E718-4AD1-BE40-825440565928") of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" of x64 registry} /qn"
Since there is only going to be one key with the matching name and it will include the curly brackets in the name, it did the trick.
Depending on the version of the client you are using (as I fixed this in a later release - I believe 9.0+) you can get a registry key of a user by:
current user key of registry
current user keys ( logged on users ) of registry
Only the agent can do this as it needs privilege but this will give you the hive of the user in question in the HKEY_USERS hive that you can use at any time and you don’t need to do things in the user’s context