 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
raphael Guest
|
Posted: Wed Nov 29, 2006 11:50 pm Post subject: Drive letter setting |
|
|
I have a removable disk used on several machines where it will get different drive letters. I would like to set a fix driveletter X: with an autoscript.
subst will not do the trick. what will?
SplitPath,A_WorkingDir, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
if(Outdrive <> "X:"){
run subst X: Outdrive
} |
|
| Back to top |
|
 |
n-l-i-d Guest
|
Posted: Wed Nov 29, 2006 11:55 pm Post subject: |
|
|
| Use DriveGet to retreive the current drive letter of your removable. Then you can use subst to remap it. |
|
| Back to top |
|
 |
raphael Guest
|
Posted: Thu Nov 30, 2006 11:02 am Post subject: |
|
|
| I said that subst *doesn't work*, I think I have to go through the API. |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Thu Nov 30, 2006 11:09 am Post subject: |
|
|
Did you tried Run %comspec% /c subst X: %Outdrive%?
It is necessary if subst is a built-in command like type (can't remember if that's an exe or com, or a command).
Anyway, your first code won't work because you didn't enclosed Outdrive between percentage signs. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
raphael
Joined: 30 Nov 2006 Posts: 5
|
Posted: Thu Nov 30, 2006 7:21 pm Post subject: |
|
|
Yes your right about that and in the context of the script this will work, but I want also the windows system to see the drive. What I'm actually looking for is reassigning the drive letter like I would trough the configuration panel.
As a work around I could use fsutil to create a hardlink but I resent that because IMHO this is a to big infringement on the running system and it only does NTFS. _________________ If (Live = OK){
enjoy} |
|
| Back to top |
|
 |
Terrapin
Joined: 15 Aug 2005 Posts: 107 Location: North Carolina
|
Posted: Thu Nov 30, 2006 9:33 pm Post subject: |
|
|
It sounds like you just want the drive letter to be the same on different machines. This does not involve AHK. You would go into Control Panel > Administrative Tools > Computer Management > Storage, to set the drive letter for this drive, on each computer. That is assuming none of them are less than W2K. Next time you plug in the drive on any of those machines, it will 'remember' the drive letter for it.
Good Luck |
|
| Back to top |
|
 |
Paulo not logged Guest
|
|
| Back to top |
|
 |
Tuncay
Joined: 07 Nov 2006 Posts: 384 Location: Berlin
|
Posted: Thu Nov 30, 2006 11:05 pm Post subject: |
|
|
I have written yesterday a function Mount() using subst.exe, because I am very often at internet cafes with my USB-Stick (AutoHotkey helped me so much thx Chris and all others here). First I wanted a tool to mount any directory into any other directory, but this is with subst not possible. sorry, now I am in an internet cafe, may be tomorrow I can show u it, but I wanted add some more functionalities.
Here the definition, (currently):
| Code: | Mount(SourceDirectory [, MountDrive, Options])
UnMount([MountPath])
IsMount(Path) |
Mount() does not need any more explanation, but if MountDrive is not given, it searches for first free drive letter. UnMount() unmounts the given drive created with subst.exe. Without any argument, all subst.exe mounted drives will be unplugged. IsMount() returns the real full path of an subst.exe mounted file path.
Do someone need it? May be in the next days, I'll post it here.
EDIT: Below I posted the code, now it is not the same described here.
Last edited by Tuncay on Fri Dec 01, 2006 7:46 pm; edited 1 time in total |
|
| Back to top |
|
 |
raphael
Joined: 30 Nov 2006 Posts: 5
|
Posted: Fri Dec 01, 2006 11:20 am Post subject: |
|
|
I doubt this can be solved with subst as it is a shell command and will probably not go beyond the current shell. One more time for everyone who didn't understand my gibberish:
I have a removable drive.
It's mounted on a great number of unknown window systems.
When I hook up the device it will autorun AHK.
On first run I want AHK to assign a drive letter of my choice (X) to the drive.
After assignment I should be able to access the drive from windows by this drive letter.
I know I can change this from the control panel but I want to have it done
auto magically. If this is possible AHK would be my number one tool on
my portable drive, and in combination with PHP CLI I got an unbeatable
duo that beats PHP-GTK in easy of use.
I'm sure it can be done but I'm now 1 week on AHK and still learning to find my way arround. But I am very, very, impressed by it. _________________ If (Live = OK){
enjoy} |
|
| Back to top |
|
 |
Tuncay
Joined: 07 Nov 2006 Posts: 384 Location: Berlin
|
Posted: Fri Dec 01, 2006 7:44 pm Post subject: |
|
|
Try this, its not full tested, but may be it does what you mean. I am also a portable user.
The main file: mount.lib.ahk | Code: | /*
Mount
Revision: 0.1
Status: EXPERIMENTAL BETA
Date: Fri, 1 December 2006 11:09:02 GMT
Author: Tuncay <tuncay.d@gmx.net>
License: GNU GPL, Version 2
Type: Library
Standalone: Yes
Polymorph: No
Tested AHK Version: 1.0.46
Tested WIN Version: XP Pro SP2
Please send any bug report to tuncay.d@gmx.net.
Public Functions: (Any parameter enclosed in '[' and ']' are optional.)
Mount([SourcePath], [Mountpoint], [Options])
Returns on success mounted drive with ending backslash and on failure
a string without content.
If Mountpoint is not given, then it looks for first free drive otherwise
existing SourcePath will be mounted to given Mountpoint. If SourcePath
is not given, it defaults to WorkingDir.
Currently there is only one option used to unmount the drive.
UnMount([Mountpoint], [Options])
Like Mount(), but without the need of SourcePath. Also the unmount
option is here given over to Mount() always.
GetMount([Path])
If the specified Path is a drive, the full real path is returned. If
the Path is not given, first virtual drive will be get.
*/
#NoEnv
SendMode Input
#NoTrayIcon
/*
Public Function Mount
Mounts with subst.exe any path to a Windows drive.
2006 by Tuncay
*/
Mount(SourcePath = "", Mountpoint = "", Options = "")
{
GoSub, SetOptions@Mount
GoSub, SetMountPath@Mount
If Option?UnMount
Command = subst %MountPath% /d
Else
{
If (SourcePath = "")
SourcePath := A_WorkingDir
Command = subst %MountPath% "%SourcePath%"
}
If (NOT Option?UnMount AND NOT FileExist(MountPath . "\") AND FileExist(SourcePath))
OR (Option?UnMount AND FileExist(MountPath . "\"))
{
RunWait, "%comspec%" /c %Command%,, Hide UseErrorLevel
Sleep, 200
If ErrorLevel = "ERROR"
{
MountPath := ""
ErrorLevel := 2 ; Failed to launch subst.exe
}
Else
{
MountPath := MountPath . "\"
ErrorLevel := 0
}
}
Else
{
MountPath := ""
ErrorLevel := 1
}
Return MountPath
SetMountPath@Mount:
If (Mountpoint = "") ; Search drive.
{
DriveGet, ActualDrives, List
If NOT Option?UnMount ; Get first free drive.
{
FreeDriveLetters := "CDEFGHIJKLMNOPQRSTUVWXYZ"
Loop, Parse, ActualDrives
StringReplace, FreeDriveLetters, FreeDriveLetters, %A_LoopField%
Loop, Parse, FreeDriveLetters
{
MountPath := A_LoopField . ":"
Break
}
}
Else If Option?UnMount ; Get first subst.exe mounted drive.
{
Loop, Parse, ActualDrives
{
If GetMount(A_LoopField . ":")
{
MountPath := A_LoopField . ":"
Break
}
}
}
}
Else If Mountpoint Is Alpha ; Add double colon on drive letter.
MountPath := Mountpoint . ":"
Else If Mountpoint ; Drive will be extracted from any path.
SplitPath, MountPath,,,,, Mountpoint
Return
SetOptions@Mount:
; Default settings
Option?UnMount := False
CurrentStringCaseSense := A_StringCaseSense
StringCaseSense On
If Options Contains --
{
StringReplace, Options, Options,--unmount,-u
}
StringReplace, Options, Options,/,-, All
; Overwriting default settings.
OptionsFoundList := "" ; For performance, not to loop if already founded
; and avoid dublicates.
Loop, Parse, Options,-,%A_SPACE%
{
If A_LoopField In ,%A_SPACE%
Continue
; Inner Loop for enabling the short style for grouping of options.
Loop, Parse, A_LoopField
{
IfInString, OptionsFoundList, %A_LoopField%
Continue
; Option?UnMount
; 0=creates a virtual drive from given path (default)
; 1=deletes the given virtual drive mounted by subst.exe
If InStr(A_LoopField, "u", 1)
{
Option?UnMount := True
OptionsFoundList := OptionsFoundList . A_LoopField
Continue
}
}
}
StringCaseSense %CurrentStringCaseSense%
Return
}
/*
Public Function UnMount
UnMounts a virtual drive mapped with subst.exe.
2006 by Tuncay
*/
UnMount(Mountpoint = "", Options = "")
{
Return Mount("", Mountpoint, "-u " . Options)
}
/*
Public Function GetMount
Converts virtual path mapped with subst.exe to real physical full path.
2006 by Tuncay
*/
GetMount(pPath = "")
{
Path := pPath
If (Path = "") ; Search first mounted drive. (very slow!)
{
DriveGet, ActualDrives, List
Loop, Parse, ActualDrives
{
;! Recursive call for every existing drive.
If GetMount(A_LoopField . ":")
{
MountPath := A_LoopField . ":"
Break
}
}
}
Else
{
If Path Is Alpha ; Add double colon on drive letter.
Path := Path . ":"
Else
SplitPath, Path,,,,, Path
If FileExist(Path . "\")
{
TempFile = %A_Temp%\{D74BA6E8-2728-4FC6-8185-623EA7DAD412}_%A_Now%.~tmp
Command = subst >"%TempFile%"
RunWait, "%comspec%" /c %Command%,, Hide UseErrorLevel
Sleep, 200
If ErrorLevel = "ERROR"
ErrorLevel := 2 ; Failed to launch subst.exe
Else
{
ErrorLevel := 0
Loop, Read, %TempFile%
{
StringMid, MountDrive, A_LoopReadLine, 1, 2
If (Path = MountDrive)
{
StringMid, MountPath, A_LoopReadLine, 9
Break
}
}
Sleep, 200
FileDelete, %TempFile%
MountPath := MountPath . SubStr(pPath, 3)
}
}
Else
{
MountPath := ""
ErrorLevel := 1
}
}
Return MountPath
} |
Example: Mount
| Code: | #Include Mount.lib.ahk
FileSelectFolder, SourcePath
Mount(SourcePath, "x") |
Example: UnMount
| Code: | #Include Mount.lib.ahk
UnMount() |
Feel free to modify, but please comment it. I have not made any gui or something, because for an automation script this is not needed. |
|
| Back to top |
|
 |
Tuncay
Joined: 07 Nov 2006 Posts: 384 Location: Berlin
|
|
| Back to top |
|
 |
malexs Guest
|
Posted: Sun Mar 11, 2007 1:22 am Post subject: alternative method.. |
|
|
There is another way to remember external drive location of specific external drives.
1. Basically you create a folder on your local hard drive, eg. "external_HDD1"
2. Then Right click my computer and select manage
3. Select disk management (under storage)
4. Right click your external drive and select "change drive letter and paths"
5. Click ADD
6. Browse to your folder your created in step one . i.e. c:\external_HDD1
7. click ok and you are done.
Then whenever you insert your external drive or usb drive into your pc, you will always be able to access it in the same place, c:\external_HDD1, regardless of what drive letter windows decides to assign to it.
Apart of retaining the same path to your drive, the other main benefit of this method is that it will remember any folders you set up as sharing on the drive. If you share a folder on an external drive in windows, when you restart your pc or unplug your drive, you loose your share and have to re-set it up. To share a folder, simply go to c:\external_HDD1\folder_to_share and set it to be shared and whenever you plug the drive into the computer that folder will be shared on the network. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|