Skip to content

Instantly share code, notes, and snippets.

@after-the-sunrise
Created February 2, 2013 03:57
Show Gist options
  • Save after-the-sunrise/4696058 to your computer and use it in GitHub Desktop.
Save after-the-sunrise/4696058 to your computer and use it in GitHub Desktop.
Script to replace specified property value. Usage : replace.vbs ${filename} ${key} ${value}
Option Explicit
Dim targetFile, propName, propValue
targetFile = WScript.Arguments(0)
propName = WScript.Arguments(1)
propValue = WScript.Arguments(2)
Dim objFS
Set objFS = CreateObject("Scripting.FileSystemObject")
Dim objTS, content, line
Set objTS = objFS.OpenTextFile(targetFile, 1, 0)
While objTS.AtEndOfStream = 0
line = objTS.ReadLine
If InStr(line, propName) <> 0 Then
line = propName & "=" & propValue
WScript.Echo "Property Changed : " & line
End If
content = content & line & vbNewLine
Wend
objTS.Close
WScript.Echo content
'
' Uncomment to replace the input file
'
' Set objTS = objFS.CreateTextFile(targetFile, true)
' objTS.Write(content)
' objTS.Close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment