Jump to content











Photo
- - - - -

Assign a Drive Letter for My Usb Stick under Win7PE


  • Please log in to reply
22 replies to this topic

#1 Tonton_Glenn

Tonton_Glenn

    Member

  • Advanced user
  • 47 posts
  •  
    France

Posted 04 October 2010 - 10:51 PM

Hi all,

I have a Win7pe project wich is booted from an USB stick.

My build is compiled in boot.wim so i have a X: drive letter for all files and folder system for Win7PE.

Drive Letter X: is only the content of boot.wim and that is perfect, but i want to launch portables apps wich are on root of my usb stick (near of "boot" and "sources" folders) and the drive letter must be fix because have some desktop shortcut to launch them. I dont want include these folders in my boot.wim, they must be placed on root of the stick.

Sometime, my usb stick take F: drive letter, sometime G: etc, depending of the number of disks present in a machine.

How can i do to assign a fix drive letter (ex: Z:) to my usb stick wich contain the project ?

I precise that this must be defined in the build and not after booting otherwise the shortcuts will be not created...

Many thanks for your attention,

Regards

#2 amalux

amalux

    Platinum Member

  • Tutorial Writer
  • 2813 posts
  •  
    United States

Posted 05 October 2010 - 12:22 AM

If you're interested, there is a W7PE here which creates shortcuts to all your portables on your desktop or start menu regardless of drive letter assigned <_<

More info here under 'Adding Portable Apps to Your PE' section.

:cheers:

#3 steve6375

steve6375

    Platinum Member

  • Developer
  • 7075 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars, www.easy2boot.com
  •  
    United Kingdom

Posted 05 October 2010 - 07:03 AM

Maybe you could use an environment variable in your shorcuts?

%PDRIVE%\pfolder\myapp\myapp.exe


and on WinPE startup, set PDRIVE to the drive letter to the USB stick using RMPartUSB, or just search all drives for a tag file to fond the correct drive?

#4 Tonton_Glenn

Tonton_Glenn

    Member

  • Advanced user
  • 47 posts
  •  
    France

Posted 05 October 2010 - 09:23 AM

Hi,

Many thanks for ure answers, Guys

Amalux, could you explain how to do what i want on my project with ure (nice and tested) ? I have read the section wich you mentionned but dont understand how to do.

steve6375 i think your tips is really what i search and just search all drives for a tag file to found the correct drive at the startup are the good way for me.

My problem is that i have an app suite portable on root of my usb stick wich is configured to launch at the startup of win7PE so the drive letter must be mount before to work fine.

How can i do this with a script a the build ?

For example, launch a script or batch file at startup wich search the file (like win7pe.cfg), when it find, assign driver lettre Z: to the stick where it was found.

Note : i not really a good developper, so if u have a script like what i want im insterrested <_<

Many thanks (and sorry for my english ^^)

#5 steve6375

steve6375

    Platinum Member

  • Developer
  • 7075 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars, www.easy2boot.com
  •  
    United Kingdom

Posted 05 October 2010 - 10:10 AM

in the cmd file use some script like

for %%I in &#40;C D E F G H I J K L M N O P Q R S T U V W X Y Z&#41; do if exist %%I&#58;\win7pe.cfg set USBdrive=%%I&#58;



@echo The USB drive is %USBdrive%



REM now run a program from the USB drive

%USBdrive%\myprog.exe
note the colon after the %%I

NB - no line break in first line (i.e. 4 lines of code)

#6 Tonton_Glenn

Tonton_Glenn

    Member

  • Advanced user
  • 47 posts
  •  
    France

Posted 05 October 2010 - 10:34 AM

exelent work steve6275 ! <_<

Only one more question and that will be perfect !

Rather than assign a variable (%USBdrive%) to call my program in the same script, can we call a dos command line who it will change actual drive letter to a fix drive letter ?

For example :

for %%I in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do if exist %%I:\win7pe.cfg set "change letter %%I to Z:"

In fact, know to translate my red comment in command line :cheers: , is that possible ?

Edit : and how can i integrate this in winbuilder via script (copy the batch file to startup procedure) ?

Thank for ure help

#7 Tonton_Glenn

Tonton_Glenn

    Member

  • Advanced user
  • 47 posts
  •  
    France

Posted 05 October 2010 - 11:00 AM

Begin of solution :

With the command subst, we can assign a virtual letter to a folder.

So, with command :

subst %%I Z&#58;

that should be working but we would have 2 drive letters for the same path, that's not awful...

Edit : maybe can we assign %%I batch file variable at a system variable ? Then i would modified my desktop shortcut generated with my winbuilder script to > AddShortcut, Desktop, "%%I\program.exe" and would be ok ? Possible ?

#8 steve6375

steve6375

    Platinum Member

  • Developer
  • 7075 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars, www.easy2boot.com
  •  
    United Kingdom

Posted 05 October 2010 - 12:26 PM

either should work, except you would use %USBdrive% not %%I in a shortcut.

however subst is probably more convenient for you so just use line
for %%I in &#40;C D E F G H I J K L M N O P Q R S T U V W X Y Z&#41; do if exist %%I&#58;\win7pe.cfg subst %%I&#58;  Z&#58;
always assuming you do not already have a Z: and the file win7pe.cfg exists in only one place of course!

No idea about winbuilder - maybe someone else can help you on this?

PS it's steve6375 not 6275 (I know it is a strange name - but I have strange parents!).

#9 Tonton_Glenn

Tonton_Glenn

    Member

  • Advanced user
  • 47 posts
  •  
    France

Posted 05 October 2010 - 01:45 PM

PS it's steve6375 not 6275 (I know it is a strange name - but I have strange parents!).

Oups sorry my friend <_<

In fact, I think that's YOUR solution the more practice, but only if the variable %DriveUSB% was kept in memory after the script at startup.

This would effectively have only one drive letter and be able to set my shortcuts with this variable that would be recognized.

But even under a normal windows, the batch with your code returns the value but does not store this value in the environment variables which is the ultimate problem.

An idee ?

#10 steve6375

steve6375

    Platinum Member

  • Developer
  • 7075 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars, www.easy2boot.com
  •  
    United Kingdom

Posted 05 October 2010 - 03:28 PM

use SETX ??

(SET USBdrive=%%I & SETX USBdrive %%I)

http://ss64.com/nt/setx.html

#11 Tonton_Glenn

Tonton_Glenn

    Member

  • Advanced user
  • 47 posts
  •  
    France

Posted 05 October 2010 - 04:31 PM

use SETX ??

(SET USBdrive=%%I & SETX USBdrive %%I)

http://ss64.com/nt/setx.html


Very nice steve6375 ! That's working on standard Windows, now will try on my project.

With setx, i have even choice between user or machine variable environnement. Will try with both and back (hope !!!) <_<

#12 Tonton_Glenn

Tonton_Glenn

    Member

  • Advanced user
  • 47 posts
  •  
    France

Posted 05 October 2010 - 06:33 PM

After several tests, that only works once batch is launched from the desktop.

Indeed, I can see that the batch is launched during boot (before arriving on desktop) but this does not affect the variable. However when I run the batch from the desktop that works, the varaible is created ...

I'm seeing for integrating the batch in the startup folder to see if that would working, but another problem is that my software shortcut does not create because the procedure is called before the batch.

Im lost, I will make other tests, any help is welcome

#13 sanbarrow

sanbarrow

    Silver Member

  • Developer
  • 788 posts
  • Location:Germany - Sauerland

Posted 05 October 2010 - 08:05 PM

So, with command :

CODE
subst %%I Z:


that should be working but we would have 2 drive letters for the same path, that's not awful...


Do you know remount.exe ?
works on 64bit as well as on 32 bit Pe and works like a charm
http://www.uwe-siebe...les/remount.zip

#14 Tonton_Glenn

Tonton_Glenn

    Member

  • Advanced user
  • 47 posts
  •  
    France

Posted 05 October 2010 - 08:27 PM

Hi sanbarrow,

Thank u for answer, I did'nt know this program thank you for this, I will use this soon i think. :cheers:

But this does not work with what I want because it goes back to the same problem, this must be initiated either manually or when the drive letter has already been assigned (on the desktop) and my shortcut woulnd'nt work...

The letter what i want must be initialized before creating the desktop shortcuts, I wonder if this is still possible.... <_<

Ive done a lot of research and here are some topics about the subject unfortunately still unanswered:

Here and Here

Some people talk about a script made by Nightman but I can not find it, however if it meets what i need...

Always in grall quest... :mellow:

#15 sanbarrow

sanbarrow

    Silver Member

  • Developer
  • 788 posts
  • Location:Germany - Sauerland

Posted 05 October 2010 - 08:48 PM

I put a tag-file on a USB disk and at boot-time search for the tag. Then replace the existing driveletter with R:

Shortcuts are no problem - I create them while booted into the PE simply by drag and drop.
Once I have my startmenu looking nice - and the desktop shortcuts as well - I copy those *.lnk files I just created and add them to the next build.
Or better - in my case I don't even have to do that as my home directory with startmenu and desktop and so on also is on the USB-drive which after boot will be used as R:
So here all I have to do is drag'n'drop to create a shortcut ...

#16 ChrisR

ChrisR

    Silver Member

  • .script developer
  • 784 posts
  •  
    France

Posted 05 October 2010 - 09:34 PM

Do you know remount.exe ?
works on 64bit as well as on 32 bit Pe and works like a charm
http://www.uwe-siebe...les/remount.zip

Hi Tonton_Glennl,

Here is what is done in Win7Pe_Se (2-Device Y.script) to assign CD/USB drive letter to Y, with the use of remount.exe (Yes, it works like a charm x86/x64).

Here the autoit program CdUsb that performs the test on the file cdusb.y and assign to Y.
Global $wait = 1000, $boucle = 10

IF NOT FILEEXISTS&#40;@SYSTEMDIR & &#34;\WinPesHL.exe&#34;&#41;THEN

 MSGBOX&#40;4096,&#34;Warning&#34;, &#34;This script only supports the VistaPE / Win7PE !&#34;, 5&#41;

EXIT

ENDIF



FILEINSTALL&#40;&#34;Win32\ReMount.exe&#34;, @SYSTEMDIR & &#34;\ReMount.exe&#34;&#41;



;Loop to wait 10 seconds max for USB drive READY

FOR $i=1 TO $boucle

$LETTER=DRIVEGETDRIVE&#40;&#34;ALL&#34;&#41;

IF NOT @ERROR THEN

FOR $L=1 TO $LETTER&#91;0&#93;

 IF &#40;STRINGREGEXP&#40;$LETTER&#91;$L&#93;, &#34;&#40;?i&#41;^&#40;A|B&#41;&#58;$&#34;&#41;&#41;THEN CONTINUELOOP

 IF &#40;STRINGREGEXP&#40;DRIVESTATUS&#40;$LETTER&#91;$L&#93;&#41;, &#34;NOTREADY&#34;&#41;&#41;THEN CONTINUELOOP

 IF FILEEXISTS&#40;$LETTER&#91;$L&#93; & &#34;\CdUsb.Y&#34;&#41;THEN

	RUNWAIT&#40;&#34;ReMount &#34; & $LETTER&#91;$L&#93; & &#34; Y&#58;&#34;, &#34;&#34;,@SW_HIDE&#41;

	FILEDELETE&#40;@SYSTEMDIR & &#34;\ReMount.exe&#34;&#41;

 EXIT

 ENDIF

NEXT

ENDIF

IF $i < $boucle THEN SLEEP&#40;$wait&#41;

NEXT
Amicalement

#17 Tonton_Glenn

Tonton_Glenn

    Member

  • Advanced user
  • 47 posts
  •  
    France

Posted 05 October 2010 - 09:45 PM

Wow !!!

Well, can i use your script "2-Device Y.script" present in Win7PE_SE_2010_09_06 distribution or i must recompilated it ?

I dont know autoit <_< so i dont hope then...

I just must put a file wich name is "cdusb.y" on my usb stick and ure script do the rest ?? If that, it's just... exelent !

Well, must recompilated it (if yes, could you explain to me how to do ?) or just use it and put the file on my stick ?

Many thanks ! (ouais, vraiment merci :cheers: )

Edit : Thanks to you too sanbarrow, I was able to test your method with bat file, i was on the right way i think :mellow:

#18 ChrisR

ChrisR

    Silver Member

  • .script developer
  • 784 posts
  •  
    France

Posted 05 October 2010 - 09:56 PM

Yes, just put a file wich name is "cdusb.y" on your usb stick and cdusb.exe do the rest.

Here's the script, the source and the program x86/x64

CdUsb.7z

Edited by ChrisR, 05 October 2010 - 09:59 PM.


#19 Tonton_Glenn

Tonton_Glenn

    Member

  • Advanced user
  • 47 posts
  •  
    France

Posted 05 October 2010 - 10:02 PM

I do not know how to thank you...

I'll test it right now, and as I said (in several different link) some people would be interested by your script, it could be integrated for futur version of Win7PE_SE dont think ? (as u have done for the cd drive)

Well, i go test it now, again thank you, you and all people who answered <_<

#20 ChrisR

ChrisR

    Silver Member

  • .script developer
  • 784 posts
  •  
    France

Posted 05 October 2010 - 10:14 PM

I do not know how to thank you...

I'll test it right now, and as I said (in several different link) some people would be interested by your script, it could be integrated for futur version of Win7PE_SE dont think ? (as u have done for the cd drive)

Well, i go test it now, again thank you, you and all people who answered <_<

Cdusb is already integrated in Win7Pe_Se. If you don't use it in wVistaPe or Win7Pe you have to change the begining of script (test WinPesHL.exe).

I'll also thank you, for your excelente french tutorials that you did.

Edited by ChrisR, 05 October 2010 - 10:25 PM.


#21 VV2006

VV2006

    Member

  • Members
  • 43 posts
  • Location:Russia
  •  
    Russian Federation

Posted 06 October 2010 - 11:22 AM

ChrisR
If filename cdusb.y will be change to usb.u and in CdUsb.au3 will be letter U: (in sting 26, 27), then this script will be not work?
Is letter Y: in CdUsb.exe hardcoded?

#22 ChrisR

ChrisR

    Silver Member

  • .script developer
  • 784 posts
  •  
    France

Posted 06 October 2010 - 02:19 PM

ChrisR
If filename cdusb.y will be change to usb.u and in CdUsb.au3 will be letter U: (in sting 26, 27), then this script will be not work?
Is letter Y: in CdUsb.exe hardcoded?

Yes letter Y and cdusb.y filename is hardcoded, but you have the autoit source code for change it if you want

#23 LeoMoon

LeoMoon
  • Members
  • 7 posts
  •  
    Canada

Posted 17 January 2011 - 09:47 AM

in the cmd file use some script like

for %%I in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do if exist %%I:\win7pe.cfg set USBdrive=%%I:



@echo The USB drive is %USBdrive%



REM now run a program from the USB drive

%USBdrive%\myprog.exe
note the colon after the %%I

NB - no line break in first line (i.e. 4 lines of code)

Hello, I want to do the same in LiveXP. I'm a total noob! Where do we put this .bat (right?) file before we make the live-xp .img file?

Tnx.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users