Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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):
Option ExplicitDim 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)) ThenDim DoesKeyExist
DoesKeyExist = "HKCU\Software\JavaSoft\Java Update\Policy"
If RegKeyExists(DoesKeyExist) then
oShell.RegDelete ("HKCU\Software\JavaSoft\Java Update\Policy\")
Else
'do nothing
End ifoFS.CopyFile "\\ds2\Network Services\Java\Scripts\DisableJavaUpdateHKCU.reg", "c:\DisableJavaUpdateHKCU.reg"
Dim java2K : java2K = "regedit c:\DisableJavaUpdateHKCU.reg"
I THINK THE PROBLEM IS THE NEXT LINE
oShell.Run (java2K)
oFS.DeleteFile "c:\DisableJavaUpdateHKCU.reg"writeCheckFile()
End ifEnd if
'******************** END MAIN
Function GetTheOS()
' 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, TrueSet fFile = FSO.OpenTextFile(sTempFile, FORREADING)
sResults = fFile.ReadAll
fFile.Close
Fso.DeleteFile(sTempFile)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"
End Select
End Function'function for writing the checkfile
Function writeCheckFile()
Dim checkFile
Set checkFile = oFS.CreateTextFile("c:\java161checkfile.txt", True)
checkFile.WriteLine("This file is used by the script JavaInstall.vbs")
checkFile.WriteBlankLines(1)
checkFile.WriteLine("If it is the first time the script runs it will write")
checkFile.WriteLine("this file to c:\java161checkfile.txt.")
checkFile.WriteBlankLines(1)
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.")
End Function' Returns True or False based on the existence of a registry key.
' This part is a compliment from Torgeir Bakken.Function RegKeyExists(ByVal sRegKey)
Dim sDescriptionRegKeyExists = True
sRegKey = Trim (sRegKey)
If Not Right(sRegKey, 1) = "\" Then
sRegKey = sRegKey & "\"
End IfOn Error Resume Next
oShell.RegRead "HKEYNotAKey\"
sDescription = Replace(Err.Description, "HKEYNotAKey\", "")Err.Clear
oShell.RegRead sRegKey
RegKeyExists = sDescription <> Replace(Err.Description, sRegKey, "")
On Error Goto 0
End Function'*********** CLEAN UP *******************
Set oFS = Nothing
Set oShell = NothingWScript.Quit (0)
'********** END CODE ****************
Any suggestions???? Anything more you need to know to answer the questions?Thanks for your help!
Cliff

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.
Well there's your problem. Either give every user write/create/delete privileges to every remote's c:\, or redirect the command to a file share. As in:
oShell.Run "regedit /s "\\ds2\Network Services\Java\Scripts\DisableJavaUpdateHKCU.reg"I didn't even look at the code, does anyone think that that'll be a problem?...

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |