No announcement yet.

Problem with space in path name

  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with space in path name

    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):

    Option Explicit

    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

    Dim DoesKeyExist
    DoesKeyExist = "HKCU\Software\JavaSoft\Java Update\Policy"
    If RegKeyExists(DoesKeyExist) then
    oShell.RegDelete ("HKCU\Software\JavaSoft\Java Update\Policy\")
    'do nothing
    End if

    oFS.CopyFile "\\ds2\Network Services\Java\Scripts\DisableJavaUpdateHKCU.reg", "c:\DisableJavaUpdateHKCU.reg"
    Dim java2K : java2K = "regedit c:\DisableJavaUpdateHKCU.reg"
    oShell.Run (java2K)
    oFS.DeleteFile "c:\DisableJavaUpdateHKCU.reg"

    End if

    End if

    '******************** END MAIN

    Function GetTheOS()
    ' Will work with most versions of WSH (windows shell)
    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"
    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.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.")
    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 sDescription

    RegKeyExists = True
    sRegKey = Trim (sRegKey)
    If Not Right(sRegKey, 1) = "\" Then
    sRegKey = sRegKey & "\"
    End If

    On Error Resume Next
    oShell.RegRead "HKEYNotAKey\"
    sDescription = Replace(Err.Description, "HKEYNotAKey\", "")

    oShell.RegRead sRegKey
    RegKeyExists = sDescription <> Replace(Err.Description, sRegKey, "")
    On Error Goto 0
    End Function

    '*********** CLEAN UP *******************

    Set oFS = Nothing
    Set oShell = Nothing

    WScript.Quit (0)

    '********** END CODE ****************

    Any suggestions???? Anything more you need to know to answer the questions?

    Thanks for your help!

  • #2
    Corrected Title: Problem merging REG file using VBS

    My apologies for the change in title. It took a long time to compose the post and the problem changed as I worked!


    • #3
      Re: Problem with space in path name

      It is a good practice to use always the program extension with the
      and it is recommended to type the complete path of the program.

      Here is an example
      Dim oShell : set oShell = WScript.CreateObject("WScript.Shell")
      Dim java2K : java2K = oShell.ExpandEnvironmentStrings _
      ("%SystemRoot%\regedit.exe -s %systemdrive%\DisableJavaUpdateHKCU.reg")
      oShell.Run (java2K), 0, true
      set oShell =  Nothing
      Where "True" is the WaitOnReturn parameter to run programs synchronously (one at a time)
      Adding the WaitOnReturn parameter here avoid the possibility that the reg-file is already deleted by the next line, before it was fully loaded by regedit.exe.

      The commandstring (java2K) does not have to be between parentheses here. Only if you planned to save the error code returned, then everything after .Run must be between round brackets not just the commandstring, and the bracket must be connected without a space to . Run
      e.g. Returncode = oShell.Run(java2K, 0, true)

      When you have problems with spaces in the path (according the Title of this thread) then add 2 quotes (extra) around the path or, put a quote-sign with an ASCI value (ASCII values are always good to try as replacement for symbols that could cause conflicts with the script language). The ASCII value for " is chr(34).
      Dim java2K : java2K = """regedit.exe"" -s " & _
                   """c:\path to folder\DisableJavaUpdateHKCU.reg"""
      Dim java2K : java2K = chr(34)& "regedit.exe" &chr(34)
                   java2k = java2k & " -s " & _
                   chr(34)& "c:\path to folder\DisableJavaUpdateHKCU.reg" &chr(34)
      Last edited by Rems; 7th June 2007, 01:47. Reason: changed what I said earlier about the use of parentheses

      This posting is provided "AS IS" with no warranties, and confers no rights.


      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts


      • #4
        Re: Problem with space in path name

        Thanks for your suggestions. I was able to solve the problem and move forward!