- Copy RndColor.bat to “%SystemRoot%\System32”
- Run RndColor.reg
- Open a command prompt
Attachment(s): [list-attachments]
Intelligence everywhere
Attachment(s): [list-attachments]
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
WScript.Quit(1)
End If
Dim arrSuccessCodes
Dim intSuccessCode
arrSuccessCodes = Split(strSuccessCodes,";")
Dim objShell
Dim objExec
Dim intReturnCode
Set objShell = CreateObject("WScript.Shell")
Err.Clear
Set objExec = objShell.Exec(strCommand)
If Err.Number <> 0 Then
WScript.Echo "Problem with command"
WScript.Quit(1)
End If
Do While objExec.Status = 0
Call WScript.Sleep(100)
Loop
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
Next
Set objExec = Nothing
Set objShell = Nothing
Call WScript.Quit(intReturnCode)
[/sourcecode]
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()
Try
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
objBinaryWriter.Write(intValue)
Next
Catch ex As Exception
End Try
End Sub
[/sourcecode]
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)
RenameComputer.bat
[sourcecode language=”plain”]
@ECHO OFF
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
[/sourcecode]
[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
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
[/sourcecode]
Here is a table of all the combinations of dos box colors
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
: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
[/sourcecode]
This app will parse the output of “RepAdmin.exe /ShowRepl *” and display a unique list of all the servers with errors
Attachment(s): [list-attachments]
[sourcecode language=”vb”]
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
[/sourcecode]
This is a macro that convert values to CamelHumpNotation
[sourcecode language=”vb”]
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
[/sourcecode]