[jedi/old/i-menu.htm]
3TGKB-0053

Last Edited :

03-08-05

Revision :

 1.0


How do I write a registry value using VBS?


I had an interesting problem earlier today – I wanted a security camera program to start automatically whenever I started up a particular Windows server. No problem I thought. Just stick it in the HKLM\Software\Microsoft\Windows\CurrentVersion\Run key using REGEDIT. Well, yeah, that will work, but that’s not reusable. So I thought I’d write some VBS to do it, just in case I ever need to re-install the OS (God forbid!!).

Here is the code, which you are welcome to use as a template for editing any registry value with VBS:

Option Explicit
Dim objShell
Dim strProg
Dim strRegKey

' Set the string values
strProg = "D:\Program Files\Security\Security For Local Transmitter\Security.exe"
strRegKey = "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\SecurityCameraApp"

' Create the Shell object
Set objShell = CreateObject("WScript.Shell")

' Write the registry value.
objShell.RegWrite strRegKey, StrProg, "REG_SZ"

' Give the user some feedback.
Wscript.Echo "All done, you handsome fox!"

' The line below was purely for testing
' objShell.RegDelete strRegKey
WScript.Quit

' End of script.

Hope it helps!!

Regards

Paul Eddington


KB Keywords:  VBS automatic start-up script registry