Jump to content

Dos command: "subst"


Recommended Posts

Hey guys I have just discovered this dos command and I thought it would be cool to make a utility for it. What you do is you select a folder, pick a drive letter and set it. Now in my computer you have a drive that goes directly to that folder, cool huh.

Let me know what you think.

here is the syntax for "SUBST"

#include <GUIConstants.au3>
; == GUI generated with Koda ==
$Form1 = GUICreate("SUBST Command Utility", 258, 282, 192, 125)
$Group1 = GUICtrlCreateGroup("Set a Drive", 8, 8, 241, 105)
$Input1 = GUICtrlCreateInput("", 72, 24, 25, 21, "M2", $WS_EX_CLIENTEDGE)
GUICtrlSetLimit(-1,1) 
GUICtrlCreateLabel("Drive letter", 16, 27, 55, 17)
$Input2 = GUICtrlCreateInput("", 16, 56, 225, 21, -1, $WS_EX_CLIENTEDGE)
$Button1 = GUICtrlCreateButton("Browse", 184, 24, 57, 25)
GUICtrlCreateLabel("Set Drive to =>", 104, 27, 75, 17)
$Button2 = GUICtrlCreateButton("Set Now", 80, 80, 97, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Current Drives", 8, 128, 241, 145)
$List1 = GUICtrlCreateList("", 24, 144, 25, 123, -1, $WS_EX_CLIENTEDGE)
$Button3 = GUICtrlCreateButton("Delete Selected", 72, 152, 153, 33)
$Button4 = GUICtrlCreateButton("Delete All Subst Drives", 72, 192, 153, 33)
$Button5 = GUICtrlCreateButton("Refresh Drives", 72, 232, 153, 33)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
getdrives()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button1
        $dir = FileSelectFolder ( "Select Folder to SUBST to.", "", 4 , "C:" )
        If $dir <> "" Then GUICtrlSetData( $Input2, $dir )
    Case $msg = $Button2
        If StringIsAlpha ( GUICtrlRead($Input1) ) And FileExists ( GUICtrlRead($Input2) ) Then
            $command = "subst /d " & GUICtrlRead($Input1) & ": "
            Run(@ComSpec & " /c " & $command, "", @SW_HIDE)
            $command = "subst " & GUICtrlRead($Input1) & ": " & '"' & GUICtrlRead($Input2) & '"'
            Run(@ComSpec & " /c " & $command, "", @SW_HIDE)
            Sleep(500)
            getdrives()
            EndIf
        Case $msg = $Button3
            $command = "subst /d " & GUICtrlRead($List1)
            Run(@ComSpec & " /c " & $command, "", @SW_HIDE)
            Sleep(500)
            getdrives()
        Case $msg = $Button4
            ProgressOn( "SUBST Delete", "Deleting drives" )
            For $i = 97 To 122
            ProgressSet( (100/26)*($i-97), "Drive " & Chr($i) & " deleted" )
            getdrives()
            Sleep(50)
            $command = "subst /d " & Chr($i) & ":"
            Run(@ComSpec & " /c " & $command, "", @SW_HIDE)
            Next
            Sleep(500)
            getdrives()
            ProgressOff()
        Case $msg = $Button5
            getdrives()
    Case Else
        ;
    EndSelect
WEnd
Exit
Func getdrives()
;GUICtrlSetData ( $List1, "" )
$drives = DriveGetDrive ( "ALL" )
$drivelist = ""
For $i = 1 to $drives[0]
    $drivelist = $drivelist & "|" & $drives[$i]
Next
GUICtrlSetData ( $List1, $drivelist )
GUISetState(@SW_SHOW)
EndFunc
Edited by zerocool60544
Check out ConsultingJoe.com
Link to comment
Share on other sites

@zerocool60544, Nice work!

A couple of features I think would be nice.

1) Refresh button - to refresh the current drive list

2) Drive Name - Currently it comes up as "Local Drive S:" for example but would be nice to change it in your utility, example: "AutoIt-Source (S:)"

The refresh looks like an easy fix but I know other people have used the Subst but the name change was never done. Not sure how you would do it otherwise I would post it! :wacko:

cheers.. :D

Link to comment
Share on other sites

@zerocool60544, Nice work!

A couple of features I think would be nice.

1) Refresh button - to refresh the current drive list

2) Drive Name - Currently it comes up as "Local Drive S:" for example but would be nice to change it in your utility, example: "AutoIt-Source (S:)"

The refresh looks like an easy fix but I know other people have used the Subst but the name change was never done. Not sure how you would do it otherwise I would post it! :wacko:

cheers.. :D

Thanks guys

@busysignal

do you mean to display the drive name and/or be able to set/change it?

and I will add a refresh right now, thanks

Check out ConsultingJoe.com
Link to comment
Share on other sites

Thanks guys

@busysignal

do you mean to display the drive name and/or be able to set/change it?

and I will add a refresh right now, thanks

To be able to set/change it. :wacko:

Thanks.. I will DL the new ver to check out the refresh..

Cheers.. :D

Link to comment
Share on other sites

@zerocool60544, another suggestion. You should UPCASE the drive letter. It seems that I got an error pressing the SET buttion. I watched Windows Explorer add a drive but it had a Red Question mark on it then disappeared. After sustituting a Uppercase Letter the drive letter appeared. Yes, it could be a fluke but test it out on your side to see which one gets consistant results..

Cheers.. :D

Link to comment
Share on other sites

@zerocool60544, another suggestion. You should UPCASE the drive letter. It seems that I got an error pressing the SET buttion. I watched Windows Explorer add a drive but it had a Red Question mark on it then disappeared. After sustituting a Uppercase Letter the drive letter appeared. Yes, it could be a fluke but test it out on your side to see which one gets consistant results..

Cheers.. :D

It didnt seem to do that on my side but I will change that just because its neater
Check out ConsultingJoe.com
Link to comment
Share on other sites

This is very nice, I already had programs that could do this with encrypted files and .iso files, but this may well come in very handy for alot of people with folders they use alot. Good job!

Edited by marfdaman

Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Link to comment
Share on other sites

Thanks guys. I am working on the drive naming now, I will post the update

Ok, Problem, I try the DriveSetLabel command on a virtual drive and it doesn't work, I also tried DriveGetLabel and that still doesnt work.

It works just fine with a hardDrive though.

I can also set the virtual drive manually through my computer and it works?

Is this a autoit glitch or is virtual drives not supposed to have labels?

try it your self:

CODE
#include <GUIConstants.au3>

$Form1 = GUICreate("SUBST Command Utility", 258, 282, 192, 125)

$Group1 = GUICtrlCreateGroup("Set a Drive", 8, 8, 241, 105)

$Input1 = GUICtrlCreateInput("", 80, 24, 17, 21, -1, $WS_EX_CLIENTEDGE)

GUICtrlCreateLabel("Drive letter:", 16, 27, 58, 17)

$Input2 = GUICtrlCreateInput("", 16, 56, 225, 21, -1, $WS_EX_CLIENTEDGE)

$Button1 = GUICtrlCreateButton("Browse", 184, 24, 57, 25)

GUICtrlCreateLabel("Set Drive to =>", 104, 27, 75, 17)

$Button2 = GUICtrlCreateButton("Set Now", 80, 80, 97, 25)

GUICtrlCreateGroup("", -99, -99, 1, 1)

$Group2 = GUICtrlCreateGroup("Current Drives", 8, 128, 241, 145)

$List1 = GUICtrlCreateList("", 24, 144, 25, 123, -1, $WS_EX_CLIENTEDGE)

$Button3 = GUICtrlCreateButton("Delete Selected", 72, 192, 153, 25)

$Button4 = GUICtrlCreateButton("Delete All Subst Drives", 72, 216, 153, 25)

$Button5 = GUICtrlCreateButton("Refresh Drives", 72, 240, 153, 25)

$Input3 = GUICtrlCreateInput("", 72, 144, 153, 21, -1, $WS_EX_CLIENTEDGE)

$Button6 = GUICtrlCreateButton("Set Name", 72, 168, 153, 17)

GUICtrlCreateGroup("", -99, -99, 1, 1)

GUISetState(@SW_SHOW)

getdrives()

While 1

$msg = GuiGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $Button1

$dir = FileSelectFolder ( "Select Folder to SUBST to.", "", 4 , "C:" )

If $dir <> "" Then GUICtrlSetData( $Input2, $dir )

Case $msg = $Button2

If StringIsAlpha ( GUICtrlRead($Input1) ) And FileExists ( GUICtrlRead($Input2) ) Then

$command = "subst /d " & GUICtrlRead($Input1) & ": "

Run(@ComSpec & " /c " & $command, "", @SW_HIDE)

$command = "subst " & GUICtrlRead($Input1) & ": " & '"' & GUICtrlRead($Input2) & '"'

Run(@ComSpec & " /c " & $command, "", @SW_HIDE)

Sleep(500)

getdrives()

EndIf

Case $msg = $Button3

$command = "subst /d " & GUICtrlRead($List1)

Run(@ComSpec & " /c " & $command, "", @SW_HIDE)

Sleep(500)

getdrives()

Case $msg = $Button4

ProgressOn( "SUBST Delete", "Deleting drives" )

For $i = 97 To 122

ProgressSet( (100/26)*($i-97), "Drive " & Chr($i) & " deleted" )

getdrives()

Sleep(50)

$command = "subst /d " & Chr($i) & ":"

Run(@ComSpec & " /c " & $command, "", @SW_HIDE)

Next

Sleep(500)

getdrives()

ProgressOff()

Case $msg = $Button5

getdrives()

Case $msg = $List1

$drivename = DriveGetLabel ( GUICtrlRead($List1)&"\" )

GUICtrlSetData( $Input3, $drivename )

Case $msg = $Button6

DriveSetLabel ( GUICtrlRead($List1)&"\", GUICtrlRead( $Input3 ) )

Case Else

;

EndSelect

WEnd

Exit

Func getdrives()

;GUICtrlSetData ( $List1, "" )

$drives = DriveGetDrive ( "ALL" )

$drivelist = ""

For $i = 1 to $drives[0]

$drivelist = $drivelist & "|" & $drives[$i]

Next

GUICtrlSetData ( $List1, $drivelist )

GUISetState(@SW_SHOW)

EndFunc

Check out ConsultingJoe.com
Link to comment
Share on other sites

  • 7 years later...

#include <Constants.au3>
#Include <Array.au3>
#include <GUIConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>

dim $array2d
global $Timeout_win,$List1,$Time_win
subst_gui()
func subst_gui()
    $Form1 = GUICreate("SUBST Command Utility", 50+258, 110+282)
    $Group1 = GUICtrlCreateGroup("Set a Drive", 8, 8, 50+241, 105)
    $Input1 = GUICtrlCreateCombo ("", 80, 24, 57, 21, BitOR($ES_READONLY,$CBS_DROPDOWNLIST,$WS_VSCROLL))            
    For $i = 97 to 122  
        if DriveGetType(chr($i)&":")="" then  GUICtrlSetData( $Input1, chr($i)&":" )
    next
    GUICtrlCreateLabel("Drive letter:", 16, 27, 58, 17)
    $Input2 = GUICtrlCreateInput("", 16, 56, 225+45, 21,$ES_READONLY)
    $Button1 = GUICtrlCreateButton("Browse", 50+184, 24, 57, 25)
    GUICtrlCreateLabel("Set Drive to =>", 50+104, 27, 75, 17)
    $Button2 = GUICtrlCreateButton("Set Now", 80+10, 80, 97, 25)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Group2 = GUICtrlCreateGroup("Current Drives", 8, 128, 50+241, 100+145)
    $List1 = GuiCtrlCreateListView("Drive|Path", 24, 144, 232+25, 123, -1)
    subst_create()
    $Button3 = GUICtrlCreateButton("Delete Selected", 45+24, 80+192, 153, 25)
    $Button4 = GUICtrlCreateButton("Delete All Subst Drives", 45+24, 80+216, 153, 25)
    $Button5 = GUICtrlCreateButton("Refresh Drives", 45+24,80+ 240, 153, 25)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    GUISetState(@SW_SHOW)
    While 1
        $msg = GuiGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit
            Case $msg = $Button1
                $dir = FileSelectFolder ( "Select Folder to SUBST to.", "", 4 , "" )
                If FileExists($dir)=1 Then GUICtrlSetData( $Input2, $dir )
            Case $msg = $Button2
                $Input1a=GUICtrlRead($Input1)
                $Input2a=GUICtrlRead($Input2)
                If $Input1a<>"" and FileExists($Input2a)=1 Then
                    $command = "subst " & $Input1a & ' "' & $Input2a & '"'
                    dim $foo = Run(@ComSpec & " /c " & $command, "", @SW_HIDE,$STDOUT_CHILD)
                    dim $line,$line1
                    While 1
                        $line = StdoutRead($foo)
                        If @error Then ExitLoop
                        $line1 &=$line
                    Wend
                    if $line1="" Then
                        $Timeout_win = 0
                        $Time_win = TimerInit()
                        AdlibRegister("_TimeCheck", 100)
                        while 1
                            If $Timeout_win Then ExitLoop
                            if DriveGetType($Input1a)<>"" then exitloop
                        wend                            
                        guidelete($Form1)
                        subst_gui()
                    else    
                        msgbox(48,"Warning !",$line1)
                    endif
                Else
                    msgbox(48,"Warning !","Some fields are empty")
                EndIf
            Case $msg = $Button3
                $split_tk_01 = StringSplit( GUICtrlRead(GUICtrlRead($List1)), "|",2 )
                if not @error then
                    $command = "subst /d " & $split_tk_01[0]
                    Run(@ComSpec & " /c " & $command, "", @SW_HIDE)                 
                    $Timeout_win = 0
                    $Time_win = TimerInit()
                    AdlibRegister("_TimeCheck", 100)
                    while 1
                        If $Timeout_win Then ExitLoop
                        if DriveGetType($split_tk_01[0])="" then exitloop
                    wend                    
                    guidelete($Form1)
                    subst_gui()
                endif
            Case $msg = $Button4
                if IsArray($array2d) then
                    ProgressOn( "SUBST Delete", "Deleting drives" )
                    for $i=0 to ubound($array2d)-1
                        ProgressSet( $i*100/ubound($array2d)-1, "Drive " & $array2d[$i][0] & " deleted" )
                        $command = "subst /d " & $array2d[$i][0]
                        Run(@ComSpec & " /c " & $command, "", @SW_HIDE)
                    Next
                    ProgressOff()
                    $Timeout_win = 0
                    $Time_win = TimerInit()
                    AdlibRegister("_TimeCheck", 100)
                    dim $i = 0, $a=0
                    Do
                        If $Timeout_win Then ExitLoop
                        if $array2d[$i][0]<>0 then
                            if DriveGetType($array2d[$i][0])="" then $array2d[$i][0]=0
                            $i = $i + 1
                            if $i=ubound($array2d) then $i=0
                        else
                            $a= $a+1
                            if $a=ubound($array2d) then exitloop
                        endif
                    Until $i <0
                    guidelete($Form1)
                    subst_gui()             
                endif               
            Case $msg = $Button5
                    guidelete($Form1)
                    subst_gui()             
            Case $msg = $List1
                $drivename = DriveGetLabel ( GUICtrlRead($List1)&"\" )
                GUICtrlSetData( $Input3, $drivename )
        EndSelect
    WEnd
endfunc

func subst_create() 
    dim $foo = Run(@ComSpec & " /c " &'subst',"", @SW_HIDE, $STDOUT_CHILD)
    dim $line,$line1
    While 1
        $line = StdoutRead($foo)
        If @error Then ExitLoop
        $line1 &=$line
    Wend
    if $line1<>"" then
        $line1=StringStripCR($line1)
        $array = StringSplit($line1,@crlf,2)
        if not @error then
            _ArrayDelete($array, ubound($array)-1)
            dim $array2d[ubound($array)][2]
            for $i=0 to ubound($array)-1
                $array2d[$i][0]=stringleft($array[$i],2)
                $array2d[$i][1]=stringtrimleft($array[$i],8)
            next
            if IsArray($array2d) then
                for $i=0 to ubound($array2d)-1
                    GuiCtrlCreateListViewItem($array2d[$i][0]&"|"&$array2d[$i][1],$List1)
                next
            endif
        endif
    endif
endfunc

Func _TimeCheck()
    If TimerDiff($Time_win) > 5 * 1000 then
        $Timeout_win = 1
        AdlibUnRegister()
    EndIf
EndFunc

To community goes all my regards and thanks

Link to comment
Share on other sites

Congrats for nominating yourself to the >Zombie Thread Award competition!

Seriously?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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...