Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been trying to run a VBScript file every time my system starts up, and have tried modifying the registry using VBScript to add it to the list of programs to run, but I'm facing a problem with permissions even though I'm the computers administrator. I'm trying to add VB_Start.vbs to the list of startup tasks by modifying the registry with the following VBScript code:

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\Visual Basic" , "VB_Start.vbs" , "REG_SZ"
Set WshShell = Nothing

When I execute this code I'm getting the following error:

Error: Invalid root in registry key HKEY_LOCAL_MACHINE\SOFTWARE\......
Error Code: 80070005
Source: WshShell.RegWrite
share|improve this question

80070005 indicates an access denied error. Just because you're an admin doesn't mean your VBS is being executed automatically with admin rights. Add the following code to the top of the script:

If WScript.Arguments.Named.Exists("elevated") = False Then
  CreateObject("Shell.Application").ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """ /elevated", "", "runas", 1
End If

The code will detect if the script is running elevated, else relaunch itself with admin rights (you'll still see the prompt of course).

share|improve this answer
Const HKEY_CURRENT_USER = &H80000001

strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
strComputer & "\root\default:StdRegProv")

strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
strValueName = "Hidden"
strStringValues = "0"

oReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,strStringValues

This is the format of code I use for adding registry keys. All you'd have to change is what's in strValueName, the strStringValues, and the initial CONST to point to the proper section in the registry. Those codes are:

Const HKEY_CLASSES_ROOT     = &H80000000
Const HKEY_CURRENT_USER     = &H80000001
Const HKEY_LOCAL_MACHINE    = &H80000002
Const HKEY_USERS        = &H80000003
Const HKEY_CURRENT_CONFIG   = &H80000005
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .