Sign in to follow this  
Followers 0
NELyon

Labeling a Subst'd drive?

11 posts in this topic

I've been working on changing the label for a drive created through the Subst command, because DriveSetLabel wasn't working whatsoever. I _had_ a working solution, but something seems to be going screwy.

This is the code that worked:

_DriveSetLabel("S:\", "somelabel")
Func _DriveSetLabel($sDrive, $sLabel)
    If Not FileExists($sDrive) Then
        Return SetError(-1, -1, -1);Drive path does not exist
    EndIf
    $oShell = ObjCreate("Shell.Application")
    If Not IsObj($oShell) Then
        Return SetError(-2, -2, -2);Error initiating the Shell.Application object
    EndIf
    $oShell.NameSpace($sDrive).Self.Name = $sLabel
    Return 1
EndFunc

That worked fine until I tried testing it on my primary drive (C: in this case). It changed the label, but now the Subst drive's label cannot change on it's own. It immediately takes on whatever label C: has. If I change the label for C:, the Subst'd drive changes as well. If I run the code on the subst drive... it does nothing.

Is this normal or am I messing up somewhere along the line?

Share this post


Link to post
Share on other sites



I've been working on changing the label for a drive created through the Subst command, because DriveSetLabel wasn't working whatsoever. I _had_ a working solution, but something seems to be going screwy.

This is the code that worked:

_DriveSetLabel("S:\", "somelabel")
Func _DriveSetLabel($sDrive, $sLabel)
    If Not FileExists($sDrive) Then
        Return SetError(-1, -1, -1);Drive path does not exist
    EndIf
    $oShell = ObjCreate("Shell.Application")
    If Not IsObj($oShell) Then
        Return SetError(-2, -2, -2);Error initiating the Shell.Application object
    EndIf
    $oShell.NameSpace($sDrive).Self.Name = $sLabel
    Return 1
EndFunc

That worked fine until I tried testing it on my primary drive (C: in this case). It changed the label, but now the Subst drive's label cannot change on it's own. It immediately takes on whatever label C: has. If I change the label for C:, the Subst'd drive changes as well. If I run the code on the subst drive... it does nothing.

Is this normal or am I messing up somewhere along the line?

Sounds like a change in Windows' behavior vice AutoIt's. Any OS changes or big SP's applied recently?

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Sounds like a change in Windows' behavior vice AutoIt's. Any OS changes or big SP's applied recently?

:)

Nope. In fact, it worked for about ten minutes, and then I tried it on the C: drive, and all of a sudden all of my Subst. drives want to mimic the C: label.

EDIT: Wow, could I have phrased that worse?

Edited by KentonBomb

Share this post


Link to post
Share on other sites

Nope. In fact, it worked for about ten minutes, and then I tried it on the C: drive, and all of a sudden all of my Subst. drives want to mimic the C: label.

EDIT: Wow, could I have phrased that worse?

AFAIK subst drives inherit the label from the real drive they exsit on unless the parent drive has no label, and even then if you use the command prompt you will be told that the virtual drive has no label. If you rename the parent label then the subst drives will get the same label. If you see a different name on a subst drive than the parent drive then it will only last untill the window is refreshed in my experience. I have read that you can change a registry key to set the label but I haven't ever got it to work.

[extreme solution]

Have a virtual PC, copy the folder to it, network to it, share the folder, and map it as a network drive and then you can rename it.

[/exteme solution :D ]


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

[extreme solution]

Have a virtual PC, copy the folder to it, network to it, share the folder, and map it as a network drive and then you can rename it.

[/exteme solution :D ]

:)

That could be the case, but it leaves me wondering why it did work until I tried changing the C: drive label.

(And supposedly you can change the default label for a certain drive letter via the registry, but I found that the key everyone says to change... doesn't exist >_< )

EDIT: Google for "Labeling a subst drive" and this thread is the first result :idiot:

EDIT2: New discovery. The code I posted above does in fact create the registry entry HKLM/Software/Microsoft/Windows/CurrentVersion/Explorer/DriveIcons/(Letter)/DefaultLabel which is supposedly supposed to label the drive, but I have found that neither that code nor manually editing that entry have any effect on the drive label.

Edited by KentonBomb

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I've been looking for an answer to this myself and have found a "cheap" way of labeling a drive that was mapped using the SUBST command.

I will explain what the script does because I KNOW there has to be a MUCH more efficient way of achieving the same results so I hope someone will post a "cleaner" version of my code.

I discovered that when you map the drive a registry key is added to "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2". The problem is that it appears the name of the key is never the same twice. I have my script read all of the keys under "MountPoints2" and add them to an array. Then I have it map the drive using the SUBST command and then it creates a new array with a list of the new keys and then compares the two until it finds the new key. I then have it add the correct REG_SZ value to name the drive.

#include <Process.au3>
Dim $Before[50], $After[50]

$times = 0;Used to determine how many subkeys there are under the MountPoints2 key

; Take a "Before" snap shot of the subkeys to see what is there prior to mapping the drive
While 1
    $times = $times + 1
    $var = RegEnumKey("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2", $times)
    If @error <> 0 then ExitLoop
    $Before[$times] = $var
WEnd

; Map the drive and then pause for a second to wait for the system to catch up (it would'nt work without a pause)
_RunDOS("Subst Z: \\server\share"); Change the drive letter and path to suit your needs
Sleep(1000)

; Take a snapshot of subkeys AFTER the mapping 
For $i = 1 to $times
    $After[$i] = RegEnumKey("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2", $i)
Next

; Compare the two arrays line by line until it finds the first discrepency (which is the new key) and write the new label
For $i = 1 to $times
    If $Before[$i] <> $After[$i] Then
    RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\" & $After[$i], "_LabelFromReg", "REG_SZ", "My new label"); Change the "My new label" to suit your needs
    Exit
    EndIf
Next

I hope this helps out.

Edited by RamEliC

Share this post


Link to post
Share on other sites

use the following Registry Key:

"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\X\DefaultLabel\" were x is the drive letter.

You must use the Standard Value of the Key "DefaultLabel".

In vbs use:

WshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\X\DefaultLabel\", "Name of Subst", "REG_SZ"

Share this post


Link to post
Share on other sites

use the following Registry Key:

"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\X\DefaultLabel\" were x is the drive letter.

You must use the Standard Value of the Key "DefaultLabel".

In vbs use:

WshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\X\DefaultLabel\", "Name of Subst", "REG_SZ"

Welcome to the AutoIt forums Hxx :)

(A strange first post though giving VB code in an AutoIt forum.)

Do you know if that still works if you give the parent drive a label?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Hello martin,

thx for audience :-).

No, if you use this Registry Key and rename the original dirve, the renaming dominate my solution.

But may solution works too, if you subst more than ones to map directories to driveletters.

Additionally i must admit, that i don't know much more than AutoIt is an tool to automate user interaction. So i use the VB Code only for legend :-).

greetings

Edited by Hxx

Share this post


Link to post
Share on other sites

Hello martin,

thx for audience :-).

No, if you use this Registry Key and rename the original dirve, the renaming dominate my solution.

But may solution works too, if you subst more than ones to map directories to driveletters.

OK.

Additionally i must admit, that i don't know much more than AutoIt is an tool to automate user interaction. So i use the VB Code only for legend :-).

greetings

I think AutoIt is much more than a tool for user interaction, but then I suppose you could say that Windows is a tool for user interaction.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

i spent a few hours researching this, and i can't find anything useful that's default on windows (other tools can mount files as drives, like alcohol 120%, daemon tools, etc.) other than Net Use, but that has a side effect of not working when you don't have an internet connection (no, loopback doesn't count)

Net Use X: \\127.0.0.1\path
// or..
Net Use X: \\%computername%\path

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
Sign in to follow this  
Followers 0