Jump to content

A simpler way to get drive letter


Recommended Posts

As IT consultant, I'm always travelling from a customer to other.

I'm used to carry a nice 2.5 HD firewire and USB external drive with all my programs I need to do the job.

WPI is very nice, but I often got problem: wrong drive letter.

I solved this by a simple modification to make it simpler:

I added the file WPI.ICO at the root of my drive.

And I modified function findcdrom()

function FindCDRom()
{
position="generate.js";
whatfunc="FindCDRom()";

var a, i, li;

if (foundCDdrv)
return cddrv;

li = GetCDRomDriveLetters();
for(i=0; i<li.length; i++)
{
if (FileExists(li[i]+'\\WPI.ICO'))
cddrv = li[i];
}



foundCDdrv = true;

return cddrv;
}

What it does:

when the function getcdrom is called, it will scan all available drives to find a file named WPI.ICO. When the file WPI.ICO is found, it assigns the drive letter to value cddrv .

Of course, WPI scripts AND files to install must be in the same drive.

Hope it will help someone

too lazy to edit the file? Get the attachment !!!!

generate.js

Edited by staline
Link to comment
Share on other sites


I already made an update like this for 5.4. What mine does is scan all the fixed disks (harddrives) and compares the letter with wpipath. If they match, started from harddrive and WPI will use it accordingly for a new USSF feature I also added for 5.4. If not hdd is "" (blank) and assumes started from CD/DVD and continues with those checks as normal.

With this new feature WPI checks if started from CD/DVD or HDD. If CD/DVD then it will auto-hide the Extra Buttons (Options, Config.......). If from HDD it will show the Extra Buttons. No more having to remember to turn them off in Options before burning your disc.

Link to comment
Share on other sites

what are you all doing

that is very strange

you make it hard at your self

just replace the cdroom drive letter

with this word %cdrom%

like that

if your cdrom drive letter is d:

u write

d:\Acrobat_Reader_7.exe

just replace and it will run from the cdrom and find it whatever the letter is!

%cdrom%\Other\Acrobat_Reader_7.exe

Link to comment
Share on other sites

@faresalandlos: %cdrom% is a WPI variable and not a ms-dos variable. It is only set once WPI is started. What they are talking about is the code used to set the %cdrom% variable.

Just wanted to make sure you understood. Welcome to MSFN and WPI! :D

Link to comment
Share on other sites

  • 1 month later...
@faresalandlos: %cdrom% is a WPI variable and not a ms-dos variable. It is only set once WPI is started. What they are talking about is the code used to set the %cdrom% variable.

Just wanted to make sure you understood. Welcome to MSFN and WPI!

thanks man :D

and sorry for being late

Link to comment
Share on other sites

The only problem i have is when a cardreader is attached to the pc.

Then its all messed up.

it says no disc in drive.

I found one or two other topics about this , but couldnt find an answer.

Link to comment
Share on other sites

@muiz,

Isn't that the reasoning behind using the %cdrom%, %wpipath% or %root% variable? These should provide the relative path to WPI regardless of whether you are launching from cdrom or not.

The only possible issue would be on initial installation of the OS when all the drives have not been assigned yet, and you are coming back after a reboot or plug'n play...but even those issues are easily worked.

What stage are you losing the paths to your installs? Is it just plugging in a card reader? Since these paths are relative to where you launch wpi.hta, it seems they should resolve properly.

Edited by lawrenca
Link to comment
Share on other sites

If it is fresh installation of the OS you are working with why don't you preassign a letter like "W" to the cdrom using diskpart in run_once? You can be pretty sure than it will be a long time before your usual range of d, e, f, etc are taken up by the volumes created on the fixed hdd or added on volumes like card readers, pen drives or anything attached to the USB port.

Edited by pmshah
Link to comment
Share on other sites

@muiz,

Isn't that the reasoning behind using the %cdrom%, %wpipath% or %root% variable? These should provide the relative path to WPI regardless of whether you are launching from cdrom or not.

The only possible issue would be on initial installation of the OS when all the drives have not been assigned yet, and you are coming back after a reboot or plug'n play...but even those issues are easily worked.

What stage are you losing the paths to your installs? Is it just plugging in a card reader? Since these paths are relative to where you launch wpi.hta, it seems they should resolve properly.

XP setup went fine , but when WPI starts......NO DISC IN DRIVE.

Without the cardreader attached to the computer , it runs fine.

Link to comment
Share on other sites

i do not know if this will help but here is a js script that will return the drive letter using WMI.

I have it set using the $OEM$ folder and the cmdlines.txt as the check, you will have to edit that

to match what you need.

var wbemFlagReturnImmediately = 0x10;
var wbemFlagForwardOnly = 0x20;
var Fso = new ActiveXObject("Scripting.FileSystemObject");
var Act = new ActiveXObject("Wscript.Shell");
var Drv
/* PLACE THE FILE NAME HERE THIS IS JUST A EXAMPLE AND USES THE $OEM$ FOLDER AND CMDLINES.TXT*/
var WPI = "\\$OEM$\\cmdlines.txt"
var objWMIService = GetObject("winmgmts:\\\\.\\root\\CIMV2");
var colItems = objWMIService.ExecQuery("SELECT * FROM Win32_CDROMDrive", "WQL",
wbemFlagReturnImmediately | wbemFlagForwardOnly);
var enumItems = new Enumerator(colItems);
for (; !enumItems.atEnd(); enumItems.moveNext()) { var objItem = enumItems.item();
Drv = objItem.Drive + WPI;
if (Fso.FileExists(Drv))
{(Act.Popup("Set The CD Drive Letter = " + Drv, 7,"Confirm", 0 + 32 + 4096));}
else { Act.Popup("Can not find the CD or DVD drive?", 7,"Missing", 0 + 32 + 4096)}
;}

Link to comment
Share on other sites

i do not know if this will help but here is a js script that will return the drive letter using WMI.

I have it set using the $OEM$ folder and the cmdlines.txt as the check, you will have to edit that

to match what you need.

var wbemFlagReturnImmediately = 0x10;
var wbemFlagForwardOnly = 0x20;
var Fso = new ActiveXObject("Scripting.FileSystemObject");
var Act = new ActiveXObject("Wscript.Shell");
var Drv
/* PLACE THE FILE NAME HERE THIS IS JUST A EXAMPLE AND USES THE $OEM$ FOLDER AND CMDLINES.TXT*/
var WPI = "\\$OEM$\\cmdlines.txt"
var objWMIService = GetObject("winmgmts:\\\\.\\root\\CIMV2");
var colItems = objWMIService.ExecQuery("SELECT * FROM Win32_CDROMDrive", "WQL",
wbemFlagReturnImmediately | wbemFlagForwardOnly);
var enumItems = new Enumerator(colItems);
for (; !enumItems.atEnd(); enumItems.moveNext()) { var objItem = enumItems.item();
Drv = objItem.Drive + WPI;
if (Fso.FileExists(Drv))
{(Act.Popup("Set The CD Drive Letter = " + Drv, 7,"Confirm", 0 + 32 + 4096));}
else { Act.Popup("Can not find the CD or DVD drive?", 7,"Missing", 0 + 32 + 4096)}
;}

Ok thx , but a bit more info about how to use this plz.

Link to comment
Share on other sites

Where do i put this?
I am not sure as I have not used WPI and only provided the script as another way to set the

drive letter.

Here is a Cmd Promt script that will only check for the CD DVD drive

1:\ Makes a vbs script that checks only for the CD DVD drive

2:\ Outputs the CD DVD drive letter to a new cmd script

3:\ Then it calls the new cmd script and passes the CD DVD drive Letter back to the original script

Note you will have to change this line to match the file it will be looking for with WPI

Red text is the part you have to change please keep the quotations

Echo If Fso.FileExists(StrD ^& "\$OEM$\cmdlines.txt") Then >> %CDDVD%

Save As Set_CDDVD_Drv.cmd

@Echo Off
CLS
Color F9
Mode 65,5
Title Set CD DVD Drive Letter
Echo.
Echo Processing the CD DVD Drive Letter
set CDDVD=%SystemDrive%\CDDVD.vbs
Echo Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject") > %CDDVD%
Echo Dim Drv, strFileName, StrD, TS >> %CDDVD%
Echo Set Drv = Fso.Drives >> %CDDVD%
Echo strFileName = Fso.BuildPath(Wscript.ScriptFullName ^& "\..", "CDDVD.cmd") >> %CDDVD%
Echo strFileName = Fso.GetAbsolutePathName(strFileName) >> %CDDVD%
Echo For Each StrD In Drv >> %CDDVD%
Echo If StrD.DriveType = 4 Then >> %CDDVD%
Echo If StrD.IsReady = True Then >> %CDDVD%
Echo If Fso.FileExists(StrD ^& "\$OEM$\cmdlines.txt") Then >> %CDDVD%
Echo Set TS = Fso.CreateTextFile(strFileName) >> %CDDVD%
Echo Ts.WriteLine "Set CDROM=" ^& StrD ^& "\" >> %CDDVD%
Echo TS.Close >> %CDDVD%
Echo Else >> %CDDVD%
Echo Set TS = Fso.CreateTextFile(strFileName) >> %CDDVD%
Echo Ts.WriteLine "Set CDROM=Wrong_CD_DVD" >> %CDDVD%
Echo TS.Close >> %CDDVD%
Echo End If >> %CDDVD%
Echo End If >> %CDDVD%
Echo Else >> %CDDVD%
Echo Set TS = Fso.CreateTextFile(strFileName) >> %CDDVD%
Echo Ts.WriteLine "Set CDROM=No_CD_DVD_Disk_In_Drive" >> %CDDVD%
Echo TS.Close >> %CDDVD%
Echo End If >> %CDDVD%
Echo Next >> %CDDVD%

Start /w %CDDVD%

Call %SystemDrive%\CDDVD.cmd
Set %CDROM%=
Del %CDDVD%
Del %SystemDrive%\CDDVD.cmd
Echo %CDROM%
Pause

Edited by gunsmokingman
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...