Create an External Bootable Hard Drive

email me

Step 1: Connect external hard drive.

Step 2:
Open elevated Command Prompt.

Step 3: When the Command Prompt opens, enter the following command:

DISKPART and press enter.

LIST DISK and press enter.

Once you enter the LIST DISK command, it will show the disk number of your external hard drive. Note disk 1 (this should be your external drive). The primary hard disk should be disk 0.

Step 4:

SELECT DISK 1
CLEAN
CREATE PARTITION PRIMARY
SELECT PARTITION 1
ACTIVE
FORMAT FS=NTFS QUICK
ASSIGN
EXIT

* Leave the Command Prompt window open

Step 5: Insert the Windows DVD.

Step 6: Go back to the Command Prompt

type D: (where “D” is the DVD drive letter)

type CD BOOT and press enter.

type BOOTSECT.EXE /NT60 H: and press enter (where “H” is the external USB hard drive letter)

* remove the Windows DVD.

Step 7:

Now, exit the Command Prompt.

Plugin the Master USB flash drive, which will contain boot, efi, sources, AnyWims.wim, Tools, and other boot files and folders (such as the BOOTMGR).

Note, you may have all the files stored on a network share—-just copy them from the share to the external hard drive.

Also, you may need to unhide any hidden files on the Master USB flash drive to copy over Bootmgr and other boot files and folders.

Copy the contents of the Master USB flash drive over to the external drive.
* Note, if you don’t have a Master USB, make sure the root of your USB drive looks like this (these files and folders can be obtained from the Win 7 DVD):

AND…make sure you copy your customized boot.wim into the sources folder—if you have one.

Step 8:

Test external hard drive by rebooting and selecting Boot from USB hard drive.

Decoding Files

email me

' Author Eddie Jackson
' Data 3/10/2014
' Written to decode text files

On error resume next

'VARIABLES
Dim arrayKey, output
Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

'FILE TO DECODE
file1 = "text1.dat"

'UNIQUE ENCRYPTION CODE
arrayKey = ReturnKey( "encryption code ""code""" )

'DECODE FILE HERE
output = Encode( file1, "text1.txt", arrayKey )

'DELETE ENCODED FILE
objShell.Run "%comspec% /c text1.dat",0,true

''''' DO NOT EDIT BELOW THIS LINE
Function Encode( myFileIn, myFileOut, arrayCode )
Dim i, objFSO, objFileIn, objFileOut, objStreamIn

Const ForAppending = 8
Const ForReading = 1
Const ForWriting = 2
Const TristateFalse = 0
Const TristateMixed = -2
Const TristateTrue = -1
Const TristateUseDefault = -2

On Error Resume Next

If Not IsArray( arrayCode ) Then
arrayCode = Array( arrayCode )
End If
For i = 0 To UBound( arrayCode )
If Not IsNumeric( arrayCode(i) ) Then
Encode = 1032
Exit Function
End If
If arrayCode(i) < 0 Or arrayCode(i) > 255 Then
Encode = 1031
Exit Function
End If
Next

Set objFSO = CreateObject( "Scripting.FileSystemObject" )

If objFSO.FileExists( myFileIn ) Then
Set objFileIn = objFSO.GetFile( myFileIn )
Set objStreamIn = objFileIn.OpenAsTextStream( ForReading, TriStateFalse )
Else
Encode = 53
objStreamIn.Close
Set objStreamIn = Nothing
Set objFileIn = Nothing
Set objFSO = Nothing
Exit Function
End If

If objFSO.FileExists( myFileOut ) Then
Encode = 58
objStreamIn.Close
Set objStreamIn = Nothing
Set objFileIn = Nothing
Set objFSO = Nothing
Exit Function
Else
Set objFileOut = objFSO.CreateTextFile( myFileOut, True, False )
End If

i = 0
Do Until objStreamIn.AtEndOfStream
i = ( i + 1 ) \ ( UBound( arrayCode ) + 1 )
objFileOut.Write Chr( Asc( objStreamIn.Read( 1 ) ) Xor arrayCode(i) )
Loop

objFileOut.Close
objStreamIn.Close
Set objStreamIn = Nothing
Set objFileIn = Nothing
Set objFileOut = Nothing
Set objFSO = Nothing

Encode = Err.Number

Err.Clear
On Error Goto 0
End Function

Function ReturnKey( encryptionCode )
Dim i, arrayCode( )
ReDim arrayCode( Len( encryptionCode ) - 1 )
For i = 0 To UBound( arrayCode )
arrayCode(i) = Asc( Mid( encryptionCode, i + 1, 1 ) )
Next
ReturnKey = arrayCode
End Function

Encoding Files

email me

On error resume next

' Author Eddie Jackson
' Data 3/10/2014
' Written to encode text files

'VARIABLES
Dim arrayKey, output
Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

'FILES TO BE ENCODED
file1 = "text1.txt"
file2 = "text2.txt"

'UNIQUE ENCRYPTION CODE
arrayKey = ReturnKey( "encryption code ""code""" )

'ENCODE FILE HERE
output = Encode( file1, "text1.dat", arrayKey )
'DELETE PLAINTEXT
objShell.Run "%comspec% /c del /q text1.txt",0,true
'ENCODE FILE HERE
output = Encode( file2, "text2.dat", arrayKey )
'DELETE PLAINTEXT
objShell.Run "%comspec% /c del /q text2.txt",0,true

''''' DO NOT EDIT BELOW THIS LINE
Function Encode( myFileIn, myFileOut, arrayCode )
Dim i, objFSO, objFileIn, objFileOut, objStreamIn

Const ForAppending = 8
Const ForReading = 1
Const ForWriting = 2
Const TristateFalse = 0
Const TristateMixed = -2
Const TristateTrue = -1
Const TristateUseDefault = -2

On Error Resume Next

If Not IsArray( arrayCode ) Then
arrayCode = Array( arrayCode )
End If

For i = 0 To UBound( arrayCode )
If Not IsNumeric( arrayCode(i) ) Then
Encode = 1032
Exit Function
End If
If arrayCode(i) < 0 Or arrayCode(i) > 255 Then
Encode = 1031
Exit Function
End If
Next

Set objFSO = CreateObject( "Scripting.FileSystemObject" )

If objFSO.FileExists( myFileIn ) Then
Set objFileIn = objFSO.GetFile( myFileIn )
Set objStreamIn = objFileIn.OpenAsTextStream( ForReading, TriStateFalse )
Else
Encode = 53
objStreamIn.Close
Set objStreamIn = Nothing
Set objFileIn = Nothing
Set objFSO = Nothing
Exit Function
End If

If objFSO.FileExists( myFileOut ) Then
Encode = 58
objStreamIn.Close
Set objStreamIn = Nothing
Set objFileIn = Nothing
Set objFSO = Nothing
Exit Function
Else
Set objFileOut = objFSO.CreateTextFile( myFileOut, True, False )
End If

i = 0
Do Until objStreamIn.AtEndOfStream
i = ( i + 1 ) \ ( UBound( arrayCode ) + 1 )
objFileOut.Write Chr( Asc( objStreamIn.Read( 1 ) ) Xor arrayCode(i) )
Loop

objFileOut.Close
objStreamIn.Close
Set objStreamIn = Nothing
Set objFileIn = Nothing
Set objFileOut = Nothing
Set objFSO = Nothing

Encode = Err.Number

Err.Clear
On Error Goto 0
End Function

Function ReturnKey( encryptionCode )
Dim i, arrayCode( )
ReDim arrayCode( Len( encryptionCode ) - 1 )
For i = 0 To UBound( arrayCode )
arrayCode(i) = Asc( Mid( encryptionCode, i + 1, 1 ) )
Next
ReturnKey = arrayCode
End Function

Change Boot Sequence One Time

This allows you to return the last boot entry in the boot table, and then use bcdedit /bootsequence GUID to make a one-time change to the boot sequence.

@echo off
color 0c
cls
title One-time Boot Sequence Change
echo Fetching last boot entry…
ping.exe -n 4 127.0.0.1>nul
bcdedit>bootcfg.txt
for /f “tokens=*” %%a in (‘findstr /c:identifier bootcfg.txt’) do echo %%a>GUID.txt
for /f “tokens=2” %%b in (GUID.txt) do set VAL=%%b
cls
echo The last boot entry GUID is
echo %VAL%
echo.
color 0a
ping.exe -n 4 127.0.0.1>nul
echo Changing default boot sequence…
ping.exe -n 4 127.0.0.1>nul
bcdedit /bootsequence %VAL%
ping.exe -n 4 127.0.0.1>nul
echo Boot sequence has been changed!
ping.exe -n 4 127.0.0.1>nul
pause

email me

Return MD5 Hash

email me

These will return a MD5 hash that you could use to run CRC checks on files or even strings.

If all you need is a MD5, try this…

PowerShell

Clear-Host
$PathToYourFile = "C:\YourFileHere.txt"
$MD5 = Get-FileHash -Path $PathToYourFile -Algorithm MD5
$MD5

 

More elaborate handling…

C#

using System;
using System.Security.Cryptography;
using System.Text;

namespace MD5Hash
{
    class Program
    {
        static void Main(string[] args)
        {
            // String to test encoding and decoding
            string source = "TheIsATestMessage!";

            // Before encoding
            Console.WriteLine("Before Encoding: " + source);
            Console.WriteLine("");

            // After encoding
            using (MD5 md5Hash = MD5.Create())
            {
                string hash = GetMd5Hash(md5Hash, source);

                Console.WriteLine("After Encoding: " + hash);
                Console.WriteLine("");

                if (VerifyMd5Hash(md5Hash, source, hash))
                {
                    //the same
                    Console.WriteLine("");
                    Console.WriteLine("After Decoding (matches)");
                    Console.ReadKey();
                }
                else
                {
                    //not the same
                    Console.WriteLine("");
                    Console.WriteLine("After Decoding (does not match)");
                    Console.ReadKey();
                }
            }



        }
        static string GetMd5Hash(MD5 md5Hash, string input)
        {

            // Input string into byte array
            byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));

            // Collect bytes
            StringBuilder sBuilder = new StringBuilder();

            // Byte to hexadecimal translation 
            for (int i = 0; i < data.Length; i++)
            {
                sBuilder.Append(data[i].ToString("x2"));
            }

            // Return the hexadecimal string.
            return sBuilder.ToString();
        }

        // Verify a hash against a string.
        static bool VerifyMd5Hash(MD5 md5Hash, string input, string OriginalHash)
        {
            // Hash input - Will be used to compare hash against original string
            // string InputHash = GetMd5Hash(md5Hash, input) + "x";
            string InputHash = GetMd5Hash(md5Hash, input);

            // Compare hashes
            StringComparer comparer = StringComparer.OrdinalIgnoreCase;

            if (0 == comparer.Compare(InputHash, OriginalHash))
            {
                Console.WriteLine("Compare Old String: " + OriginalHash + " New String: " + InputHash);
                return true;
            }
            else
            {
                Console.WriteLine("Compare Old String: " + OriginalHash + " New String: " + InputHash);
                return false;
            }
        }

    }
}

 

VBScript method, though it is slow if the file is large…

VBScript

'Notes
'I created this using:
'http://www.pro-bono-publico.de/projects/unpacked/misc/mymd4.c
'Could be upgraded to:
'http://www.pro-bono-publico.de/projects/unpacked/misc/mymd5.c
'Pseudocode available here:
'https://en.wikipedia.org/wiki/MD5

Option Explicit
Dim PathToYourFile

'The file to return a MD5
PathToYourFile = "C:\YourFileHere.txt"


'No need to modify anything else

Private longTrack
Private arrayLongConversion(4)
Private arraySplit64(63)

Private Const OFFSET_4 = 4294967296
Private Const MAXINT_4 = 2147483647

Private Const S11 = 7
Private Const S12 = 12
Private Const S13 = 17
Private Const S14 = 22
Private Const S21 = 5
Private Const S22 = 9
Private Const S23 = 14
Private Const S24 = 20
Private Const S31 = 4
Private Const S32 = 11
Private Const S33 = 16
Private Const S34 = 23
Private Const S41 = 6
Private Const S42 = 10
Private Const S43 = 15
Private Const S44 = 21

'Calls md5 function and returns md5 hash
msgbox "MD5: " & MD5Hash(PathToYourFile),64,"MD5"


Public Function MD5Hash(strFilename)

	Dim strMD5, objFSO

	Set objFSO = CreateObject("Scripting.FileSystemObject")
	'clear string
	strMD5 = ""

	'If file exists, try reading it
	If objFSO.FileExists(strFilename) then
		strMD5 = BinaryToString(ReadTextFile(strFilename, ""))
		MD5Hash = CalculateMD5(strMD5)
	Else
		MD5Hash = strFilename & VbCrLf & "File not found!"
	End if

	End Function


Function ReadTextFile(FileName, CharSet)

	Const adTypeText = 2
	Dim BinaryStream 
	
	Set BinaryStream = CreateObject("ADODB.Stream")

	BinaryStream.Type = adTypeText

	If Len(CharSet) > 0 Then
		BinaryStream.CharSet = CharSet
	End If

	BinaryStream.Open
	BinaryStream.LoadFromFile FileName
	ReadTextFile = BinaryStream.ReadText

End Function


Function BinaryToString(Binary)

	Dim cl1, cl2, cl3, pl1, pl2, pl3, L	
	
	cl1 = 1
	cl2 = 1
	cl3 = 1
	L = LenB(Binary)

Do While cl1<=L 

	pl3 = pl3 & Chr(AscB(MidB(Binary,cl1,1))) 
	cl1 = cl1 + 1 
	cl3 = cl3 + 1 

	If cl3>300 Then
		pl2 = pl2 & pl3
		pl3 = ""
		cl3 = 1
		cl2 = cl2 + 1

		If cl2>200 Then
			pl1 = pl1 & pl2
			pl2 = ""
			cl2 = 1

		End If
	End If
Loop

BinaryToString = pl1 & pl2 & pl3

End Function


Private Function MD5Round(stringTranslation, a, b, c, d, X, S, ac)

	Select Case stringTranslation

	Case "FF"
		a = MD5LongAdd4(a, (b And c) Or (Not (b) And d), X, ac)
		a = MD5Rotate(a, S)
		a = MD5LongAdd(a, b)

	Case "GG"
		a = MD5LongAdd4(a, (b And d) Or (c And Not (d)), X, ac)
		a = MD5Rotate(a, S)
		a = MD5LongAdd(a, b)

	Case "HH"
		a = MD5LongAdd4(a, b Xor c Xor d, X, ac)
		a = MD5Rotate(a, S)
		a = MD5LongAdd(a, b)

	Case "II"
		a = MD5LongAdd4(a, c Xor (b Or Not (d)), X, ac)
		a = MD5Rotate(a, S)
		a = MD5LongAdd(a, b)
	End Select
	
End Function


Private Function MD5Rotate(longValue, longBits)

	Dim longSign, longI

	longBits = (longBits Mod 32)

	If longBits = 0 Then MD5Rotate = longValue: Exit Function

	For longI = 1 To longBits
		longSign = longValue And &HC0000000
		longValue = (longValue And &H3FFFFFFF) * 2
		longValue = longValue Or ((longSign < 0) And 1) Or (CBool(longSign And &H40000000) And &H80000000) 
	Next 

	MD5Rotate = longValue 

End Function 


Private Function TRID() 

	Dim singleNum, longnum, stringResult 

	singleNum = Rnd(2147483648) 
	stringResult = CStr(singleNum) 
	stringResult = Replace(stringResult, "0.", "") 
	stringResult = Replace(stringResult, ".", "") 
	stringResult = Replace(stringResult, "E-", "") 
	TRID = stringResult 

End Function 

Private Function MD564Split(longLength, bytBuffer()) 
	
	Dim longBytesTotal, longBytesToAdd, intLoop, intLoop2, longTrace, intInnerLoop, intLoop3 
	
	longBytesTotal = longTrack Mod 64
	longBytesToAdd = 64 - longBytesTotal 
	longTrack = (longTrack + longLength) 
	
	If longLength >= longBytesToAdd Then
		For intLoop = 0 To longBytesToAdd - 1
			arraySplit64(longBytesTotal + intLoop) = bytBuffer(intLoop)
		Next

	MD5Conversion arraySplit64

	longTrace = (longLength) Mod 64

	For intLoop2 = longBytesToAdd To longLength - intLoop - longTrace Step 64

		For intInnerLoop = 0 To 63
			arraySplit64(intInnerLoop) = bytBuffer(intLoop2 + intInnerLoop)
		Next

		MD5Conversion arraySplit64

	Next

	longBytesTotal = 0

Else

	intLoop2 = 0

End If

	For intLoop3 = 0 To longLength - intLoop2 - 1
		arraySplit64(longBytesTotal + intLoop3) = bytBuffer(intLoop2 + intLoop3)
	Next

End Function


Private Function MD5StringArray(strInput)

	Dim intLoop
	Dim bytBuffer()
	ReDim bytBuffer(Len(strInput))

	For intLoop = 0 To Len(strInput) - 1
		bytBuffer(intLoop) = Asc(Mid(strInput, intLoop + 1, 1))
	Next

	MD5StringArray = bytBuffer

End Function


Private Sub MD5Conversion(bytBuffer())
	
	Dim X(16), a, b, c, d

	a = arrayLongConversion(1)
	b = arrayLongConversion(2)
	c = arrayLongConversion(3)
	d = arrayLongConversion(4)

	MD5Decode 64, X, bytBuffer

	'reference: http://www.pro-bono-publico.de/projects/unpacked/misc/mymd4.c
	'/* Round 1 */
	MD5Round "FF", a, b, c, d, X(0), S11, -680876936
	MD5Round "FF", d, a, b, c, X(1), S12, -389564586
	MD5Round "FF", c, d, a, b, X(2), S13, 606105819
	MD5Round "FF", b, c, d, a, X(3), S14, -1044525330
	MD5Round "FF", a, b, c, d, X(4), S11, -176418897
	MD5Round "FF", d, a, b, c, X(5), S12, 1200080426
	MD5Round "FF", c, d, a, b, X(6), S13, -1473231341
	MD5Round "FF", b, c, d, a, X(7), S14, -45705983
	MD5Round "FF", a, b, c, d, X(8), S11, 1770035416
	MD5Round "FF", d, a, b, c, X(9), S12, -1958414417
	MD5Round "FF", c, d, a, b, X(10), S13, -42063
	MD5Round "FF", b, c, d, a, X(11), S14, -1990404162
	MD5Round "FF", a, b, c, d, X(12), S11, 1804603682
	MD5Round "FF", d, a, b, c, X(13), S12, -40341101
	MD5Round "FF", c, d, a, b, X(14), S13, -1502002290
	MD5Round "FF", b, c, d, a, X(15), S14, 1236535329

	'/* Round 2 */
	MD5Round "GG", a, b, c, d, X(1), S21, -165796510
	MD5Round "GG", d, a, b, c, X(6), S22, -1069501632
	MD5Round "GG", c, d, a, b, X(11), S23, 643717713
	MD5Round "GG", b, c, d, a, X(0), S24, -373897302
	MD5Round "GG", a, b, c, d, X(5), S21, -701558691
	MD5Round "GG", d, a, b, c, X(10), S22, 38016083
	MD5Round "GG", c, d, a, b, X(15), S23, -660478335
	MD5Round "GG", b, c, d, a, X(4), S24, -405537848
	MD5Round "GG", a, b, c, d, X(9), S21, 568446438
	MD5Round "GG", d, a, b, c, X(14), S22, -1019803690
	MD5Round "GG", c, d, a, b, X(3), S23, -187363961
	MD5Round "GG", b, c, d, a, X(8), S24, 1163531501
	MD5Round "GG", a, b, c, d, X(13), S21, -1444681467
	MD5Round "GG", d, a, b, c, X(2), S22, -51403784
	MD5Round "GG", c, d, a, b, X(7), S23, 1735328473
	MD5Round "GG", b, c, d, a, X(12), S24, -1926607734
	
	'/* Round 3 */
	MD5Round "HH", a, b, c, d, X(5), S31, -378558
	MD5Round "HH", d, a, b, c, X(8), S32, -2022574463
	MD5Round "HH", c, d, a, b, X(11), S33, 1839030562
	MD5Round "HH", b, c, d, a, X(14), S34, -35309556
	MD5Round "HH", a, b, c, d, X(1), S31, -1530992060
	MD5Round "HH", d, a, b, c, X(4), S32, 1272893353
	MD5Round "HH", c, d, a, b, X(7), S33, -155497632
	MD5Round "HH", b, c, d, a, X(10), S34, -1094730640
	MD5Round "HH", a, b, c, d, X(13), S31, 681279174
	MD5Round "HH", d, a, b, c, X(0), S32, -358537222
	MD5Round "HH", c, d, a, b, X(3), S33, -722521979
	MD5Round "HH", b, c, d, a, X(6), S34, 76029189
	MD5Round "HH", a, b, c, d, X(9), S31, -640364487
	MD5Round "HH", d, a, b, c, X(12), S32, -421815835
	MD5Round "HH", c, d, a, b, X(15), S33, 530742520
	MD5Round "HH", b, c, d, a, X(2), S34, -995338651

	'/* Round 4 */
	MD5Round "II", a, b, c, d, X(0), S41, -198630844
	MD5Round "II", d, a, b, c, X(7), S42, 1126891415
	MD5Round "II", c, d, a, b, X(14), S43, -1416354905
	MD5Round "II", b, c, d, a, X(5), S44, -57434055
	MD5Round "II", a, b, c, d, X(12), S41, 1700485571
	MD5Round "II", d, a, b, c, X(3), S42, -1894986606
	MD5Round "II", c, d, a, b, X(10), S43, -1051523
	MD5Round "II", b, c, d, a, X(1), S44, -2054922799
	MD5Round "II", a, b, c, d, X(8), S41, 1873313359
	MD5Round "II", d, a, b, c, X(15), S42, -30611744
	MD5Round "II", c, d, a, b, X(6), S43, -1560198380
	MD5Round "II", b, c, d, a, X(13), S44, 1309151649
	MD5Round "II", a, b, c, d, X(4), S41, -145523070
	MD5Round "II", d, a, b, c, X(11), S42, -1120210379
	MD5Round "II", c, d, a, b, X(2), S43, 718787259
	MD5Round "II", b, c, d, a, X(9), S44, -343485551

	arrayLongConversion(1) = MD5LongAdd(arrayLongConversion(1), a)
	arrayLongConversion(2) = MD5LongAdd(arrayLongConversion(2), b)
	arrayLongConversion(3) = MD5LongAdd(arrayLongConversion(3), c)
	arrayLongConversion(4) = MD5LongAdd(arrayLongConversion(4), d)

End Sub


Private Function MD5LongAdd(longVal1, longVal2)

	Dim longHighWord, longLowWord, longOverflow

	longLowWord = (longVal1 And &HFFFF&) + (longVal2 And &HFFFF&)
	longOverflow = longLowWord \ 65536
	longHighWord = (((longVal1 And &HFFFF0000) \ 65536) + ((longVal2 And &HFFFF0000) \ 65536) + longOverflow) And &HFFFF&
	MD5LongAdd = MD5LongConversion((longHighWord * 65536) + (longLowWord And &HFFFF&))

End Function


Private Function MD5LongAdd4(longVal1, longVal2, longVal3, longVal4)
	
	Dim longHighWord, longLowWord, longOverflow

	longLowWord = (longVal1 And &HFFFF&) + (longVal2 And &HFFFF&) + (longVal3 And &HFFFF&) + (longVal4 And &HFFFF&)
	longOverflow = longLowWord \ 65536
	longHighWord = (((longVal1 And &HFFFF0000) \ 65536) + ((longVal2 And &HFFFF0000) \ 65536) + ((longVal3 And &HFFFF0000) \ 65536) + ((longVal4 And &HFFFF0000) \ 65536) + longOverflow) And &HFFFF&
	MD5LongAdd4 = MD5LongConversion((longHighWord * 65536) + (longLowWord And &HFFFF&))
	
End Function


Private Sub MD5Decode(intLength, longOutBuffer(), bytInBuffer())
	
	Dim intdoubleIndex, intByteIndex, doubleSum

	intdoubleIndex = 0

	For intByteIndex = 0 To intLength - 1 Step 4
		doubleSum = bytInBuffer(intByteIndex) + bytInBuffer(intByteIndex + 1) * 256 + bytInBuffer(intByteIndex + 2) * 65536 + bytInBuffer(intByteIndex + 3) * 16777216
		longOutBuffer(intdoubleIndex) = MD5LongConversion(doubleSum)
		intdoubleIndex = (intdoubleIndex + 1)
	Next
	
End Sub


Private Function MD5LongConversion(doubleValue)
	
	If doubleValue < 0 Or doubleValue >= OFFSET_4 Then Error 6

	If doubleValue <= MAXINT_4 Then
		MD5LongConversion = doubleValue
	Else
		MD5LongConversion = doubleValue - OFFSET_4
	End If
	
End Function


Private Sub MD5Finish()
	
	Dim doubleBits, arrayPadding(72), longBytesBuffered
	
	arrayPadding(0) = &H80
	
	doubleBits = longTrack * 8
	longBytesBuffered = longTrack Mod 64
	
	If longBytesBuffered <= 56 Then
		MD564Split (56 - longBytesBuffered), arrayPadding
	Else
		MD564Split (120 - longTrack), arrayPadding	
	End If

	arrayPadding(0) = MD5LongConversion(doubleBits) And &HFF&
	arrayPadding(1) = MD5LongConversion(doubleBits) \ 256 And &HFF&
	arrayPadding(2) = MD5LongConversion(doubleBits) \ 65536 And &HFF&
	arrayPadding(3) = MD5LongConversion(doubleBits) \ 16777216 And &HFF&
	arrayPadding(4) = 0
	arrayPadding(5) = 0
	arrayPadding(6) = 0
	arrayPadding(7) = 0

	MD564Split 8, arrayPadding
	
End Sub


Private Function MD5StringChange(longnum)
	Dim bytA, bytB, bytc, bytD

	bytA = longnum And &HFF&
	
	If bytA < 16 Then
		MD5StringChange = "0" & Hex(bytA)
	Else
		MD5StringChange = Hex(bytA)
	End If

	bytB = (longnum And &HFF00&) \ 256
	
	If bytB < 16 Then
		MD5StringChange = MD5StringChange & "0" & Hex(bytB)
	Else
		MD5StringChange = MD5StringChange & Hex(bytB)
	End If

	bytC = (longnum And &HFF0000) \ 65536
		
	If bytC < 16 Then
		MD5StringChange = MD5StringChange & "0" & Hex(bytC)
	Else
		MD5StringChange = MD5StringChange & Hex(bytC)
	End If

	If longnum < 0 Then
		bytD = ((longnum And &H7F000000) \ 16777216) Or &H80&
	Else
		bytD = (longnum And &HFF000000) \ 16777216
	End If

	If bytD < 16 Then
		MD5StringChange = MD5StringChange & "0" & Hex(bytD)
	Else
		MD5StringChange = MD5StringChange & Hex(bytD)
	End If
End Function


Private Function MD5Value()
	MD5Value = LCase(MD5StringChange(arrayLongConversion(1)) &_ 
	MD5StringChange(arrayLongConversion(2)) &_
	MD5StringChange(arrayLongConversion(3)) &_
	MD5StringChange(arrayLongConversion(4)))
End Function


Public Function CalculateMD5(strMessage)
	Dim bytBuffer
	bytBuffer = MD5StringArray(strMessage)
	MD5Start
	MD564Split Len(strMessage), bytBuffer
	MD5Finish
	CalculateMD5 = MD5Value
End Function


Private Sub MD5Start()
	longTrack = 0
	arrayLongConversion(1) = MD5LongConversion(1732584193)
	arrayLongConversion(2) = MD5LongConversion(4023233417)
	arrayLongConversion(3) = MD5LongConversion(2562383102)
	arrayLongConversion(4) = MD5LongConversion(271733878)
End Sub

 

Notes

Microsoft File Checksum Integrity Verifier

http://www.pro-bono-publico.de/projects/unpacked/misc/mymd4.c

http://www.pro-bono-publico.de/projects/unpacked/misc/mymd5.c

 

Batch

for /r %%a in (*) do md5.exe %%a << md5.txt md5.exe C:\YourFileHere.txt < md5.txt

Setting up BitLocker on Multiple Partitions

This can setup BitLocker on C: drive and D: drive.

I am using E: drive as my recovery partition, and a temporary holding place for the keys. The keys should be deleted, moved, or encrypted once the encryption process is complete (for security reasons). You really want to separate the keys from the drive…just in case your computer falls into the wrong hands, or an emergency recovery is necessary due to a malfunctioning hard drive.

Note, this script should also be compiled after testing.

Script

rem this file should be named bitlocker.cmd and stored in c:\bittemp
rem launch file to begin enabling bitlocker

@echo off
color 0a
title Hard Drive Setup – Enable BitLocker
if exist c:\bittemp\token.txt goto :ENABLE

REM THIS COULD EVENTUALLY BE ENCRYPTED
set UName=administrator
set PWord=YourPasswordHere
set FName=bitlocker.cmd

md E:\boot\bitlocker

:TPM
cls
echo Disabling UAC…
REM DISABLES UAC
\\%computername%\c$\windows\system32\reg.exe ADD “HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System” /v EnableLUA /t REG_DWORD /d 0 /f
\\%computername%\c$\windows\system32\reg.exe ADD “HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System” /v PromptOnSecureDesktop /t REG_DWORD /d 0 /f
\\%computername%\c$\windows\system32\ping.exe -n 4 127.0.0.1>nul

rem Enable Autologin
cls
echo Disabling UAC…done
echo Enabling Autologin…
echo.
\\%computername%\c$\windows\system32\reg.exe add “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Runonce” /v bitlocker /t REG_SZ /d C:\bittemp\%FName% /f

REM ENABLE AUTOLOGIN
\\%computername%\c$\windows\system32\reg.exe add “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon” /v AutoAdminLogon /d 1 /t REG_SZ /f
\\%computername%\c$\windows\system32\reg.exe add “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon” /v DefaultUserName /d “%UName%” /t REG_SZ /f
\\%computername%\c$\windows\system32\reg.exe add “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon” /v DefaultPassword /d “%PWord%” /t REG_SZ /f
\\%computername%\c$\windows\system32\reg.exe delete “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System” /v LegalNoticeCaption /f
\\%computername%\c$\windows\system32\reg.exe delete “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System” /v LegalNoticeText /f
\\%computername%\c$\windows\system32\ping.exe -n 4 127.0.0.1>nul

cls
echo Disabling UAC…done
echo Enabling Autologin…done
echo Enabling TPM…
echo.
manage-bde -tpm -t
\\%computername%\c$\windows\system32\ping.exe -n 4 127.0.0.1>nul
echo done>c:\bittemp\token.txt
cls
echo Disabling UAC…done
echo Enabling Autologin…done
echo Enabling TPM…done
echo.
echo Restarting Computer…
\\%computername%\c$\windows\system32\ping.exe -n 4 127.0.0.1>nul
shutdown -r -f -t 3
goto:eof

:ENABLE
cls
echo Disabling UAC…done
echo Enabling Autologin…done
echo Enabling TPM…done
echo Enabling BitLocker for C: Systems drive…
echo.
\\%computername%\c$\windows\system32\ping.exe -n 60 127.0.0.1>nul
rem Enable Bitlocker on Data Drive
manage-bde -protectors -add c: -rp -rk E:\boot\bitlocker
manage-bde -on c: -s
manage-bde -protectors -get c: -type recoverypassword >e:\boot\bitlocker\c-drive.txt
\\%computername%\c$\windows\system32\ping.exe -n 4 127.0.0.1>nul

cls
echo Disabling UAC…done
echo Enabling Autologin…done
echo Enabling TPM…done
echo Enabling BitLocker for C: Systems drive…done
echo Enabling BitLocker for D: Data drive…
echo.
\\%computername%\c$\windows\system32\ping.exe -n 4 127.0.0.1>nul
manage-bde -protectors -add d: -rp -rk E:\boot\bitlocker
manage-bde -on d: -s
manage-bde -protectors -get d: -type recoverypassword>e:\boot\bitlocker\d-drive.txt
rem try copying to USB drive
if exist g: (
manage-bde -protectors -get d: -type recoverypassword>g:\d-drive.txt
)
rem set to autounlock on this computer
manage-bde -autounlock -enable d:
\\%computername%\c$\windows\system32\ping.exe -n 4 127.0.0.1>nul

REM DISABLE AUTOLOGIN
cls
echo Disabling UAC…done
echo Enabling Autologin…done
echo Enabling TPM…done
echo Enabling BitLocker for C: Systems drive…done
echo Enabling BitLocker for D: Data drive…done
echo Disabling Autologin…
\\%computername%\c$\windows\system32\reg.exe add “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon” /v AutoAdminLogon /d 0 /t REG_SZ /f
\\%computername%\c$\windows\system32\reg.exe add “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon” /v DefaultUserName /d “” /t REG_SZ /f
\\%computername%\c$\windows\system32\reg.exe add “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon” /v DefaultPassword /d “” /t REG_SZ /f
\\%computername%\c$\windows\system32\ping.exe -n 4 127.0.0.1>nul

REM ENABLES UAC
cls
echo Disabling UAC…done
echo Enabling Autologin…done
echo Enabling TPM…done
echo Enabling BitLocker for C: Systems drive…done
echo Enabling BitLocker for D: Data drive…done
echo Disabling Autologin…done
echo Enabling UAC…
\\%computername%\c$\windows\system32\reg.exe ADD “HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System” /v EnableLUA /t REG_DWORD /d 1 /f
\\%computername%\c$\windows\system32\reg.exe ADD “HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System” /v PromptOnSecureDesktop /t REG_DWORD /d 1 /f
\\%computername%\c$\windows\system32\ping.exe -n 4 127.0.0.1>nul

cls
echo Disabling UAC…done
echo Enabling Autologin…done
echo Enabling TPM…done
echo Enabling BitLocker for C: Systems drive…done
echo Enabling BitLocker for D: Data drive…done
echo Disabling Autologin…done
echo Enabling UAC…done
echo.
echo Bitlocker was successfully enabled!
echo.
echo Restarting Computer…
\\%computername%\c$\windows\system32\ping.exe -n 4 127.0.0.1>nul
start “” shutdown -r -f -t 4
del /q c:\bittemp\token.txt
del /q c:\bittemp\%FName%
rd /q c:\bittemp
exit /b 0

email me

Verify Files Based on MD5 Hash in WinPE

email me

@echo off
color 0c
title Imaging Compliance Tool

REM ADD FILE CRCs HERE using MD5deep64
REM USAGE IS – MD5 BOOT.WIM
REM USAGE IS – MD5 IMAGE.WIM

set BOOTWIM=497d8fc41a3c40b0a70f22a4f0e22f1a
set IMGWIM=d769b380931ec91eb1588bb260e57131

REM THIS WILL BE A HIDDEN DIAGNOSTIC WINDOW – ALT-TAB to get to Window
rem DO NOT EDIT BELOW THIS LINE
rem —————————————————————
cls
echo Verify imaging files and integrity
echo.

rem check to make sure files exist

color 0c

echo Searching for imaging files:
echo.
if not exist f:\boot\wim\boot.wim (
echo The Boot.wim file is missing! Setup will exit.
f:\boot\apps\ping.exe -n 10 127.0.0.1>nul
echo boot.wim could not be found>>f:\boot\wim\error.log
f:\boot\apps\taskkill.exe /f /im cmd.exe
)
echo Boot.wim found!
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul

if not exist f:\boot\wim\image.wim (
echo The Image.wim file is missing! Setup will exit.
f:\boot\apps\ping.exe -n 10 127.0.0.1>nul
echo image.wim could not be found>>f:\boot\wim\error.log
f:\boot\apps\taskkill.exe /f /im cmd.exe
)
echo Image.wim found!
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul

if not exist f:\boot\wim\imagex.exe (
echo The ImageX.exe file is missing! Setup will exit.
f:\boot\apps\ping.exe -n 10 127.0.0.1>nul
echo imagex.exe could not be found>>f:\boot\wim\error.log
f:\boot\apps\taskkill.exe /f /im cmd.exe
)
echo ImageX.exe found!
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul

if not exist f:\boot\wim\disk.txt (
echo The Disk.txt file is missing! Setup will exit.
f:\boot\apps\ping.exe -n 10 127.0.0.1>nul
echo disk.txt could not be found>>f:\boot\wim\error.log
f:\boot\apps\taskkill.exe /f /im cmd.exe
)
echo Disk.txt found!
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul

echo.
echo.
echo CRC validation – This process may take up to 5 minutes.
echo.
echo Performing Boot.wim CRC check…
echo.
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul

FOR /F “tokens=1 delims=%%i in (‘f:\boot\wim\md5 f:\boot\wim\boot.wim’) do set strBoot=%%i
echo Boot.wim is
echo %strBoot%
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul
echo.
echo CRC is
echo %BOOTWIM%
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul
echo.
if %strBoot% EQU %BOOTWIM% (
echo Boot.wim verified!
echo.
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul
)
if %strBoot% NEQ %BOOTWIM% (
echo Boot.wim failed CRC check! Setup will exit.
f:\boot\apps\ping.exe -n 10 127.0.0.1>nul
echo boot.wim failed crc>>f:\boot\wim\error.log
f:\boot\apps\taskkill.exe /f /im cmd.exe
)

echo.
echo.

echo Performing Image.wim CRC check…
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul

FOR /F “tokens=1 delims=%%j in (‘f:\boot\wim\md5 f:\boot\wim\image.wim’) do set strIMG=%%j
echo Image.wim is
echo %strIMG%
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul
echo.
echo CRC is
echo %IMGWIM%
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul
echo.
if %strIMG% EQU %IMGWIM% (
echo Image.wim verified!
echo.
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul
)
if %strIMG% NEQ %IMGWIM% (
echo Image.wim failed CRC check! Setup will exit.
f:\boot\apps\ping.exe -n 10 127.0.0.1>nul
echo image.wim failed crc>>f:\boot\wim\error.log
f:\boot\apps\taskkill.exe /f /im cmd.exe
)
echo.
echo.

echo Compliance check complete!
rem continue the imaging process
f:\boot\apps\ping.exe -n 4 127.0.0.1>nul

color 0a

Verify Files Based on Size and Date in WinPE

email me

@echo off
color 0c
title Imaging Compliance Tool

rem ADD SIZES OF FILES HERE – DIR FILENAME
set IMGWIM=11261172302
rem add date
set IMGDATE=03/05/2014

rem add size
set BOOTWIM=251636641
rem add date
set BOOTDATE=03/05/2014

cls
echo Used to verify imaging files, sizes, and dates
echo.

rem DO NOT EDIT BELOW THIS LINE
rem —————————————————————
rem check to make sure files exist

echo Searching for imaging files:
echo.
if not exist boot.wim (
echo The Boot.wim file is missing! Setup will exit.
pause
f:\boot\apps\taskkill.exe /f /im cmd.exe
)
echo Boot.wim found!
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul

if not exist image.wim (
echo The Image.wim file is missing! Setup will exit.
pause
f:\boot\apps\taskkill.exe /f /im cmd.exe
)
echo Image.wim found!
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul

if not exist imagex.exe (
echo The ImageX.exe file is missing! Setup will exit.
pause
f:\boot\apps\taskkill.exe /f /im cmd.exe
)
echo ImageX.exe found!
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul

if not exist disk.txt (
echo The Disk.txt file is missing! Setup will exit.
pause
f:\boot\apps\taskkill.exe /f /im cmd.exe
)
echo Disk.txt found!
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul

echo.
echo.

echo Checking Image.wim size…
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul
FOR /F “tokens=4 delims=%%i in (‘dir /-C image.wim ^| find /i “image.wim”‘) do (
echo Image.wim file size: %%i
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul
IF %%i EQU %IMGWIM% (
echo Image.wim verified!: %IMGWIM%
echo SUCCESS!
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul
) ELSE (
echo FAILED. Exiting setup…
pause
f:\boot\apps\taskkill.exe /f /im cmd.exe
)
)

echo.
echo.

echo Checking Image.wim date…
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul
FOR /F “tokens=1 delims=%%k in (‘dir /-C image.wim ^| find /i “image.wim”‘) do (
echo Image.wim file date: %%k
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul

f:\boot\apps\ping.exe -n 2 127.0.0.1>nul
IF %%k EQU %IMGDATE% (
echo Image.wim date verified!: %IMGDATE%
echo SUCCESS!
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul
) ELSE (
echo FAILED. Exiting setup…
pause
f:\boot\apps\taskkill.exe /f /im cmd.exe
)
)

echo.
echo.

echo Checking Boot.wim size…
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul
FOR /F “tokens=4 delims=%%j in (‘dir /-C boot.wim ^| find /i “boot.wim”‘) do (
echo Boot.wim file size: %%j
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul

f:\boot\apps\ping.exe -n 2 127.0.0.1>nul
IF %%j EQU %BOOTWIM% (
echo Boot.wim verified!: %BOOTWIM%
echo SUCCESS!
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul
) ELSE (
echo FAILED. Exiting setup…
pause
f:\boot\apps\taskkill.exe /f /im cmd.exe
)
)

echo.
echo.

echo Checking Boot.wim date…
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul
FOR /F “tokens=1 delims=%%l in (‘dir /-C boot.wim ^| find /i “boot.wim”‘) do (
echo Boot.wim file date: %%l
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul

f:\boot\apps\ping.exe -n 2 127.0.0.1>nul
IF %%l EQU %BOOTDATE% (
echo Boot.wim date verified!: %BOOTDATE%
echo SUCCESS!
f:\boot\apps\ping.exe -n 2 127.0.0.1>nul
) ELSE (
echo FAILED. Exiting setup…
pause
f:\boot\apps\taskkill.exe /f /im cmd.exe
)
)

echo.
echo.

color 0a
pause

Adding a Refresh Option to the Boot Menu

email me

This adds a Refresh Computer boot menu option to point to a recovery partition (e: in my case).

This boot option will launch your customized boot.wim, which will load the WinPE interface.
You can customize exactly what you want to happen once WinPE loads by editing the startnet.cmd in the boot.wim (c:\windows\system32\startnet.cmd).

You could refresh your system partition by storing an image.wim located on your recovery partition:

diskpart /s PathToRecoveryPartition\disk.txt (your partitioning sequence goes in here)

PathToRecoveryPartition\imagex.exe /apply PathToRecoveryPartition\image.wim 1 c: (c: or other drive will be your windows partition)

 

So, if you want to fully automate refreshing a computer from the boot menu:

Step 1 – Build an image.wim that is automated (this will be your customized windows image)

Step 2 – Edit the boot.wim startnet.net with diskpart and imagex command lines (basically the
WinPE.wim with added packages for scripting, hta, vbscript, etc.)

Step 3 – Partition drive with 4 partitions: system reserved, system, recovery, data (in that order)

Step 4 – Copy recovery files to recovery partition

Step 5 – Run the script below in WinPE

Step 6 – Select Recovery Option from the boot menu

 

Script

@echo off
color 0a
title Administrative Boot Loader

setlocal

:: Use the following set of commands to create a ramdiskoptions
:: object in the BCD store. The string "{ramdiskoptions}" is the
:: well-known name for the object's GUID.

set bcdedit=%systemroot%\system32\bcdedit.exe
set bcdstore=c:\boot\bcd

rem WDS
bcdedit /create {ramdiskoptions} /d "Refresh Your Computer"
bcdedit /set {ramdiskoptions} ramdisksdidevice partition=c:
bcdedit /set {ramdiskoptions} ramdisksdipath \boot\boot.sdi

rem Create a new boot entry.
bcdedit -create /d "Refresh Your Computer" /application OSLOADER
for /f "tokens=3" %%A in ('%bcdedit% -create /d "Refresh Your Computer" /application OSLOADER') do set guid1=%%A
echo The GUID is %guid1%

%bcdedit% /set %guid1% device ramdisk=[e:]\boot.wim,{ramdiskoptions}
%bcdedit% /set %guid1% path \windows\system32\boot\winload.exe
%bcdedit% /set %guid1% osdevice ramdisk=[e:]\boot.wim,{ramdiskoptions}
%bcdedit% /set %guid1% systemroot \Windows
%bcdedit% /set %guid1% winpe yes
%bcdedit% /set %guid1% detecthal yes
%bcdedit% /displayorder %guid1% /addlast
rem this sets boot to be default
rem %bcdedit% /default %guid1%

endlocal

pause
exit /b 0

Rename Workgroup Name

email me

This allows you to rename the WORKGROUP name to something else:

Source_files_here

VBscript
On error resume next
Set objShell = CreateObject(“WScript.Shell”)
objShell.Run “cmd /c C:\path\NetDom_NT.exe MEMBER \\%computername% /JOINWorkgroup New_Name_Here”, 0, True
WScript.Quit(0)

Shell
c:\path\NetDom_NT.exe MEMBER \\%computername% /JOINWorkgroup New_Name_Here


Notes

Join Computer to Domain
NETDOM /Domain:MYDOMAIN /user:adminuser /password:apassword MEMBER
MYCOMPUTER /JOINDOMAIN