How to create a registry key with VBS

vbscript

Okay, I will try asking this question again.
I used this code:

Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System\test", 1, "REG_DWORD"

I get the error 'Invalid root in registry key' Code: 80070005 (Access Denied)
The code works with other registry roots. I am logged on as an administrator. It works when I run it from an elevated command prompt. But I am making this VBS as a prank to a friend to make him not know what I'm doing. Any ideas?

Best Answer

The best way to distribute registry setting is by exporting the part of a registry where this setting is active to a .reg file with the registry editor. In the save part of the export dialog you choose Win9x/NT4 as format. You can check the .reg file with an editor. The user only has to double click the .reg file and confirm the prompt and possibly reboot his pc. Even normal users should be able to do this. If the registrybranch you try to change is protected by security he wil have to do this with admin right and possibly (depenidng on OS version) start regedit with the the regedt32.exe executable and first adapt the security of that branch so that it can be changed.

Doing this with a script means having to pass additional layers of security to make sure this isn't a malicious script.

Related Topic