Jump to content

How to tell which drive WinPE was launched from?


quantumriff

Recommended Posts

Is there a way to tell where WinPE was launched from?

We currently use a Batch file to do our imaging inside WinPe, and boot from either a USB flash drive, or a CD. However, we have a customization file that sits at the root of the drive (in the case of the USB flash drive) that allows you to set certain configuration settings, such as your default server, and stuff..

However, to find the file currently, in our batch file, we do somthing like this:

:LoadCustSettings

if exist c:\%CustFileName% set CustLoc=c:\%CustFileName%

if exist d:\%CustFileName% set CustLoc=d:\%CustFileName%

if exist e:\%CustFileName% set CustLoc=e:\%CustFileName%

if exist f:\%CustFileName% set CustLoc=f:\%CustFileName%

if exist g:\%CustFileName% set CustLoc=g:\%CustFileName%

if exist h:\%CustFileName% set CustLoc=h:\%CustFileName%

if exist x:\%CustFileName% set CustLoc=x:\%CustFileName%

That is rather in-efficient. Is there a way for Windows PE to know which drive it was booted from, such as an evironment variable? %SystemDrive% will point to the X: drive, but we don't want to inject this config file into the WIM file. We want to be able update it when needed, from inside Windows PE.

Link to comment
Share on other sites


I am to think, you can use a script that returns the drive letter for a specific volume name. Where a volume named "WinPE_CD" is on drive d: for example. My best bet would be that you could do this with AutoIT. It could be a combination of the following functions:

DriveGetDrive()

So if you use a CD, you would use DriveGetDrive("cdrom") which would return the drive letters for each of the CD Drives. If a case where there are multiple CD Drives, the next option would come in handy:

DriveGetLabel()

This lets you check by drive letter. You can check each drive letter returned in the previous function for the specific label that your PE media is using. This will allow you to get the drive letter you are searching for.

You may additionally wish to use @ScriptDir macro for any script sitting on that drive that is not in the PE media.

Visit: http://www.autoitscript.com/

Link to comment
Share on other sites

I use this to set the DVD drive to the 'z' drive and a timer function.

'--------------------------------------------------
' Here is some code to set the DVD to the z drive
'--------------------------------------------------

on error resume Next
Set Fso = CreateObject("Scripting.FileSystemObject")
Set objWShell = createobject("wscript.shell")
Set objWMI = GetObject("winmgmts:\\.\root\CIMV2")
set dc = fso.drives
found = False
for i = 0 to 5
For each d in dc
'** We only want to check DVD\CD-ROM drives **
if d.drivetype = 4 Then
if d.isready Then
dl = d.driveletter
'** Set the parent folder **
path = dl & ":\Tools"
if fso.folderexists(path) Then
set diskpart_script = fso.opentextfile("x:\set_drv.txt", 2, true)
diskpart_script.writeline "select volume " & dl & ":"
diskpart_script.writeline "assign letter = z:"
diskpart_script.writeline "exit"
diskpart_script.close
wshshell.run "diskpart /s x:\set_drv.txt",2,True
found = True
exit For
end If
end If
end If
Next
if found = true then exit For
objWShell.Run("wscript.exe sleep.vbs 5000"),0,True
Next



'---------------------------------------------------
' Here is the sleep timer.
'---------------------------------------------------
Option Explicit
Dim ArgObj, vSeconds
'create the object to get the seconds variable
Set ArgObj = WScript.Arguments
vSeconds = ArgObj(0)
set ArgObj = Nothing
' call wscript.sleep
wscript.sleep(vSeconds) '<– wait the length of time input
' that’s all folks!

I added it as an attachment TXT file too, I hope this helps...

Randy

SetDVD_Timer.txt

Edited by Tripredacus
added codebox
Link to comment
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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...