Non-standard success exit codes

Some software distribution tools do not allow custom success exit codes. This means that if a software package returns a non-standard success exit code that the deployment status might return a failure instead of a success.

With this script an installation package’s non-standard success exit codes can be translated to exit code 0 within the software distribution tool.

Example: CScript.exe Setup.vbs /Command:SomeSetup.exe /SuccessCodes:1;2;3
In this example exit code 1,2 and 3 for SomeSetup.exe will be changed to 0

Attachment(s): [list-attachments]

[sourcecode language=”vb”]
Option Explicit

On Error Resume Next

Dim strCommand
Dim strSuccessCodes

strCommand = WScript.Arguments.Named("Command")
strSuccessCodes = WScript.Arguments.Named("SuccessCodes")

If Len(Trim(strCommand)) = 0 Or Len(Trim(strSuccessCodes)) = 0 Then
End If

Dim arrSuccessCodes
Dim intSuccessCode

arrSuccessCodes = Split(strSuccessCodes,";")

Dim objShell
Dim objExec
Dim intReturnCode

Set objShell = CreateObject("WScript.Shell")

Set objExec = objShell.Exec(strCommand)
If Err.Number <> 0 Then
WScript.Echo "Problem with command"
End If

Do While objExec.Status = 0
Call WScript.Sleep(100)

intReturnCode = objExec.ExitCode

For Each intSuccessCode In arrSuccessCodes
If IsNumeric(intSuccessCode) Then
If intReturnCode = CInt(intSuccessCode) Then
WScript.Echo "Success"
intReturnCode = 0
Exit For
End If
End If

Set objExec = Nothing
Set objShell = Nothing

Call WScript.Quit(intReturnCode)


This utility can be used to recreate any file at runtime.

It works by reading the input file with binaryreader and creates a function that can be called to recreate the input file.

Usage: CreateFileWithCode INPUTFILE > OUTPUTFILE

Attachment(s): [list-attachments]

[sourcecode language=”vb”]
Private Sub CreateFile()
Dim objBinaryWriter As System.IO.BinaryWriter

objBinaryWriter = New System.IO.BinaryWriter(System.IO.File.Open("CreateFileWithCode.exe", System.IO.FileMode.Create))

Dim intValue As Int32
Dim arrValues() As Int32 = { _
9460301, _
3, _
4, _
65535, _
184, _
0, _
64, _
0, _
0, _
0, _
0, _
0, _
0, _
0, _
0, _
128, _
247078670, _
-855002112, _
1275181089, _

0 _
For Each intValue In arrValues
Catch ex As Exception

End Try
End Sub

Remotely Rename A Computer

Remotely rename a computer and its Active Directory account using PSExec and batch file (vbs dropper)

Usage: PSExec.exe \\CURRENTCOMPUTERNAME -c -d -f RenameComputer.bat NEWCOMPUTERNAME
(Account needs Admin on target computer and modify rights on computer object in AD)

[sourcecode language=”plain”]
ECHO Option Explicit > RenameComputer.vbs
ECHO. >> RenameComputer.vbs
ECHO On Error Resume Next >> RenameComputer.vbs
ECHO. >> RenameComputer.vbs
ECHO Dim objWMIService >> RenameComputer.vbs
ECHO Dim colComputers >> RenameComputer.vbs
ECHO Dim objComputer >> RenameComputer.vbs
ECHO Dim varError >> RenameComputer.vbs
ECHO. >> RenameComputer.vbs
ECHO Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") >> RenameComputer.vbs
ECHO. >> RenameComputer.vbs
ECHO Set colComputers = objWMIService.ExecQuery("Select * from Win32_ComputerSystem") >> RenameComputer.vbs
ECHO. >> RenameComputer.vbs
ECHO For Each objComputer in colComputers >> RenameComputer.vbs
ECHO varError = objComputer.Rename("%1") >> RenameComputer.vbs
ECHO Next >> RenameComputer.vbs
ECHO WScript.Echo varError >> RenameComputer.vbs

CScript //NOLOGO RenameComputer.vbs
DEL RenameComputer.vbs

Shutdown -r -f -t 60

Generic RegEx Script

[sourcecode language=”vb”]

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
End If
End If
If Trim(strOutputFile) <> "" Then
End If
Set objInputFile = Nothing
Set objOutputFile = Nothing
Set objFSO = Nothing
End If
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


Command Prompt with Random Color on Startup

Add REG_SZ to HKLM\SOFTWARE\Microsoft\Command Processor with name AutoRun and value of RndColor.bat

Create file RndColor.bat in %WINDIR%\System32

[sourcecode language=”plain”]
@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

Color 1F
Goto END

Color 20
Goto END

Color 30
Goto END

Color 4E
Goto END

Color 5F
Goto END

Color 80
Goto END

Color 4F
Goto END



This app will parse the output of “RepAdmin.exe /ShowRepl *” and display a unique list of all the servers with errors

  1. First create OUT.TXT with the following command:
  2. RepAdmin.exe /ShowRepl * > OUT.TXT
  3. Then run the following to get all errors from OUT.TXT
  4. ShowReplParser.exe OUT.TXT

Attachment(s): [list-attachments]

Excel Macro to Convert to CamelHumpNotation

This is a macro that convert values to CamelHumpNotation
[sourcecode language=”vb”]
Sub FixCamelHump()

‘ FixCamelHump Macro

Dim strValue As String

strValue = ActiveCell.Value
Do While strValue <> ""
ActiveCell.Value = FixThisString(strValue)
ActiveCell.Offset(1, 0).Select
strValue = ActiveCell.Value
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)
strBuild = strBuild & LCase(strCurrentChar)
End If
If blnStartOfWord = True Then
blnStartOfWord = False
End If
strBuild = strBuild & strCurrentChar
End If
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