Option Explicit
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim objRegEx
Dim targetString
Dim colMatch
Dim objMatch
Dim objFSO
Dim strInputFile
Dim strOutputFile
Dim objInputFile
Dim objOutputFile
Dim strLine
Dim strPattern
Dim strMatch
strInputFile = Wscript.Arguments.Named("InputFile")
strOutputFile = Wscript.Arguments.Named("OutputFile")
strPattern = Wscript.Arguments.Named("Pattern")
strPattern = Replace(strPattern,""","""")
If Trim(strInputFile) <> "" And Trim(strPattern) <> "" Then
Set objRegEx = CreateObject("vbscript.regexp")
With objRegEx
.Pattern = strPattern
.Global = True
.IgnoreCase = True
End With
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strInputFile) Then
Set objInputFile = objFSO.OpenTextFile(strInputFile, ForReading )
If Trim(strOutputFile) <> "" Then
Set objOutputFile = objFSO.OpenTextFile(strOutputFile, ForAppending, True)
End If
Do While Not objInputFile.AtEndOfStream
strLine = objInputFile.ReadLine
If Trim(strLine) <> "" Then
Set colMatch = objRegEx.Execute(strLine)
For each objMatch in colMatch
strMatch = Replace(Replace(objMatch.Value,"UniqueID=",""),"""","")
If Trim(strOutputFile) <> "" Then
objOutputFile.WriteLine(strMatch)
Else
WScript.Echo(strMatch)
End If
Next
End If
Loop
objInputFile.Close
If Trim(strOutputFile) <> "" Then
objOutputFile.Close
End If
Set objInputFile = Nothing
Set objOutputFile = Nothing
Set objFSO = Nothing
End If
Else
ShowUsage()
End If
Sub ShowUsage
WScript.Echo "Usage: CScript.exe " & WScript.ScriptName & " /InputFile:""FILENAME"" [/OutputFile:""FILENAME]"" /Pattern:""PATTERN"""
WScript.Echo ""
WScript.Echo "Is OutputFile is omitted, matches will be displayed"
WScript.Echo ""
WScript.Echo "Substitute "" with ""
End Sub
Posted in Scripts.
Tagged with regular expression.
By svermaak
– May 6, 2012
Here is a table of all the combinations of dos box colors

Posted in Development.
Tagged with box, colors, dos.
By svermaak
– April 16, 2012
Add REG_SZ to HKLM\SOFTWARE\Microsoft\Command Processor with name AutoRun and value of RndColor.bat
Create file RndColor.bat in %WINDIR%\System32
@Echo Off
Echo Loading...
SET rnd=%random%
IF %rnd% LSS 4681 GOTO 1
IF %rnd% LSS 9362 GOTO 2
IF %rnd% LSS 14043 GOTO 3
IF %rnd% LSS 18724 GOTO 4
IF %rnd% LSS 23405 GOTO 5
IF %rnd% LSS 28086 GOTO 6
IF %rnd% LSS 32767 GOTO 7
Goto END
:1
Color 1F
Goto END
:2
Color 20
Goto END
:3
Color 30
Goto END
:4
Color 4E
Goto END
:5
Color 5F
Goto END
:6
Color 80
Goto END
:7
Color 4F
Goto END
:END
CLS
Posted in Development, Scripts.
Tagged with CMD, color, command prompt, random.
By svermaak
– April 12, 2012
This app will parse the output of “RepAdmin.exe /ShowRepl *” and display a unique list of all the servers with errors
- First create OUT.TXT with the following command:
- RepAdmin.exe /ShowRepl * > OUT.TXT
- Then run the following to get all errors from OUT.TXT
- ShowReplParser.exe OUT.TXT
Attachment(s):
Posted in Development.
Tagged with errors, repadmin, showrepl.
By svermaak
– April 11, 2012
Option Explicit
Dim objSMSClient
Dim varSiteID
varSiteID = Wscript.Arguments.Named("SiteID")
If Trim(varSiteID) <> "" Then
Set objSMSClient = CreateObject("Microsoft.SMS.Client")
objSMSClient.SetAssignedSite(varSiteID)
End If
Posted in Scripts.
Tagged with GPO, ID, SCCM, site.
By svermaak
– November 8, 2011
This is a macro that convert values to CamelHumpNotation
Sub FixCamelHump()
'
' FixCamelHump Macro
'
Dim strValue As String
Range("A1").Select
strValue = ActiveCell.Value
Do While strValue <> ""
ActiveCell.Value = FixThisString(strValue)
ActiveCell.Offset(1, 0).Select
strValue = ActiveCell.Value
Loop
End Sub
Private Function FixThisString(strValue As String)
Dim intCnt As Integer
Dim blnStartOfWord As Boolean
Dim strBuild As String
Dim strCurrentChar As String
For intCnt = 1 To Len(strValue)
strCurrentChar = Mid(strValue, intCnt, 1)
If IsLetter(strCurrentChar) = True Then
If blnStartOfWord = False Then
blnStartOfWord = True
strBuild = strBuild & UCase(strCurrentChar)
Else
strBuild = strBuild & LCase(strCurrentChar)
End If
Else
If blnStartOfWord = True Then
blnStartOfWord = False
End If
strBuild = strBuild & strCurrentChar
End If
Next
FixThisString = strBuild
End Function
Private Function IsLetter(strChar As String) As Boolean
If Asc(strChar) >= 97 And Asc(strChar) <= 122 Or Asc(strChar) >= 65 And Asc(strChar) <= 90 Then
IsLetter = True
Exit Function
End If
IsLetter = False
End Function
Posted in Scripts.
Tagged with CamelHumpNotation, Macro, Script.
By svermaak
– March 28, 2011
Usage: CScript.exe //NOLOGO InputBox.vbs /SendTo:SOMEAPP.BAT /prompt:”YOUR PROMPT GOES HERE” /title:”YOUR TITLE GOES HERE”
Example: CScript.exe //NOLOGO InputBox.vbs /SendTo:RUN.BAT /prompt:”Please enter you name” /title:”Name?”
Value supplied will be send to RUN.BAT as %1
Attachment(s):
Posted in Scripts.
Tagged with CMD, InputBox, Script.
By svermaak
– October 13, 2010
Usage: REG.vbs /Action:ADD|/Action:DELETE /Key:REGISTRYKEY [/Value:REGISTRYVALUE] [/DATA:REGISTRYVALUEDATA] [/TYPE:REGISTRYVALUETYPE]
Examples:
REG.vbs /Action:Add /Key:HKLM\SOFTWARE\NewKey
REG.vbs /Action:Add /Key:HKLMSOFTWARENewKey /Value:New_REG_SZ /Data:Value /Type:REG_SZ
REG.vbs /Action:Add /Key:HKLMSOFTWARENewKey /Value:New_REG_Binary /Data:”0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0″ /Type:REG_BINARY
REG.vbs /Action:Add /Key:HKLMSOFTWARENewKey /Value:New_REG_DWORD /Data:0 /Type:REG_DWORD
REG.vbs /Action:Add /Key:HKLMSOFTWARENewKey /Value:New_REG_EXPAND_SZ /Data:Value /Type:REG_EXPAND_SZ
REG.vbs /Action:Add /Key:HKLMSOFTWARENewKey /Value:New_REG_MULTI_SZ /Data:”Value1,Value2,Value3″ /Type:REG_MULTI_SZ
REG.vbs /Action:Delete /Key:HKLMSOFTWARENewKey /Value:New_REG_SZ
REG.vbs /Action:Delete /Key:HKLMSOFTWARENewKey
Attachment(s):
Posted in Scripts.
Tagged with Active Directory, GPO, REG.exe, Registry.
By svermaak
– September 1, 2010
If you want to start a disk cleanup with cleanmgr.exe, a sageset needs to exist.
Then following batch first replicates the settings that the command “cleanmgr /sageset:777” with all options selected would have create. After that it executes “cleanmgr /sagerun:777”.
For more info on cleanmgr.exe see http://cr.tl/11hm
@Echo Off
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Active Setup Temp Folders" /v "StateFlags0777" /t REG_DWORD /d 00000002 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Compress old files" /v "StateFlags0777" /t REG_DWORD /d 00000002 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Content Indexer Cleaner" /v "StateFlags0777" /t REG_DWORD /d 00000002 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Downloaded Program Files" /v "StateFlags0777" /t REG_DWORD /d 00000002 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Internet Cache Files" /v "StateFlags0777" /t REG_DWORD /d 00000002 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Memory Dump Files" /v "StateFlags0777" /t REG_DWORD /d 00000002 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Microsoft_Event_Reporting_2.0_Temp_Files" /v "StateFlags0777" /t REG_DWORD /d 00000002 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Offline Pages Files" /v "StateFlags0777" /t REG_DWORD /d 00000002 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Old ChkDsk Files" /v "StateFlags0777" /t REG_DWORD /d 00000002 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Recycle Bin" /v "StateFlags0777" /t REG_DWORD /d 00000002 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Remote Desktop Cache Files" /v "StateFlags0777" /t REG_DWORD /d 00000002 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Setup Log Files" /v "StateFlags0777" /t REG_DWORD /d 00000002 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files" /v "StateFlags0777" /t REG_DWORD /d 00000002 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\WebClient and WebPublisher Cache" /v "StateFlags0777" /t REG_DWORD /d 00000002 /f
CleanMgr /sagerun:777
This batch file can then be executed on remote host with PSExec from Sysinternals
PSExec.exe \\RemoteHost -c -d -f DiskCleanup.bat
Posted in Scripts.
Tagged with disk cleanup, remotely.
By svermaak
– August 23, 2010
IsSlowLink by Shaun Vermaak is an utility that returns Error Code 1 if slow link detected
Usage: IsSlowLink.exe HOSTNAMEORADDRESS MAXROUNDTRIPTIME
Attachment(s):
Posted in Development.
Tagged with is slow link.
By svermaak
– July 22, 2010