Jump to content

Get Drive Letter


 Share

Recommended Posts

i've been playing with my first script and have an issue i can't seem to find here. Script will be used to load fresh computers with software and updates not included in the image. Script will be run from a portable or flash drive and i need to ensure that i can get the drive name so the script will operate first time out of the chute no matter what the drive name is.

How do i go about getting the drive name (e.g.; E:, F:, whatever) prior to starting everything up?

Thanks,

Dave

Link to comment
Share on other sites

Assuming you are referring to the Path from which the script is being run:

@ScriptDir = the full path of the script (e.g. F:\Scripts)

StringLeft(@ScriptDir, 2) = the Drive letter portion of the path from which the script is run

$FullPath = @ScriptDir
$DriveLetter = StringLeft(@ScriptDir, 2)
MsgBox(0, 'Path Info', 'The Script Directory is: ' & $FullPath & @LF & 'The Drive Letter is: ' & $DriveLetter)
Edited by Varian
Link to comment
Share on other sites

i've been playing with my first script and have an issue i can't seem to find here. Script will be used to load fresh computers with software and updates not included in the image. Script will be run from a portable or flash drive and i need to ensure that i can get the drive name so the script will operate first time out of the chute no matter what the drive name is.

How do i go about getting the drive name (e.g.; E:, F:, whatever) prior to starting everything up?

Thanks,

Dave

I had the same problem and used the following method : put a file with a very unlikelt name on your key and try to find it ...

$var = DriveGetDrive( "all" )
    If NOT @error Then
        For $i = 1 to $var[0]
            FileChangeDir ( $var[$i] )
            $search=FileFindFirstFile ( "wxzrtybdpq_fdtehsdt.txt" ) ; Unlikely to be found elsewhere ...
            If $search = -1 Then
                FileClose($search)
            Else
                FileClose($search)
                $drive = $var[$i] ; Won your drive's name is there
                $i = $var[0]
            EndIf
        Next
        If $search = -1 Then
            MsgBox(48, "Clé absente", "La clé USB est absente !!! Veuillez la mettre et relancer le programme ...")
            Exit
        EndIf

    EndIf

Theare are surely better ways to do it ... That only my two cents.

EDIT : I was right about the better way : Varian solution is obviously better

Edited by Stan099
Link to comment
Share on other sites

If you run the script, compiled or not, from the root of the thumb drive you can use the relative path to point to the programs to install. For example, installs are in a folder called Installs, the program to install is program.exe, you'd use "@ScriptDir & "\Installs\Program.exe""

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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
 Share

  • Recently Browsing   0 members

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