Windows 7/8: Klon für das Ausführen von einem USB-Datenträger

 

Windows 7/8: How to start a Clone from a USB Drive

 

This page contains a VBS script that helps you to change the settings of the registry of the Windows clone in such a way that the clone can be booted via USB. The complete description is here. Before running the script you must connect to the registry of the windows clone (using letter z) and you must change the 4 drive letters on top of the script to your necessities.

 

How to

 

1.      Copy the text of the script into a new file and save it with the file extension VBS, e.g. USB_reg_change.VBS

2.      For Copyrights and exclusion of liability you should read at the top of the script.

3.      WARNING: VBS scripts may do anything on your computer. So you should check the contents to avoid this danger. I, even, cannot exclude that anybody changed the content of this website without my knowledge.

4.      Change the drive letters on top of the file.

5.      Connect to the proper registry.

6.      Run the script from commandline: cscript USB_reg_change.VBS (Remark: If you doubleclick the file it will run under wscript and all messages will not be print onto the console, but as message boxes.)

7.      Before starting the changes of the USB settings, the script will prompt a message box (STEP 1)

8.      Before renaming the drive letters, the script will prompt the 2nd message box (STEP 2)

 

 

The VBS script

 

str_actual_driveletter_of_original_windows_partition = "C:"    ' This is the System drive of the original windows.

str_new_driveletter_of_original_windows_partition    = "B:"    ' This drive letter should not exist, otherwise the old drive with this name will no longer be available

str_actual_driveletter_of_windows_clone_partition    = "R:"    ' This is the System drive of the windows clone. This drive letter will be unused at the end.

str_new_driveletter_of_windows_clone_partition       = "C:"    ' Mostly this will be the same letter as the first one!

 

 

' This script was written by Bernhard Abmayr of company EDV Abmayr

' This is version 1.0 of May 16th, 2013

' (c) Copyright: This script or any part of it may be copied, used and modified freely for private and other not commercial purpose.

'                You may give it or parts of it freely to others only together with the information about the author,

'                the exclusion of liability and the copyright. This script or parts of it must not be sold and it must not be used

'                for any commercial purpose without permission of the author. For this you need a license.

'

' Exclusion of liability: The user of this script is alone responsible for the results, I herewith deny any liability of my person!

'                         This script can contain program errors and could cause errors in your computers.

'

' I used http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/registry/#CreateStringDword.htm

' to generate this script

 

 

' Definitions for the registry part:

const HKEY_CURRENT_USER = &H80000001

const HKEY_LOCAL_MACHINE = &H80000002

 

' Definitions for the value types:

const REG_SZ = 1

const REG_EXPAND_SZ = 2

const REG_BINARY = 3

const REG_DWORD = 4

const REG_MULTI_SZ = 7

 

 

' Wscript.Echo: If you run that under wscript.exe (the default handler for the .vbs extension,

'               so what you'll get if you double-click the script) you'll get a "MessageBox"

'               dialog with your text in it. If you run that under cscript.exe you'll get

'               output in your console window.

' WScript.StdOut.WriteLine: This will cause an error, if it is started via Wscript. If you

'                           start it via Cscript, it makes an console output.

 

'MsgBox ("ATTENTION! This program modifies the connected registry!")

Wscript.Echo "This program changes the USB driver settings in such a way that the computer can be booted via USB."

Wscript.Echo "Before clicking OK, be sure that you have loaded the proper registry file X:\Windows\System32\Config\SYSTEM"

Wscript.Echo "to HKEY_LOCAL_MACHINE with the name z (using regedt32)"

' Loading another registry file as structure is fine, as this loaded structure is seen

' by this script too!

Wscript.Echo ""

Wscript.Echo "NOTE: If you are just looking to those registry entries, the changes will "

Wscript.Echo "      become visible after refreshing (F5)"

Wscript.Echo ""

Wscript.Echo ""

Wscript.Echo ""

 

msg = "STEP 1: Select YES if you want the program to change the USB settings of the connected registry!"

mb_result = MsgBox( msg, vbYesNo)

 

 

' Get the registry

strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_

strComputer & "\root\default:StdRegProv")

 

if (mb_result) = vbYes then

    '######################   CHANGE USB SETTINGS OF ControlSet001   ############################################################

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet001\Services\usbccgp", "Start", REG_DWORD, 0)

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet001\Services\usbccgp", "Group", REG_SZ   , "System Bus Extender")

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet001\Services\usbhub" , "Start", REG_DWORD, 0)

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet001\Services\usbhub" , "Group", REG_SZ   , "System Bus Extender")

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet001\Services\usbehci", "Start", REG_DWORD, 0)

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet001\Services\usbehci", "Group", REG_SZ   , "Boot Bus Extender")

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet001\Services\usbohci", "Start", REG_DWORD, 0)

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet001\Services\usbohci", "Group", REG_SZ   , "Boot Bus Extender")

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet001\Services\usbuhci", "Start", REG_DWORD, 0)

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet001\Services\usbuhci", "Group", REG_SZ   , "Boot Bus Extender")

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet001\Services\USBSTOR", "Start", REG_DWORD, 0)

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet001\Services\USBSTOR", "Group", REG_SZ   , "SCSI miniport")

 

    '######################   CHANGE USB SETTINGS OF ControlSet002  #############################################################

    ' This is needed for Windows 7, but will cause errors in Windows 8. Those errors can be ignoed

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet002\Services\usbccgp", "Start", REG_DWORD, 0)

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet002\Services\usbccgp", "Group", REG_SZ   , "System Bus Extender")

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet002\Services\usbhub" , "Start", REG_DWORD, 0)

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet002\Services\usbhub" , "Group", REG_SZ   , "System Bus Extender")

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet002\Services\usbehci", "Start", REG_DWORD, 0)

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet002\Services\usbehci", "Group", REG_SZ   , "Boot Bus Extender")

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet002\Services\usbohci", "Start", REG_DWORD, 0)

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet002\Services\usbohci", "Group", REG_SZ   , "Boot Bus Extender")

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet002\Services\usbuhci", "Start", REG_DWORD, 0)

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet002\Services\usbuhci", "Group", REG_SZ   , "Boot Bus Extender")

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet002\Services\USBSTOR", "Start", REG_DWORD, 0)

    iResult = SetRegistryValue(oReg, HKEY_LOCAL_MACHINE, "z\ControlSet002\Services\USBSTOR", "Group", REG_SZ   , "SCSI miniport")

else

    WScript.Echo "USB setting NOT changed."

end if

 

 

 

 

 

' Renaming the drive letters will not remove any entry in the registry.

' Only the key names are renamed. So you may restore it, if you made a

' mistake: Just replace the drive letters between ...Act and ...New

' But be sure that the order of renaming is so that not an existing entry

' is overwritten.

msg = "STEP 2: Now the program will change the drive letters of the connected registry: " & vbLf _

    & "Drive " & str_actual_driveletter_of_original_windows_partition & " will be renamed into " & str_new_driveletter_of_original_windows_partition & vbLf _

    & "Drive " & str_actual_driveletter_of_windows_clone_partition & " will be renamed into " & str_new_driveletter_of_windows_clone_partition & vbLf _

    & "If you want this, click YES, else NO" & vbLf _

    & "If you want to do it with other letters, select NO, change the script and run it again."

mb_result = MsgBox( msg, vbYesNo)

 

if mb_result = vbYes then

   

    strKeyPath = "z\MountedDevices"

 

    ' ### Change the drive letter of the original windows partition

    strValueNameAct = "\DosDevices\" & str_actual_driveletter_of_original_windows_partition

    strValueNameNew = "\DosDevices\" & str_new_driveletter_of_original_windows_partition

    intResult = oReg.GetBinaryValue (HKEY_LOCAL_MACHINE,strKeyPath,strValueNameAct,binValue)

    if intResult <> 0 then

        msg = "SCRIPT STOPPED, as it could not get the value of " & strKeyPath & strValueNameAct

        WScript.Echo "Quitting with error code 11001"

        WScript.Quit 11001

    else

        intResult = oReg.SetBinaryValue (HKEY_LOCAL_MACHINE,strKeyPath,strValueNameNew,binValue)

        if intResult = 0 then

            msg = strKeyPath & "\" & strValueNameAct & " was copied to " & strValueNameNew & ", value = "

            for i = LBound(binValue) to UBound(binValue)

                msg = msg & CInt(binValue(i)) & " "

            next

            Wscript.Echo msg

        else

            msg = strKeyPath & "\" & strValueNameAct & " FAILED copying to " & strValueNameNew & ", value = "

            WScript.Echo msg

            WScript.Echo "Quitting with error code 11002"

            WScript.Quit 11002

       end if

    end if

 

    ' ### Change the drive letter of the windows clone partition

    strValueNameAct = "\DosDevices\" & str_actual_driveletter_of_windows_clone_partition

    strValueNameNew = "\DosDevices\" & str_new_driveletter_of_windows_clone_partition

    intResult = oReg.GetBinaryValue (HKEY_LOCAL_MACHINE,strKeyPath,strValueNameAct,binValue)

    if intResult <> 0 then

        msg = "SCRIPT STOPPED, as it could not get the value of " & strKeyPath & strValueNameAct

        WScript.Echo "Quitting with error code 11011"

        WScript.Quit 11011

    else

        intResult = oReg.SetBinaryValue (HKEY_LOCAL_MACHINE,strKeyPath,strValueNameNew,binValue)

        if intResult = 0 then

            msg = strKeyPath & "\" & strValueNameAct & " was copied to " & strValueNameNew & ", value = "

            for i = LBound(binValue) to UBound(binValue)

                msg = msg & CInt(binValue(i)) & " "

            next

            Wscript.Echo msg

        else

            msg = strKeyPath & "\" & strValueNameAct & " FAILED copying to " & strValueNameNew & ", value = "

            WScript.Echo msg

            WScript.Echo "Quitting with error code 11012"

            WScript.Quit 11012

       end if

    end if

 

    ' ### Delete the old drive letter of the windows clone partition

    oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strValueNameAct

    if intResult = 0 then

        msg = strKeyPath & "\" & strValueNameAct & " was deleted "

        Wscript.Echo msg

    else

        msg = strKeyPath & "\" & strValueNameAct & " FAILED deleting "

        Wscript.Echo msg

    end if

 

else

    Wscript.Echo "Did not change any drive letters."

end if

 

Wscript.Echo "Program finished"

 

' sub SetRegistryValue

' INPUT: obj_registry: must be a valid, opened registry object

'        dw_registry_part: specifies the part of the registry (HKLM, ...) values see at top of file

'        str_key_path    : example: "z\ControlSet001\Services\usbccgp"

'        str_value_name  : example: "Start"   If the value name does not exist, it is tried to create it.

'        dw_value_type   : The type of the value. For existing values we could (but do not

'                          make this) determine the type ourselves:

'                          http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/registry/#EnumRegVals.htm

'                          But for new values the value type must be supplied.

'                          For valid values see the constant definition on top of file

'                          Actually only 2 types are supported!

'        new_value:        This is the new value for the registry entry, it may be of various types)

' RETURN: 0: function succeeded, the value did exist already and was overwritten

'        -1: function succeeded, the value did NOT exist and was created

'         1: setting or creating the value failed

function SetRegistryValue(obj_registry, dw_registry_part, str_key_path, str_value_name, dw_value_type, new_value)

 

    SetRegistryValue = 0     ' set the return value for "success"

 

    On Error resume next

 

    if dw_value_type = REG_DWORD then

        int_get_result = obj_registry.GetDWORDValue  (dw_registry_part, str_key_path, str_value_name, old_value)

        int_set_result = obj_registry.SetDWORDValue  (dw_registry_part, str_key_path, str_value_name, new_value)

        ' The following (commented) line of error testing did not work, but checking int_set_result works well.

        ' if Err.Number <> 0 then WScript.Echo Err.Number & " ERROR Source: " & Err.Source & " Description: " &  Err.Description

 

    elseif dw_value_type = REG_SZ then

        int_get_result = obj_registry.GetStringValue (dw_registry_part, str_key_path, str_value_name, old_value)

        int_set_result = obj_registry.SetStringValue (dw_registry_part, str_key_path, str_value_name, new_value)

    end if

 

    if int_get_result <> 0 then

        old_value = "UNDEFINED"

        SetRegistryValue = -1

    end if

 

    if int_set_result = 0 then   

        msg = str_key_path & "\" & str_value_name & "    was changed  from " & old_value & " into " & new_value

    else

        ' The following (commented) line of error testing did not work, but checking int_set_result works well.

        ' WScript.Echo Err.Number & " ERROR Source: " & Err.Source & " Description: " &  Err.Description

        ' Err.Clear

        msg = str_key_path & "\" & str_value_name & " FAILED changing from " & old_value & " into " & new_value

        SetRegistryValue = 1

    end if

    Wscript.Echo msg

 

    On Error goto 0

end function

 

 

 

 

 

 

 

Responsible: Bernhard Abmayr,  www.edv-abmayr.de, Last change: May 16th, 2013