Jump to content
cemster

Permanent Internal Drive Letters

Recommended Posts

cemster

Hello everyone,

First, let me reveal the obvious; I am not an IT person, I am hardly trying to survive in the jungle... 
I have a production workstation with up to 13 internal drives with specific drive lettering assignment which is essential for my workflow.

My problem starts when I need to swap drives back and forth.
Even if I put the drives back with the same cabling, they still might be assigned different drive letters than they suppose to get.
So my question was; "Is there any way I can assign drive letters permanently no matter what, of course, unless I change them again.? Because I am really tired of reassigning 12 drives everytime I swap drives back and forth. There must be a way to prevent that... I am hoping..."

Few forums later I was politely suggested that I could do that with a boot/login script.
and suggested that I'd look in here and here...

As soon as I checked hen out I realized that this stuff is above my paycheck...

I don't know how and whit what, that I can pull this scripting thing off... Or how to implement one...

Is there anything in the script world that would provide such a wonderful function?

Thank you so much if you decide to give a hand to this miserable layman, he will be most appreciative...
 

Share this post


Link to post
Share on other sites
Earthshine

Why on earth are you swapping drives?  


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
orbs

@cemster, welcome to AutoIt and to the forum. first, allow me to apologize for the somewhat unwelcoming response above. i believe it meant that when you say 

On 1/21/2019 at 2:26 AM, cemster said:

13 internal drives with specific drive lettering assignment which is essential for my workflow.

then your workflow may be in need of revision.

given your workflow as it is, it should not be too hard to assign the same drive letter to the same physical drive when it is connected. drives (better referred to as "volumes") have a unique identifier (a.k.a. "Device ID"), and one can easily write a script that, when launched, scans the mounted volumes, use their Device ID to compare the assigned drive letter to the desired one, and changes the drive letter if required.

the first step is to formulate a list of your volumes and respective desired drive letters. to do that, connect your volumes, start a command prompt, and execute the command mountvol

you will see a list of your volumes, each showing the Device ID and drive letter. with this information we can proceed.

 

Share this post


Link to post
Share on other sites
Earthshine

It sounds like you need a little NAS instead


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
caramen

The best solution (in my opinion) is to work with your IT on this, 

 

You can ask them to put a batch script to map all your drive at the openning of your windows session, 

 

If you show them this thread, you can show them in active directory it is here : 

In english that will give you these fields : 

User properties, > Profil tab > Scipt of  openning's session, 

image.png.a6248257912e882b2651b3518073bbf3.png

This is how the script should be

net use w: /delete
net use w: \\******\*******$ /PERSISTENT:YES

net use k: /delete
net use k: \\********\*******$ /PERSISTENT:YES

net use q: /delete
net use q: \\******\*******$ /PERSISTENT:YES

net use u: /delete
net use u: \\******\**************$ /PERSISTENT:YES

net use j: /delete
net use j: \\*****************\************$ /PERSISTENT:YES

  

The second best solution (in my opinion) if you got admin rights, is to do it yourself and add a script like this into your startup folder.

The purpose is your goal. 

Have at each session openning a mapping of all needed folders. With the same letter :) And same tree.

Edited by caramen

My video tutorials : HERE ( In construction ) 

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
cemster

Thank you all for chipping in...

Thank you Orb for a warm welcome. 

My system needs to recognize the volumes as they are configured with their assigned Letters so things wouldn't get messed up. Not to mention that thousands of shortcuts depend on the same identification structure.

Nas is something I can not afford at the moment. 
As the swapping drives go, I need to swap libraries, raw material and work data back and forth with each new project. 

I will try to digest and understand the information that Orbs & Caramen have provided.

Unfortunately, I do not have any IT personnel in my payroll. I am it. :)
Hopefully, that will be enough to write that little script. I have a feeling that if I manage to ask smart questions, I might get some help... 
 

Edited by cemster

Share this post


Link to post
Share on other sites
jdelaney

you can also do net use * /delete to delete all network mappings, then rebuild them as you desire.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
Earthshine

What would happen if one or more of the 13 drives fails? Are you all backed up? Hopefully you are. 

Large hard drives are not expensive. A 4 bay nas isn’t either. Maybe from profits you can afford one and come up with a good back up plan if you don’t have one because that could be disastrous if you lose your drives


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
user4157124

As a start; array of drive properties (driveinfo.au3) :

#include-once
#include <AutoItConstants.au3>
#include <WinAPI.au3>; _WinAPI_GetVolumeNameForVolumeMountPoint()
#include <Array.au3>;  _ArrayColInsert()

Global Enum  $DRV_LETTER, _
             $DRV_TYPE, _
             $DRV_BUS, _
             $DRV_SSDSTAT, _
             $DRV_STATUS, _
             $DRV_FILESYS, _
             $DRV_LABEL, _
             $DRV_SERIAL, _
             $DRV_ID, _
             $DRV_SPCTOTAL, _
             $DRV_SPCOCC, _
             $DRV_SPCFREE, _
             $DRV__ENUM
Global       $__g_aDrvAttr[$DRV__ENUM]
             $__g_aDrvAttr[$DRV_LETTER]   = 'drive letter'
             $__g_aDrvAttr[$DRV_TYPE]     = 'drive type'
             $__g_aDrvAttr[$DRV_BUS]      = 'bus type'
             $__g_aDrvAttr[$DRV_SSDSTAT]  = 'SSD status'
             $__g_aDrvAttr[$DRV_STATUS]   = 'drive status'
             $__g_aDrvAttr[$DRV_FILESYS]  = 'file system'
             $__g_aDrvAttr[$DRV_LABEL]    = 'volume label'
             $__g_aDrvAttr[$DRV_SERIAL]   = 'volume serial'
             $__g_aDrvAttr[$DRV_ID]       = 'volume id'
             $__g_aDrvAttr[$DRV_SPCTOTAL] = 'space (MB) total'
             $__g_aDrvAttr[$DRV_SPCOCC]   = 'space (MB) occupied'
             $__g_aDrvAttr[$DRV_SPCFREE]  = 'space (MB) free'

Func _DriveGetAll()
    Local $aDrive = DriveGetDrive($DT_ALL)

    For $i1 = 1 To $DRV__ENUM - 1

        _ArrayColInsert($aDrive, $i1)

    Next

    $aDrive[0][0] = UBound($aDrive) - 1

    For $i1 = 1 To $aDrive[0][0]

        $aDrive[$i1][$DRV_LABEL]    = DriveGetLabel($aDrive[$i1][$DRV_LETTER] & '\')
        $aDrive[$i1][$DRV_TYPE]     = DriveGetType($aDrive[$i1][$DRV_LETTER] & '\', $DT_DRIVETYPE)
        $aDrive[$i1][$DRV_BUS]      = DriveGetType($aDrive[$i1][$DRV_LETTER] & '\', $DT_BUSTYPE)
        $aDrive[$i1][$DRV_SSDSTAT]  = DriveGetType($aDrive[$i1][$DRV_LETTER] & '\', $DT_SSDSTATUS)
        $aDrive[$i1][$DRV_STATUS]   = DriveStatus($aDrive[$i1][$DRV_LETTER] & '\')
        $aDrive[$i1][$DRV_FILESYS]  = DriveGetFileSystem($aDrive[$i1][$DRV_LETTER] & '\')
        $aDrive[$i1][$DRV_SERIAL]   = DriveGetSerial($aDrive[$i1][$DRV_LETTER] & '\')
        $aDrive[$i1][$DRV_ID]       = _WinAPI_GetVolumeNameForVolumeMountPoint($aDrive[$i1][$DRV_LETTER] & '\')
        $aDrive[$i1][$DRV_SPCTOTAL] = DriveSpaceTotal($aDrive[$i1][$DRV_LETTER] & '\')
        $aDrive[$i1][$DRV_SPCFREE]  = DriveSpaceFree($aDrive[$i1][$DRV_LETTER] & '\')
        $aDrive[$i1][$DRV_SPCOCC]   = $aDrive[$i1][$DRV_SPCTOTAL] - $aDrive[$i1][$DRV_SPCFREE]

    Next

    Return $aDrive
EndFunc

Func _DriveAttrHeader()
    Local $sHeader = ''

    For $i1 = 0 To $DRV__ENUM - 1

        $sHeader &= $__g_aDrvAttr[$i1] & ($i1 < $DRV__ENUM - 1 ? '|' : '')

    Next

    Return $sHeader
EndFunc

Example (retrieving collected information) :

#include <Array.au3>; _ArrayDisplay()
#include "driveinfo.au3"

Global Const $g_aDrive = _DriveGetAll()

_ArrayDisplay($g_aDrive, @ScriptName, '', 0, Default, _DriveAttrHeader())
ConsoleWrite('Drive ' & $g_aDrive[1][$DRV_LETTER] & '\ (' & $g_aDrive[1][$DRV_LABEL] & ') ' & Round($g_aDrive[1][$DRV_SPCFREE], 2) & 'MB free' & @CRLF)

 

Edited by user4157124
_WinAPI_GetVolumeNameForVolumeMountPoint()

Share this post


Link to post
Share on other sites
orbs

@caramen, @jdelaney, this is not about mapping network shares, this is about local volumes. "net use" does not fit here.

@user4157124, using AutoIt native Drive* functions is not suitable. these functions correlate the drive information to the drive letter as the unique identifier. this is sufficient for most purposes, however when the drive letter itself changes, you lose all reference to the volume. you cannot mount (or dismount and remount) a volume with these functions, you can only work with volumes that are already mounted as a root drive - i.e. have an unchanging drive letter.

 

Share this post


Link to post
Share on other sites
caramen

@orbs You are true I just noticed that. 

Edited by caramen

My video tutorials : HERE ( In construction ) 

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Nine

Hey guys how about using WMI to keep track of all the devices and reassign proper lettering based on device recognition ?

@cemster run this and see if you find something useful of it...there is a huge number of classes within WMI.  Maybe some could fit your needs.

#include <Constants.au3>

Opt ("MustDeclareVars", 1)

_DiskDrive ()

Func _DiskDrive ()
Local $List, $Rep

    Local $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
    Local $colItems = $objWMIService.ExecQuery('SELECT * FROM Win32_DiskDrive')
    If not IsObj($colItems) Then Exit MsgBox (0,"","Not an object")
    If not $colItems.count then Exit MsgBox (0,"","Not found")
    For $sItem In $colItems
        $List = ""
        For $sProperty In $sItem.Properties_
            $List &= $sProperty.Name & ": " & $sProperty.Value & @CRLF
        Next
        $Rep = MsgBox ($MB_OKCANCEL,"",$List)
        if $Rep = $IDCANCEL then ExitLoop
    Next

EndFunc

#cs

  uint16   Availability;
  uint32   BytesPerSector;
  uint16   Capabilities[];
  string   CapabilityDescriptions[];
  string   Caption;
  string   CompressionMethod;
  uint32   ConfigManagerErrorCode;
  boolean  ConfigManagerUserConfig;
  string   CreationClassName;
  uint64   DefaultBlockSize;
  string   Description;
  string   DeviceID;
  boolean  ErrorCleared;
  string   ErrorDescription;
  string   ErrorMethodology;
  string   FirmwareRevision;
  uint32   Index;
  datetime InstallDate;
  string   InterfaceType;
  uint32   LastErrorCode;
  string   Manufacturer;
  uint64   MaxBlockSize;
  uint64   MaxMediaSize;
  boolean  MediaLoaded;
  string   MediaType;
  uint64   MinBlockSize;
  string   Model;
  string   Name;
  boolean  NeedsCleaning;
  uint32   NumberOfMediaSupported;
  uint32   Partitions;
  string   PNPDeviceID;
  uint16   PowerManagementCapabilities[];
  boolean  PowerManagementSupported;
  uint32   SCSIBus;
  uint16   SCSILogicalUnit;
  uint16   SCSIPort;
  uint16   SCSITargetId;
  uint32   SectorsPerTrack;
  string   SerialNumber;
  uint32   Signature;
  uint64   Size;
  string   Status;
  uint16   StatusInfo;
  string   SystemCreationClassName;
  string   SystemName;
  uint64   TotalCylinders;
  uint32   TotalHeads;
  uint64   TotalSectors;
  uint64   TotalTracks;
  uint32   TracksPerCylinder;

#ce

 

Edited by Nine

Share this post


Link to post
Share on other sites
orbs

i use WMI volume enumeration in a project of mine involving monitoring volumes. WMI is a powerful tool, but i suspect it is overkill for this purpose (and for the OP skill set).

(b.t.w. @Nine, you are doing drive enumeration, not volume enumeration, which is problematic for the same reason i mentioned earlier.)

an alternative approach would be to have, on the root of each volume, a text file (named for example "DesiredDriveLetter.txt") which for example holds only the text "F:" for the volume that should be mounted as drive F:

then, a script is to scan the mounted volumes, and for each one that has such a file, compare the contents of the file with the current drive letter. if different, use the following functions:

_WinAPI_GetVolumeNameForVolumeMountPoint() ; get the volume unique identifier
_WinAPI_DeleteVolumeMountPoint() ; disassociate the current drive letter
_WinAPI_SetVolumeMountPoint() ; associate the desired drive letter

to accommodate for cross-assignment (i.e. F: is assigned to the volume supposed to be G: and vice-versa) the operation should be performed as a batch, not for each volume separately. like this:

STEP 1: list all volumes that have a DesiredDriveLetter.txt into an array
STEP 2 (loop #1): for each volume, remember the desired drive letter into the array, then get the GUID and dismount (optimization: dismount only if the desired drive letter is already assigned to another volume)
STEP 3 (loop #2): for each volume, mount with the desired drive letter stored in the array

then throw in some logging, error checking, messages, etc.

 

Edited by orbs

Share this post


Link to post
Share on other sites
Nine

@orbs  Well I understand what you are saying (I think).  I was at the very beginning to identify (recognize) the drives that were swap in and swap out. Once we know what drives are in, then they must be mounted with the correct letter drive.  I was thinking of SQLite to store the match between physical drives and  logical drives (maybe another overkill :lol:)...

 

Share this post


Link to post
Share on other sites
BrewManNH
On 1/20/2019 at 7:26 PM, cemster said:

Because I am really tired of reassigning 12 drives everytime I swap drives back and forth. There must be a way to prevent that... I am hoping..."

I think the easiest way to prevent it, as has been stated, is to stop swapping your drives around like they're lego blocks. You really need to find a better solution to whatever it is you're doing that "requires" you to swap drives like this. The best way would be to get rid of the 13 drives, and put what's on them on to a larger drive or 2, repartition them to give them the drive letters you want, and leave them inside the case where they belong. Or get a lot of external drive enclosures, and hook them up to the USB port(s) and leave them connected there.

What you're doing now is going to cause data loss at some time when you zap one or more of the drives with static as you remove them or put them back in, or you'll drop one causing physical damage, or any other scenario I haven't thought of as of yet that will eventually happen with this approach.


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

Share this post


Link to post
Share on other sites
orbs

nope. the volume serial number (8-digit hex), although is indeed sort of a volume ID - which can be used to identify a volume (except of a cloned one) - is not the "Device ID" handled by the aforementioned WinAPI functions and the mountvol utility.

the "Remarks" section for that function help is misleading:

The value returned is not the hardware serial number as found on the label of the drive

this part is correct. however,

it is the Windows Volume ID for the drive.

this part is not. the serial number for the volume has nothing to do with Windows, it is a piece of data written to the volume. and it is eligible for the title Volume ID as much as any other unique parameter of the volume. except, of course, when the volume is cloned, the serial number is cloned too - so forget about the "unique" thing.

Share this post


Link to post
Share on other sites
orbs

that, unfortunately, has been tested and found lacking. i was surprised to see such a pretentious statement, so i read the article bottom line, which reads...

While you can manually assign a permanent letter to drives you connect to your computer, the move won't stop Windows 10 from randomly assigning the same letter to another drive when the first drive is not plugged in.

so, although it might work in the more common scenario (one or two USB drives), it may prove insufficient when swapping a considerable amount of drives.

Share this post


Link to post
Share on other sites
ahha

OP - can we make the assumption that a single drive remains constant like c: , and is never removed?

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

×