Sign in to follow this  
Followers 0
mehrdad39

Using fixed USB drive letter

8 posts in this topic

Hi All,

I am very new to scripting and programming and have been searching through all the posts and could not find a starting point for my project and I am hoping someone could get me on the right track. I have a system with one hard drive and two partitions. I have created a USB bootable WinPE with a script that restores either the "C" partition by one choice or the entire hard drive by another choice. It works greate except that when I add a second hard drive to my system, it can not find the drives to restore or clean because of different drive letters and volumes. Is there a way to fix the USB drive letter to maybe "Z" drive and still be able to restore "C" partiton by one choice and formatting the second partition and all other attached drives by a second choice. I used a sample script for button GUI and modified it to make it work with my USB WinPE as shown below. Is there anything anyone can suggest to make this work on any system with multiple hard drives and partitions? I appreciate any suggestions.

Thanks

Mehrdad

#include <GUIConstantsEx.au3>
#include <Process.au3>


Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $Button_1, $Button_2, $Button_3, $font, $msg, $widthCell
    
    GUICreate("Recovery Menu") ; will create a dialog box that when displayed is centered
    
        $widthCell = 100
    GUISetFont(11, 800, 4, $font) 
    GUICtrlCreateLabel("Restore and Recovery Utility", 1 * $widthCell, 15)
    GUISetFont(8.5, 400, $font) 
    GUICtrlCreateLabel("This utility is intended for a quick recovery of the server.", 50, 50, 3 * $widthCell, 70)
    GUICtrlCreateLabel("PARTIAL RESTORE will restore the System Files ONLY!", 50, 120, 3 * $widthCell, 40)
    GUICtrlCreateLabel("FULL RESTORE will restore the ENTIRE System!  All Data files will be ERASED!!!", 50, 160, 3 * $widthCell, 40)
    
    Opt("GUICoordMode", 2)
    $Button_1 = GUICtrlCreateButton("Partial Restore", -2 * $widthCell, 20, 100, 20)
    $Button_2 = GUICtrlCreateButton("Full Restore", -1, 30, 100, 20)
    $Button_3 = GUICtrlCreateButton("Reboot", -1, 30, 100, 20)
    
    GUISetState()      ; will display an dialog box with 3 button

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button_1
                RunWait(@ComSpec & " /c " & "USB Drive letter:\partial.cmd")    ; Will Run/Open Partial Restore script
            Case $msg = $Button_2
                RunWait(@ComSpec & " /c " & "USB Drive letter:\full.cmd")       ; Will Run/Open Full Restore script
            Case $msg = $Button_3
                Exit
        EndSelect
    WEnd
EndFunc

Share this post


Link to post
Share on other sites



Hi,

I don't know if it's working with WinPE but maybe this tool will help you to get the goal ...

USB Drive Letter Manager

Greets

Greenhorn

Share this post


Link to post
Share on other sites

Hi,

I don't know if it's working with WinPE but maybe this tool will help you to get the goal ...

USB Drive Letter Manager

Greets

Greenhorn

Hi Greenhorn

Thank you for your response. Unfortunately, that software will not work because WinPE is loased from USB and the first screen that loads up is the menu I have running. The service can not be installed before using the menu. This is a single load of WinPE everytime, on the server. There is no access to any part of windows to install the program. I was hoping to have a solution that could be included at the begining of the code I have for the menu so when the buttons are clicked, it would launch the CMD programs I have from "Z" drive (USB) regardless of the number of hard drives and their drive letters. I appreicate any other suggestions.

Thanks

Mehrdad

Share this post


Link to post
Share on other sites

If the script is running from the USB drive, you can pull the drive letter from @ScriptDir.

Otherwise, you can identify the USB drive with DriveGetDrive, DriveGetLabel, and/or DriveGetSerial.


[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites

If the script is running from the USB drive, you can pull the drive letter from @ScriptDir.

Otherwise, you can identify the USB drive with DriveGetDrive, DriveGetLabel, and/or DriveGetSerial.

I have added the code to get the correct drive letter for the removable drive. It works fine if I add that drive letter in my menu since the number of drives/partitions do not change. Of course if I add more drives or partitions to the system, that drive letter changes. My problem is changing that drive letter (whatever it comes up as based on the number of hard drives in the system) to "Z" drive everytime so the codes in the menu would run under one fixed drive letter regardless of what system it is plugged into.

Share this post


Link to post
Share on other sites

I have added the code to get the correct drive letter for the removable drive. It works fine if I add that drive letter in my menu since the number of drives/partitions do not change. Of course if I add more drives or partitions to the system, that drive letter changes. My problem is changing that drive letter (whatever it comes up as based on the number of hard drives in the system) to "Z" drive everytime so the codes in the menu would run under one fixed drive letter regardless of what system it is plugged into.

Hi,

maybe I'm a little bit dazed and confused ...

Please, tell me on which system your script is running and which system shall "see" the stick under the drive letter "Z:", WinPE or your PC system ...

To see the full actually code and a description of a scenario would help better to understand and help you.

Sorry, english isn't my native language ...

Share this post


Link to post
Share on other sites

Hi,

maybe I'm a little bit dazed and confused ...

Please, tell me on which system your script is running and which system shall "see" the stick under the drive letter "Z:", WinPE or your PC system ...

To see the full actually code and a description of a scenario would help better to understand and help you.

Sorry, english isn't my native language ...

Thanks for your response. The script is running from USB using WinPE 2. The system OS is not used. At this time I boot with USB and run The restore images (server1-3.wim) that are on the USB drive manually. I want to be able to restore any of the (3) systems automatically using the USB drive. However, I have different # of drives and partitions in each system. The script I have runs fine if all systems had the same # of HD and partitions. But it will not find the USB drive and it's restore files when it is inserted into a system with more # of HD and partitions. If there is a way I can force the USB to stay as "Z" drive within the same script as posted, then I can use the USB restore to restore any of the systems with their images automatically.

Thanks

Mehrdad

Share this post


Link to post
Share on other sites

I don't know about setting the USB drive letter on boot, it could be in winPE somewhere, but there is two options I could point you to, first is since the .cmd files are ASCII text files, you could always do a FileRead(), StringReplace(), FileWrite() on the .cmd files. The second option is to use EnvSet() and adjust the cmd files to use whatever environmental variables you set in the format of %var%

those are the 2 best ways to make it as dynamic as possible that I can see, without the contents of partial.cmd and full.cmd.

here is a good way to run the .cmd files if the autoit script is running off the usb.

;before the loop
$sDriveLetter = StringLeft(@ScriptDir,3)

;in the loop
RunWait(@ComSpec & " /c " & $sDriveLetter & "partial.cmd")

[size="2"] "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian Kernighan[/size]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0