• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 859
  • Last Modified:

VBS script help needed to modify a registry key


Could someone help me out to write a quick vbs script that will change the following keys on the registry.

1.      Using a Registry Editor such as Regedt32.exe, open this key:

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Styles

Note If the Styles key is not present, create a new key that is called Styles.

2.      Create a new DWORD value called "MaxScriptStatements" under this key and set the value to the desired number of script statements. If you are unsure of what value you need to set this to, you can set it to a DWORD value of 0xFFFFFFFF to completely avoid the dialog.

  • 3
  • 2
1 Solution
Although this does not have the "check if registry key exists", it does show an example of creating a reg entry without calling another executable. If the registry entry already exists, it is simply re-written with the same info.

Option Explicit
Dim objShell, strRoot, strModify, strDelete
strRoot = "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Styles"
' Create the Shell object
Set objShell = CreateObject("WScript.Shell")
strModify = objShell.RegWrite(strRoot,"0xFFFFFFFF", "DWORD")
strModify = null
This should do it:
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ 
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Software\Microsoft\Internet Explorer\Styles"
strValueName = "MaxScriptStatements"
dwValue = 0xFFFFFFFF
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue

Open in new window

llaravaAuthor Commented:
Our users are do NOT have admin rights to their computers. I am facing the following problem since the script or the MSI provided by MS http://support.microsoft.com/default.aspx?scid=kb;en-us;175500

Since the changes are being applied to the HKEY_CURRENT_USER\Software\ neither the script or the MSI are working since the admin rights are needed.

The problem is that if a deploy the script or the MSI with SCCM (deployment tools) I can choose to run the script/MSI with admin rights however since the change is applied to the HKEY_CURRENT_USER\ hive I guess the change it is NOT applied correctly.

Is there anyway that I could make this change?
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

lookup the syntax of the runas command to see how to run it as the local administrator on the workstations

this will fix the problem by running the script under the context of the local admin, allowing full access to the system files and registry
llaravaAuthor Commented:
The run as will execute the script as whatever user your are "running as..." the script will be making changes to the HKEY_CURRENT_USER\ hive so the script has to be executed as the "user" for which you want the changes to be applied.

If your execute the script or the MSI with run as then chages are not applied to the HKEY_CURRENT_USER\

Do you know what I mean...
OK.  How about having two scripts, one that you run as an administrator to change write permission on the necessary key, then the other to run as the user to change the key, then change the permissions back.

This link, http://support.microsoft.com/?kbid=237607, shows how to use regini.exe to change the permissions.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now