VBScript Basics, Part 58 | Write To The Registry (Regedit)

Visual Basic Script (.vbs) Basic Tutorial:
Learn how to write to the registry and create new keys, or edit existing values. As a bonus also learn how to change your desktop wallpaper.

Example Code:

Function RunAsAdmin()
Dim objAPP
If WScript.Arguments.length = 0 Then
Set objAPP = CreateObject(“Shell.Application”)
objAPP.ShellExecute “wscript.exe”, “””” & _
WScript.ScriptFullName & “””” & ” RunAsAdministrator”,,”runas”, 1
End If
End Function


Set objSHL = CreateObject(“WScript.Shell”)
chg_wall = “C:UsersJeremyDesktop.jpg”

objSHL.RegWrite “HKCUControl PanelDesktopWallpaper”, chg_wall, “REG_SZ”

objshl.Run “RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters”