ccook13MemberJun 06, 2007 at 1:43 pm #125938
I am having a problem using a vbs script to add registry entries.
1. I am using group policy to add registry entries to prevent the auto update of Sun Java Runtime Environment. I need to add registry entries at both startup and login.
2. Since I have pretty limited knowledge of scripting I started by modifying another login script which I know to work.
3. After a lot of hacking around I ended up with the following code (placed after my comments)
4. The code seems to do everything I ask EXCEPT that I cannot get the script to merge the REG file into the registry on the remote PC.
5. Since the REG file includes a long binary value I am limited as to my choices for editing the registry. It does not look like the RegWrite method works for long binary values. I suppose I could try to call a CMD or BAT file and have that file do the registry edit, but this is already a complicated install and I’d like to avoid another step.
6. The error message I get on the remote PC is “Registry Editor: Cannot import c:DisableJavaUpdateHKCU.reg: Error opening the file. There may be a disk or file system error.
Here’s the code (sorry its long – I’ve flagged the line where I think the problem occurs):
Dim oShell : set oShell = WScript.CreateObject(“WScript.Shell”)
Dim oFS : set oFS = WScript.CreateObject(“Scripting.FileSystemObject”)
Dim checkFileExists : checkFileExists = “c:java161checkfile.txt”
REM On error resume next
if (GetTheOS() = “W2K”) then
‘ IF the check file does not exist then run the following steps
If(NOT oFS.FileExists(checkFileExists)) Then
DoesKeyExist = “HKCUSoftwareJavaSoftJava UpdatePolicy”
If RegKeyExists(DoesKeyExist) then
oShell.RegDelete (“HKCUSoftwareJavaSoftJava UpdatePolicy”)
Dim java2K : java2K = “regedit c:DisableJavaUpdateHKCU.reg”
I THINK THE PROBLEM IS THE NEXT LINE
‘******************** END MAIN
‘ Will work with most versions of WSH (windows shell)
CONST FORREADING = 1
Dim sResults, fFile
Dim WshShell : Set WshShell = CreateObject(“WScript.Shell”)
Dim FSO : Set FSO = CreateObject(“Scripting.FileSystemObject”)
Dim sTemp : sTemp = WshShell.ExpandEnvironmentStrings(“%TEMP%”)
Dim sTempFile : sTempFile = “c:runresult.tmp”
WshShell.Run “%comspec% /c ver >” & sTempFile, 0, True
Set fFile = FSO.OpenTextFile(sTempFile, FORREADING)
sResults = fFile.ReadAll
Select Case True
Case InStr(sResults, “Windows NT”) > 1 : GetTheOS = “NT4”
Case InStr(sResults, “Windows 2000”) > 1 : GetTheOS = “W2K”
Case InStr(sResults, “Windows XP”) > 1 : GetTheOS = “WXP”
Case Else : GetTheOS = “Unknown”
‘function for writing the checkfile
Set checkFile = oFS.CreateTextFile(“c:java161checkfile.txt”, True)
checkFile.WriteLine(“This file is used by the script JavaInstall.vbs”)
checkFile.WriteLine(“If it is the first time the script runs it will write”)
checkFile.WriteLine(“this file to c:java161checkfile.txt.”)
checkFile.WriteLine(“If this file exists the next time the script will skip”)
checkFile.WriteLine(“the running of the Java install and associated registry edits.”)
‘ Returns True or False based on the existence of a registry key.
‘ This part is a compliment from Torgeir Bakken.
Function RegKeyExists(ByVal sRegKey)
RegKeyExists = True
sRegKey = Trim (sRegKey)
If Not Right(sRegKey, 1) = “” Then
sRegKey = sRegKey & “”
On Error Resume Next
sDescription = Replace(Err.Description, “HKEYNotAKey”, “”)
RegKeyExists = sDescription <> Replace(Err.Description, sRegKey, “”)
On Error Goto 0
‘*********** CLEAN UP *******************
Set oFS = Nothing
Set oShell = Nothing
‘********** END CODE ****************
Any suggestions???? Anything more you need to know to answer the questions?
Thanks for your help!
You must be logged in to reply to this topic.