Wednesday, November 23, 2016

Java path

@echo off
cls
setlocal ENABLEEXTENSIONS
set KEY_NAME="HKLM\SOFTWARE\JavaSoft\Java Runtime Environment"
set VALUE_NAME=CurrentVersion
::
:: get the current version
::
FOR /F "usebackq skip=2 tokens=3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
    set ValueValue=%%A
)
if defined ValueValue (
    @echo the current Java runtime is  %ValueValue%
) else (
    @echo %KEY_NAME%\%VALUE_NAME% not found.
    goto end
)
set JAVA_CURRENT="HKLM\SOFTWARE\JavaSoft\Java Runtime Environment\%ValueValue%"
set JAVA_HOME=JavaHome

::
:: get the javahome
::
FOR /F "usebackq skip=2 tokens=3*" %%A IN (`REG QUERY %JAVA_CURRENT% /v %JAVA_HOME% 2^>nul`) DO (
    set JAVA_PATH=%%A %%B
)
echo the path of the current Java JVM according to the registry is
echo %JAVA_PATH%
echo.
echo now if we try it :
"%JAVA_PATH%\bin\java.exe" -version
set JAVA_HOME="%JAVA_PATH%\bin\java.exe"

:end

Shortpath Folder

Set fso = CreateObject("Scripting.FileSystemObject")
strProgramFiles = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%ProgramFiles%")

Set f = fso.GetFolder(strProgramFiles)
strShortProgramFiles = f.ShortPath

session.property("ZI_SHORT_PF") = strShortProgramFiles

Process check Notification (Only twice)

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set WshShell = CreateObject("WScript.Shell")

strAppName = "CatiaV5R19"
intSecondsToWait = 10

strMessageTextENG =(vbCr & "You have been scheduled to Upgrade CatiaV5R19."&vbCrlf& "Please exit out of the following program before Upgrading:"_
&vbCrlf&"• CATIA V5")

strMessageText = strMessageTextENG & VbCR & strMessageTextDEU & VbCR & strMessageTextFRA & VbCR & strMessageTextITA & VbCR & strMessageTextESP

strProcessName = "cNext.exe"

CheckForRunningApp strMessageText, intSecondsToWait, strAppName, strProcessName

Function CheckForRunningApp (strMessageText, intSecondsToWait, strAppName, strProcessName)
    Do
        found = false
        Set colProcessList = objWMIService.ExecQuery ("SELECT * FROM Win32_Process WHERE Name = '" & strProcessName & "'")
        For Each objProcess in colProcessList
            WshShell.Popup strMessageText, intSecondsToWait, strAppName, vbInformation + vbSystemmodal
            found = true
        Next
    Loop Until found = false
End Function



Dim objWMIService, objProcess, colProcess, strComputer, processName, instances,found,strMessageText,strMessageTextENG,WshShell,strAppName,intSecondsToWait
Set WshShell = CreateObject("WScript.Shell")

instances = 0
processName = "MsHta.exe"
strAppName = "CatiaV5R19"
intSecondsToWait = 10

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process")

For Each objProcess in colProcess
If objProcess.Name = processName Then instances = instances + 1
Next

Do

found=false
Set colProcess = objWMIService.ExecQuery ("SELECT * FROM Win32_Process WHERE Name = '" & processName & "'")
strMessageTextENG =(vbCr & "You have been scheduled to Upgrade CatiaV5R19."&vbCrlf& "Please exit out of the following program before upgrading:"_
&vbCrlf&"• Catiav5 / 3d Com Launcher")

strMessageText = strMessageTextENG
For Each objProcess in colProcess

              
WshShell.Popup strMessageText, intSecondsToWait, strAppName, vbInformation + vbSystemmodal
if colProcess.Count = instances then
found=true
Else
WScript.Quit

End If
 Next
Loop until Found=false

User reg Del ( All available users Machine)

On Error Resume Next

  
Dim WshShell, RegRoot, objFSO
Set WshShell = CreateObject("WScript.shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const HKEY_CURRENT_USER     = &H80000001
Const HKEY_LOCAL_MACHINE    = &H80000002
Const HKEY_USERS            = &H80000003
Const HKEY_CURRENT_CONFIG   = &H80000005
'
Const DAT_NTUSER             = &H70000000
Const DAT_USRCLASS             = &H70000001
 
    
'==============================================
' SCRIPT BEGINS HERE
'==============================================

RegRoot = "HKLM\TEMPHIVE" 

'== Loads each user's "HKCU" registry hive
Call Load_Registry_For_Each_User(DAT_NTUSER)     

'== Loads each user's "HKCR" registry hive
Call Load_Registry_For_Each_User(DAT_USRCLASS) 

WScript.Quit(0)
'                                                                   |
'                                                                   |
'====================================================================
 
Sub KeysToModify(sRegistryRootToUse, DAT_FILE)
    '==============================================
    ' Change variables here, or add additional keys
    '==============================================
    '
    On Error Resume Next
   

    If DAT_FILE = DAT_NTUSER Then 'This is for updating HKCU keys
        Dim strRegPathParent01
        Dim strRegPathParent02
        Dim strRegPathParent03
       

strRegPathParent01 = "Software\Microsoft\Active Setup\Installed Components\ETS-ENG-OneDrive-17.3.6390.0509-GBL-R1\"
strRegPathParent02 = "Software\Wow6432Node\Microsoft\Active Setup\Installed Components\ETS-ENG-OneDrive-17.3.6390.0509-GBL-R1\"
strRegPathParent03 = "Software\Microsoft\Active Setup\Installed Components\{8A69D345-D564-463c-AFF1-A69D9E530F96}\"
   

        WshShell.regdelete sRegistryRootToUse & "\" & strRegPathParent01  
        WshShell.regdelete sRegistryRootToUse & "\" & strRegPathParent02
        WshShell.regdelete sRegistryRootToUse & "\" & strRegPathParent03 

    End If
End Sub



Function GetDefaultUserPath
    On Error Resume Next
   
    Dim objRegistry
    Dim strKeyPath
    Dim strDefaultUser
    Dim strDefaultPath
    Dim strResult
 
    Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
 
    objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,"DefaultUserProfile",strDefaultUser
    objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,"ProfilesDirectory",strDefaultPath
         
    If Len(strDefaultUser) < 1 or IsEmpty(strDefaultUser) or IsNull(strDefaultUser) Then
        'must be on Vista or newer
        objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,"Default",strDefaultPath
        strResult =  strDefaultPath
    Else
        'must be on XP
        strResult =  strDefaultPath & "\" & strDefaultUser
    End If
     
    GetDefaultUserPath = strResult
End Function
 
Function RetrieveUsernameFromPath(sTheProfilePath)
    On Error Resume Next
   
    Dim lstPath
    Dim sTmp
    Dim sUsername
    
    lstPath = Split(sTheProfilePath,"\")
    For each sTmp in lstPath
        sUsername = sTmp
        'last split is our username
    Next
    
    RetrieveUsernameFromPath = sUsername
End Function
 
Sub LoadProfileHive(sProfileDatFilePath, sCurrentUser, DAT_FILE)
    On Error Resume Next
   
    Dim intResultLoad, intResultUnload, sUserSID

    'Load user's HKCU into temp area under HKLM
    intResultLoad = WshShell.Run("reg.exe load " & RegRoot & " " & chr(34) & sProfileDatFilePath & chr(34), 0, True)
    If intResultLoad <> 0 Then
        ' This profile appears to already be loaded...lets update it under the HKEY_USERS hive
        Dim objRegistry2, objSubKey2
        Dim strKeyPath2, strValueName2, strValue2
        Dim strSubPath2, arrSubKeys2
 
        Set objRegistry2 = GetObject("winmgmts:\\.\root\default:StdRegProv")
        strKeyPath2 = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
        objRegistry2.EnumKey HKEY_LOCAL_MACHINE, strKeyPath2, arrSubkeys2
        sUserSID = ""
 
        For Each objSubkey2 In arrSubkeys2
            strValueName2 = "ProfileImagePath"
            strSubPath2 = strKeyPath2 & "\" & objSubkey2
            objRegistry2.GetExpandedStringValue HKEY_LOCAL_MACHINE,strSubPath2,strValueName2,strValue2
            If Right(UCase(strValue2),Len(sCurrentUser)+1) = "\" & UCase(sCurrentUser) Then
                'this is the one we want
                sUserSID = objSubkey2
            End If
        Next
 
        If Len(sUserSID) > 1 Then
            'WScript.Echo "  Updating another logged-on user: " & sCurrentUser & vbCrLf

            If DAT_FILE = DAT_NTUSER Then
                Call KeysToModify("HKEY_USERS\" & sUserSID, DAT_FILE)
            ElseIf DAT_FILE = DAT_USRCLASS Then
                Call KeysToModify("HKEY_USERS\" & sUserSID & "_Classes", DAT_FILE)
            End If       
        Else
            'WScript.Echo("  *** An error occurred while loading HKCU for this user: " & sCurrentUser)
        End If
    Else
        'WScript.Echo("  HKCU loaded for this user: " & sCurrentUser)
    End If
 
    ''
    If sUserSID = "" then 'check to see if we just updated this user b/c they are already logged on
        Call KeysToModify(RegRoot, DAT_FILE) ' update registry settings for this selected user
    End If
    ''
 
    If sUserSID = "" then 'check to see if we just updated this user b/c they are already logged on
        intResultUnload = WshShell.Run("reg.exe unload " & RegRoot,0, True) 'Unload HKCU from HKLM
        If intResultUnload <> 0 Then
            'WScript.Echo("  *** An error occurred while unloading HKCU for this user: " & sCurrentUser & vbCrLf)
        Else
            'WScript.Echo("  HKCU UN-loaded for this user: " & sCurrentUser & vbCrLf)
        End If
    End If
End Sub
 
Function GetUserRunningScript()
    On Error Resume Next
    Dim sUserRunningScript, sComputerName
    sUserRunningScript = WshShell.ExpandEnvironmentStrings("%USERNAME%") 'Holds name of current logged on user running this script
    sComputerName = UCase(WshShell.ExpandEnvironmentStrings("%COMPUTERNAME%"))
    
    If sUserRunningScript = "%USERNAME%" or sUserRunningScript = sComputerName & "$"  Then
        ' This script might be run by the SYSTEM account or a service account
        Dim sTheProfilePath
        sTheProfilePath = WshShell.ExpandEnvironmentStrings("%USERPROFILE%") 'Holds name of current logged on user running this script
   
        sUserRunningScript = RetrieveUsernameFromPath(sTheProfilePath)
    End If

    GetUserRunningScript = sUserRunningScript
End Function

Function RemoveTrailingPathDelimiter(sPath)
    On Error Resume Next

    Dim sUpdatedPath
    sUpdatedPath = sPath

    If Right(sUpdatedPath,1) = "\" Then
        sUpdatedPath = Left(sUpdatedPath,Len(sUpdatedPath)-1)
    End If

    RemoveTrailingPathDelimiter = sUpdatedPath
End Function

Function GetPathToDatFileToUpdate(sProfilePath, DAT_FILE)
    On Error Resume Next

    Dim sDatFile, sPathToDat, sTrimmedProfilePath
    Dim bFoundDatFile
    sPathToDat = "" 'default

    sTrimmedProfilePath = RemoveTrailingPathDelimiter(sProfilePath)

    If DAT_FILE = DAT_NTUSER Then
        sDatFile = "NTUSER.DAT"

        If objFSO.FileExists(sTrimmedProfilePath & "\" & sDatFile) or objFSO.FileExists(chr(34) & sTrimmedProfilePath & "\" & sDatFile & chr(34)) Then
            sPathToDat = sTrimmedProfilePath & "\" & sDatFile       
        End If
    ElseIf DAT_FILE = DAT_USRCLASS Then
        sDatFile = "USRCLASS.DAT"

        If objFSO.FileExists(sTrimmedProfilePath & "\AppData\Local\Microsoft\Windows\" & sDatFile) OR _
            objFSO.FileExists(chr(34) & sTrimmedProfilePath & "\AppData\Local\Microsoft\Windows\" & sDatFile & chr(34)) Then
            sPathToDat = sTrimmedProfilePath & "\AppData\Local\Microsoft\Windows\" & sDatFile
        ElseIf objFSO.FileExists(sTrimmedProfilePath & "\Local Settings\Application Data\Microsoft\Windows\" & sDatFile) OR _
            objFSO.FileExists(chr(34) & sTrimmedProfilePath & "\Local Settings\Application Data\Microsoft\Windows\" & sDatFile & chr(34)) Then
            sPathToDat = sTrimmedProfilePath & "\Local Settings\Application Data\Microsoft\Windows\" & sDatFile
        End If
    End If

    GetPathToDatFileToUpdate = sPathToDat
End Function

Sub Load_Registry_For_Each_User(DAT_FILE)
    On Error Resume Next
        
    Dim sUserRunningScript
    Dim objRegistry, objSubkey
    Dim strKeyPath, strValueName, strValue, strSubPath, arrSubKeys
    Dim sCurrentUser, sProfilePath, sNewUserProfile
    Dim sPathToDatFile

    sUserRunningScript = GetUserRunningScript       
    'WScript.Echo "Updating the logged-on user: " & sUserRunningScript & vbCrLf
    ''

    If DAT_FILE = DAT_NTUSER Then
        Call KeysToModify("HKCU", DAT_FILE) 'Update registry settings for the user running the script
    ElseIf DAT_FILE = DAT_USRCLASS Then
        Call KeysToModify("HKCR", DAT_FILE) 'Update registry settings for the user running the script
    End If
    ''     
    sNewUserProfile = GetDefaultUserPath

    sPathToDatFile = GetPathToDatFileToUpdate(sNewUserProfile, DAT_FILE)

    If Len(sPathToDatFile) > 0 Then
        'WScript.Echo "Updating the DEFAULT user profile which affects newly created profiles." & vbCrLf
        Call LoadProfileHive(sPathToDatFile, "Default User Profile", DAT_FILE)
   
    End If
        
    Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
    objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
    
    For Each objSubkey In arrSubkeys
        strValueName = "ProfileImagePath"
        strSubPath = strKeyPath & "\" & objSubkey
        objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,strSubPath,strValueName,strValue
        sProfilePath = strValue
        sCurrentUser = RetrieveUsernameFromPath(strValue)
    
        If ((UCase(sCurrentUser) <> "ALL USERS") and _
            (UCase(sCurrentUser) <> UCase(sUserRunningScript)) and _
            (UCase(sCurrentUser) <> "LOCALSERVICE") and _
            (UCase(sCurrentUser) <> "SYSTEMPROFILE") and _
            (UCase(sCurrentUser) <> "NETWORKSERVICE")) then
            
            sPathToDatFile = GetPathToDatFileToUpdate(sProfilePath, DAT_FILE)

            If Len(sPathToDatFile) > 0 Then
                'WScript.Echo "Preparing to update the user: " & sCurrentUser
                Call LoadProfileHive(sPathToDatFile, sCurrentUser, DAT_FILE)
            End If
        End If
    Next
End Sub

Logged on user

On Error Resume Next

Const ForReading = 1
Dim objWshShell : Set objWshShell = CreateObject("WScript.Shell")
Dim WshShell : Set WshShell = CreateObject("WScript.Shell")
Dim str1, Windir
Set objFSO = CreateObject("Scripting.FileSystemObject")
Windir = WshShell.ExpandEnvironmentStrings("%windir%")
Set objFile = objFSO.OpenTextFile(windir & "\Temp\ansi_Lguser.txt", ForReading)

Do Until objFile.AtEndOfStream
    strNextLine = objFile.ReadLine
    If Len(strNextLine) > 0 Then
        strLine=strNextLine
    End If
Loop

objFile.Close
'Wscript.Echo strLine
str1 = "HKEY_LOCAL_MACHINE\SOFTWARE\CSC\Current_UName\Username"
WshShell.Regwrite str1,strLine,"REG_SZ"   

Empty Folder Del

on error resume next

Dim wshShell, objFSO, ProgramFiles

Set wshShell =CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
ProgramFiles=wshShell.ExpandEnvironmentStrings("%ProgramFiles%")

If FolderEmpty(ProgramFiles & "\MATLAB") Then
objFSO.DeleteFolder ProgramFiles & "\MATLAB"
End If



Function FolderEmpty(strFolder)
Dim objFSO, objFolder
Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FolderExists(strFolder) Then
    Set objFolder = objFSO.GetFolder(strFolder)
 
    If objFolder.Files.Count = 0 And objFolder.SubFolders.Count = 0 Then
        FolderEmpty=True
    Else
        FolderEmpty=False

    End If
End If

Set objFSO = Nothing
End Function


Set wshShell = Nothing
Set objFSO = Nothing
WScript.Quit

All Keys information

'''
''' No Warrenty Provided for this code. Use at your own risk.
'''

Const HKEY_CLASSES_ROOT   = &H80000000
Const HKEY_CURRENT_USER   = &H80000001
Const HKEY_LOCAL_MACHINE  = &H80000002
Const HKEY_USERS          = &H80000003
Const REG_SZ        = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY    = 3
Const REG_DWORD     = 4
Const REG_MULTI_SZ  = 7


'' Looking at the local machines registry
Set reg = GetObject("winmgmts://./root/default:StdRegProv")

 '' Check the current user hive for values
FindAndDeleteKey HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections"

'' get a list of user hives
  reg.EnumKey HKEY_USERS, "", subkeys
  If Not IsNull(subkeys) Then
    '' Iterate through each hive and call the sub to find and delete the values
    For Each sk In subkeys
        FindAndDeleteKey HKEY_USERS, sk & "\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections"
    Next
  End If


''' sub '''
''Find and display the value of the related keys.
Sub FindAndDeleteKey(root, key)
  reg.EnumValues root, key, names, types
  If Not IsNull(names) Then
    For Each name In names
        '' For each value in this key searh for the two valeus we are looking for.
      If (name = "DefaultConnectionSettings") Or (name = "SavedLegacySettings") Then
        Dim strValue
        reg.GetBinaryValue root, key, name, strValue
        PrintData key, name, regReadBinary(strValue)
        '''''''''
        '' We have all the data we need, we could put a delete command here
        '' to remove the entry if the user has the permissions to do this.
        '''''''''
      End If
    Next
  End If
End Sub

Sub PrintData(heading,body,data)
    wScript.Echo VbCrLf + "#################"
    wScript.Echo "###  Key  ###"   
    wScript.Echo heading
    wScript.Echo "### Value ###"
    wScript.Echo body
    wScript.Echo "### Data  ###"
    wScript.Echo data
    wScript.Echo "#################" + VbCrLf
End Sub

''Convert REG_BINARY to ASCII String.
Function regReadBinary(aBin)
      Dim aInt(), i, iBinSize, sString, iChar, sChar
      If Err.Number = 0 Then
             iBinSize = UBound(aBin)
             ReDim aInt(iBinSize)
             For i = LBound(aBin) To UBound(aBin)
                   aInt(i) = CInt(aBin(i))
                   If aInt(i) <> 0 Then
                         iChar = aInt(i)
                         sChar = Chr(iChar)
                         sString = sString&sChar
                   End If
             Next
             regReadBinary=sString
      End If
End Function

Userfile Read & Write Script



Option Explicit
On Error Resume Next

' Variable Declarations
Dim sInFile, sOutFile
Dim oShell, fso
Dim InFile, OutFile
Dim WshNetwork
Dim sFolderLoc, sFile
Dim dictParams
Dim sCurrentLine
Dim sParam, sValue
Dim i, j, ParamCount
Dim bFound
Dim sProfilePath
Dim Linecount

Dim SHOWDEBUG
Dim MAXLINES

' Variable Definitions
Const ForReading = 1, ForWriting = 2, ForAppending = 8
SHOWDEBUG = False                                    ' Set this to True for various debug output

MAXLINES = 1000    ' This is the maximum number of lines the script will copy/create before quitting

' Setup Objects
Set oShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set dictParams = CreateObject("Scripting.Dictionary")

' This is the array of parameters we want to set
dictParams.Add "property", Array("deployment.expiration.check.enabled", "deployment.cache.enable" )    ' Add any additional parameters here
dictParams.Add "value",    Array("false"                              , "true"                    ) ' Add the value for each parameter here

ParamCount = UBound(dictParams("property"))                    ' How many parameters are we adding?
DebugText "Found " & ParamCount + 1 & " parameter(s)."

' Determine the path to the current deployment.properties file
' This has only been tested on Win 7 and Win 8.1
sProfilePath = oShell.ExpandEnvironmentStrings("%USERPROFILE%")
sFolderLoc = sProfilePath & "\AppData\LocalLow\Sun\Java\Deployment"
DebugText "Folder Loc: " & sFolderLoc

sInFile = sFolderLoc & "\deployment.properties"
sOutFile = sFolderLoc & "\deployment.newproperties"


' deployment.properties will obviously not be present if Java has not been installed,
' however it will also not be there until Java has run for the current user. The directory
' structure will not have been created either. By creating the properties file in advance
' however, we ensure that the settings will be there on our first-run, and they carry forward.
DebugText "Checking for existence of " & sInFile   

If NOT( FileExists ( sInFile ) ) Then                 ' If the file isn't there
    DebugText "Cannot find Java deployment.properties file. Java may nor be installed or has not been run yet."
    If NOT FolderExists ( sFolderLoc ) Then            ' Check if the folder is there (it shouldn't be)
        CreateDirs ( sFolderLoc )                    ' Create the folder, using a sub since we can't natively create nested folders
    End If
    Set Infile = fso.OpenTextFile(sInFile,ForWriting,True)    ' Create the properties file; this way we can just continue the rest of the
    InFile.Close                                            ' script as if the file had been there all along.
End If

Set InFile = fso.OpenTextFile(sInFile, ForReading)                ' This will be the original file we read in
Set OutFile = fso.OpenTextFile(sOutFile, ForWriting, True)        ' This is the revised file we create

' Basically we're going to:    Iterate through InFile file line by line
'                            Check each line to see if it matches one of the properties we want to change
'                            If it does, drop the line; we'll re-add at the end since there's no need to keep the file in order
'                            Otherwise just copy the line as it exists to the new file

LineCount = 0                                                ' Line counter

Do Until ( InFile.AtEndOfStream OR ( LineCount > MAXLINES ))
    sCurrentLine = InFile.ReadLine                            ' Read a line from InFile
    DebugText "Read line: " & sCurrentLine
    i = instr(sCurrentLine,"=")                                ' Find the split between the property and it's value
    If i > 0 Then                                            ' If we have an '=' then we have a property/value and not something else e.g. a comment (#)
        sParam = Left(sCurrentLine,(i-1))                    ' Split out the property
        sValue = Right(sCurrentLine, Len(sCurrentLine)-i)    ' Split out the value
        DebugText "Parameter: " & sParam & " | Value: " & sValue
        bFound = False                                       
        For j = 0 to ParamCount                                ' Loop through the list of parameters we want to set
            If sParam = dictParams("property")(j) Then        ' We've found a line matching the parameter we want to set so we are going to
                bFound = True                                ' skip copying it and instead replace it with our desired parameter/value
            End If
        Next
        If NOT bFound Then                                    ' If the line is NOT something we want to set/change, write it out, otherwise ignore it
            OutFile.WriteLine sParam & "=" & sValue            ' Technically we could just write out the entire line, but I split this up in case
        End If                                                ' I want to add some additional logic to the script down the road
    Else
        OutFile.WriteLine sCurrentLine                        ' Since we didn't find an '=' this is most likely a comment; just copy the line
    End If
    LineCount = LineCount + 1                                ' Increment the line count
Loop

For i = 0 to ParamCount                                        ' This is where we're adding the parameters and values we want to the new file
    OutFile.WriteLine dictParams("property")(i) & "=" & dictParams("value")(i)
Next

InFile.Close
OutFile.Close

fso.DeleteFile sInFile & ".bak"                                ' Delete any prior .bak files
fso.MoveFile sInFile, sInFile & ".bak"                        ' Copy the existing deployment.properties to deployment.properties.bak
fso.MoveFile sOutFile, sInFile                                ' Copy deployment.newproperties to deployment.properties

WScript.Quit ( 0 )                                            ' And we're done

' ******* Support Routines below
Function FileExists(file)
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    If (fso.FileExists(file)) Then
        FileExists = True
    Else
        FileExists = False
    End If
End Function

Private Function DebugText(text)
   If SHOWDEBUG Then
      MsgBox text
   End If
End Function

Function FolderExists(fldr)
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    If (fso.FolderExists(fldr)) Then
        FolderExists = True
    Else
        FolderExists = False
    End If
End Function

Sub CreateDirs( MyDirName )
' This subroutine creates multiple folders like CMD.EXE's internal MD command.
' By default VBScript can only create one level of folders at a time (blows
' up otherwise!).
'
' Argument:
' MyDirName   [string]   folder(s) to be created, single or
'                        multi level, absolute or relative,
'                        "d:\folder\subfolder" format or UNC
'
' Written by Todd Reeves
' Modified by Rob van der Woude
' http://www.robvanderwoude.com

    Dim arrDirs, i, idxFirst, objFSO, strDir, strDirBuild

    ' Create a file system object
    Set objFSO = CreateObject( "Scripting.FileSystemObject" )

    ' Convert relative to absolute path
    strDir = objFSO.GetAbsolutePathName( MyDirName )

    ' Split a multi level path in its "components"
    arrDirs = Split( strDir, "\" )

    ' Check if the absolute path is UNC or not
    If Left( strDir, 2 ) = "\\" Then
        strDirBuild = "\\" & arrDirs(2) & "\" & arrDirs(3) & "\"
        idxFirst    = 4
    Else
        strDirBuild = arrDirs(0) & "\"
        idxFirst    = 1
    End If

    ' Check each (sub)folder and create it if it doesn't exist
    For i = idxFirst to Ubound( arrDirs )
        strDirBuild = objFSO.BuildPath( strDirBuild, arrDirs(i) )
        If Not objFSO.FolderExists( strDirBuild ) Then
            objFSO.CreateFolder strDirBuild
        End if
    Next

    ' Release the file system object
    Set objFSO= Nothing
End Sub