Check File Version

email me

‘On Error Resume Next

Option Explicit

Dim ReturnString, OfficePath, strValue, FSO

set FSO=CreateObject(“Scripting.FileSystemObject”)

OfficePath=”C:\Program Files (x86)\Microsoft Office\Office14\”
ReturnString=FSO.getfileversion(OfficePath & “winword.exe”)
strValue = Left(ReturnString,2)

msgbox strValue

‘Session.Property(“OFFVER”) = strValue
set fso=nothing

Search and Replace in Text File

email me

strFile = “C:\scripts\test.txt”
strFind = “Alpha”
strReplace = “Bravo”
FindAndReplace strFile, strFind, strReplace
function FindAndReplace(strFile, strFind, strReplace)
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objInputFile = objFSO.OpenTextFile(strFile,1)
strTempDir = objFSO.GetSpecialFolder(2)
Set objTempFile = objFSO.OpenTextFile(strTempDir & “\tmp.txt”,2,true)
do until objInputFile.AtEndOfStream
objTempFile.WriteLine(Replace(objInputFile.ReadLine, strFind, strReplace))
loop
objInputFile.Close
Set objInputFile = Nothing
objTempFile.Close
Set objTempFile = Nothing
objFSO.DeleteFile strFile, true
objFSO.MoveFile strTempDir & “\tmp.txt”, strFile
Set objFSO = Nothing
end function

Delete Reg Key using VBScript

email me

Option Explicit

‘On Error Resume Next

Dim WshShell
Set WshShell = CreateObject(“WScript.Shell”)

If KeyExists(“HKEY_CLASSES_ROOT\Test\Shell\Open”) Then

WshShell.RegDelete (“HKEY_CLASSES_ROOT\Test\Shell\Open\”)
End If

Function KeyExists(key)
Dim objShell
On Error Resume Next
Set objShell = CreateObject(“WScript.Shell”)
objShell.RegRead (key)
Set objShell = Nothing
If Err = 0 Then KeyExists = True
End Function

VBScript – Delete Line From a Text File

email me

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile("C:\scripts\file.txt")

OldContents = Split(objFile.ReadAll, vbNewLine)

objFile.Close

NewContents = ""

For Each Line In OldContents

	If InStr(Line,"TEXT1") > 0 Or InStr(Line,"TEXT2") > 0 Then
	
		NewContents = NewContents
		
	Else
		If Len(NewContents) = 0 Then
		
			NewContents = Line
			
		Else
		
			NewContents = NewContents & vbCrLf & Line
			
		End If
		
	End If
Next

Set objFile = objFSO.CreateTextFile("C:\scripts\file.txt")

objFile.Write NewContents

objFile.Close

 

 

Dim WshShell, value, strComputer, strProcess

Set WshShell = CreateObject("WScript.Shell")

strKey = wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")'could be any word(s) you're looking for
strFile = "C:\scripts\YourTextFile.txt"
LineNumber = "0"
CheckCase = "0"

DeleteLine strFile, strKey, LineNumber, CheckCase

 

Function DeleteLine(strFile, strKey, LineNumber, CheckCase)

'Remove line(s) containing text (strKey) from text file (strFile)

'or
'Remove line number from text file (strFile)
'or
'Remove line number if containing text (strKey) from text file (strFile)

'Use strFile = "C:\scripts\YourTextFile.txt" (Full path to text file)
'Use strKey = "Alpha Bravo" (Lines containing this text string to be deleted)
'Use strKey = "" (To not use keyword search)
'Use LineNumber = "1" (Enter specific line number to delete)
'Use LineNumber = "0" (To ignore line numbers)
'Use CheckCase = "1" (For case sensitive search )
'Use CheckCase = "0" (To ignore upper/lower case characters)

Const ForReading=1:Const ForWriting=2

Dim objFSO,objFile,Count,strLine,strLineCase,strNewFile

Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFile=objFSO.OpenTextFile(strFile,ForReading)
Do Until objFile.AtEndOfStream
strLine=objFile.Readline
If CheckCase=0 then strLineCase=ucase(strLine):strKey=ucase(strKey)
If LineNumber=objFile.Line-1 or LineNumber=0 then
If instr(strLine,strKey) or instr(strLineCase,strkey) or strKey="" then
strNewFile=strNewFile
Else
strNewFile=strNewFile&strLine&vbcrlf
End If
Else
strNewFile=strNewFile&strLine&vbcrlf
End If
Loop

objFile.Close

Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFile=objFSO.OpenTextFile(strFile,ForWriting)
objFile.Write strNewFile
objFile.Close

End Function

Uninstall Certificate Using Certutil.exe

email me

Option Explicit

On Error Resume Next

Dim objWshShell

Dim strCmd, strSupportDir,progfiles,certloc,strCmd1,systemdrv,oWs

Set objWshShell = CreateObject(“WScript.Shell”)
systemdrv = objWshShell.ExpandEnvironmentStrings(“%SystemDrive%”)

strSupportDir = systemdrv & “\Windows\SysWOW64\”

progfiles = objWshShell.ExpandEnvironmentStrings(“%ProgramFiles%”)

certloc = progfiles & “\Juniper Networks\Network Connect 6.3.0\Certificate Files\”

strCmd = strSupportDir & “certutil.exe -delstore Root ” & Chr(34) & “f1f3d981bf5062a64d363a5f215d43f3″ & Chr(34)

strCmd1 = strSupportDir & “certutil.exe -delstore TrustedPublisher ” & Chr(34) & “f1f3d981bf5062a64d363a5f215d43f3″ & Chr(34)

objWshShell.Run strCmd, 0, True
objWshShell.Run strCmd, 0, True
objWshShell.Run strCmd1, 0, True
objWshShell.Run strCmd1, 0, True
Set objWshShell = Nothing

Install Certificate Using Certutil.exe

email me

Option Explicit

‘On Error Resume Next

Dim objWshShell

Dim strCmd, strSupportDir,progfiles,certloc,strCmd1,systemdrv,oWs

Set objWshShell = CreateObject(“WScript.Shell”)
systemdrv = objWshShell.ExpandEnvironmentStrings(“%SystemDrive%”)

strSupportDir = systemdrv & “\Windows\SysWOW64\”

progfiles = objWshShell.ExpandEnvironmentStrings(“%ProgramFiles%”)

certloc = progfiles & “\Juniper Networks\Network Connect 6.3.0\Certificate Files\”

strCmd = strSupportDir & “certutil.exe -addstore Root ” & Chr(34) & certloc & “Juniper Netwrok adapters.cer” & Chr(34)

strCmd1 = strSupportDir & “certutil.exe -addstore TrustedPublisher ” & Chr(34) & certloc & “Juniper Netwrok adapters.cer” & Chr(34)

objWshShell.Run strCmd, 0, True

objWshShell.Run strCmd1, 0, True
Set objWshShell = Nothing

Check Reg Key using VBScript

email me

' RegKeyExists(strName)
'
' Returns True if a registry key exists and False if not.
'
' strName = Name of the registry key
'
' strName should begin with:
' HKEY_CURRENT_USER (or HKCU),
' HKEY_LOCAL_MACHINE (or HKLM),
' HKEY_CLASSES_ROOT (or HKCR),
' HKEY_USERS, or
' HKEY_CURRENT_CONFIG
 
Function RegKeyExists(strName)
 
Const NO_EXISTING_KEY = "HKEY_NO_EXISTING\Key\"
 
Dim objWsh
Dim strKeyPath
Dim strNoKeyError
 
Set objWsh = WScript.CreateObject("WScript.Shell")
strKeyPath = Trim(strName)
If Right(strKeyPath, 1) <> "\" Then strKeyPath = strKeyPath & "\"
On Error Resume Next
' Get the error description by trying to read a non-existent key
objWsh.RegRead NO_EXISTING_KEY
strNoKeyError = Err.Description
Err.Clear
objWsh.RegRead strKeyPath
' Compare the error description with the previous determined sample
If Replace(Err.Description, strKeyPath, NO_EXISTING_KEY) = strNoKeyError Then
  RegKeyExists = False
Else
  RegKeyExists = True
End If
Err.Clear
On Error Goto 0
Set objWsh = Nothing
 
End Function