Sign in to follow this  
Followers 0
LeeSylvester

Virtual-Drive

36 posts in this topic

Hey guys,

I've just started with AutoIt, really, having discovered it a couple of weeks ago. Two days ago, I started a project whose source files needed to sit in a path that was located on a drive P: rather than where I normally keep my project files (nested deep in my "My Documents" directory). So, I went on a hunt to find a decent Virtual Drive application. I ended up finding two. Both were buggy and required fee's to make the drives remain following a reboot. Thus I decided to use AutoIt to write my own tool

It took just four hours to make

You guys, being the users of such a cool product, can download this tool (no fees like those cheap @$?%) from here. It supports adding and removing virtual drives and persists after a reboot. Just as it should!!!

Regards,

Lee

Share this post


Link to post
Share on other sites



I'm not going to run any app a n00bie posts unless the source is included.


Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Share this post


Link to post
Share on other sites

I'm not going to run any app a n00bie posts unless the source is included.

lol... Yeah, I hadn't thought of that. Okay, I can't see why not. This will at least set me up for the bigger projects which I might not want to submit source for :)

Lee

#include <Constants.au3>
#include <GUIConstants.au3>
#Include <GuiListView.au3>
#include <Array.au3>
#Include <GuiCombo.au3>
#include <File.au3>

TraySetToolTip( "DesignRealm Virtual-Drive" )
Opt( "TrayIconHide", 1 )
Opt("OnExitFunc", "OnClose")

Dim $win_width = 420
Dim $win_height = 250
Dim $btn_top_height = 30
Dim $btn_top_width = 100
Dim $btn_bottom_height = 30
Dim $btn_bottom_width = 100
Dim $btn_file_height = 20
Dim $btn_file_width = 20
Dim $txt_file_height = 20
Dim $txt_file_width = 220
Dim $cbs_drive_height = 20
Dim $cbs_drive_width = 50

Dim $spacer = 5

Dim $diag = GUICreate( "DesignRealm Virtual-Drive", $win_width, $win_height, -1, -1, BitOR( $WS_POPUPWINDOW, $WS_CAPTION ), BitOR( $WS_EX_ACCEPTFILES, $WS_EX_TOOLWINDOW ) )
Dim $listview = GUICtrlCreateListView ( "Select | Drive | Path", $spacer, ( $spacer*2 ) + $btn_top_height, $win_width - ( $spacer*2 ), $win_height - ( ( ( $spacer*2 ) + $btn_top_height ) + ( ( $spacer*2 ) + $btn_bottom_height ) ), BitOR( $LVS_SINGLESEL, $LVS_SORTDESCENDING ), BitOR( $LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_FLATSB ) )
_GUICtrlListViewSetColumnWidth ( $listview, 0, 50 )
_GUICtrlListViewSetColumnWidth ( $listview, 1, 50 )
_GUICtrlListViewSetColumnWidth ( $listview, 2, ( $win_width - ( $spacer*2 ) ) - 105 )
Dim $refresh_btn = GUICtrlCreateButton ( "Refresh", $win_width - ( $btn_bottom_width + $spacer ), $win_height - ( $btn_bottom_height + $spacer ), $btn_bottom_width, $btn_bottom_height )
Dim $create_btn = GUICtrlCreateButton ( "Create New", $spacer, $win_height - ( $btn_bottom_height + $spacer ), $btn_bottom_width, $btn_bottom_height )
Dim $delete_btn = GUICtrlCreateButton ( "Delete Selected", $btn_bottom_width + ( $spacer*2 ), $win_height - ( $btn_bottom_height + $spacer ), $btn_bottom_width, $btn_bottom_height )
Dim $fileopen = GUICtrlCreateButton ( "...", $win_width - ( $btn_file_width + $spacer ), $spacer + ( $btn_top_height - $btn_file_height ), $btn_file_width, $btn_file_height )
Dim $filetxt = GUICtrlCreateInput( "", $win_width - ( $btn_file_width + ( $spacer*2 ) + $txt_file_width ), $spacer + ( $btn_top_height - $txt_file_height ), $txt_file_width, $txt_file_height, $ES_READONLY )
Dim $driveletters = GUICtrlCreateCombo ( "", $win_width - ( $btn_file_width + ( $spacer*3 ) + $txt_file_width + $cbs_drive_width ), $spacer + ( $btn_top_height - $cbs_drive_height ), $cbs_drive_width, $cbs_drive_height, $CBS_DROPDOWNLIST )
GUISetState ( @SW_SHOW )

Func AddDriveToList( $driveStr )
    Dim $array = StringSplit( $driveStr, '\: => ', 1 )
    If $array[0] > 1 Then $item = GUICtrlCreateListViewItem( "|" & $array[1] & "|" & $array[2], $listview )
EndFunc
    
Func AddDrive()
    If GUICtrlRead( $filetxt ) <> "" Then
        RunWait( @ComSpec & " /c subst " & GUICtrlRead( $driveletters ) & ': "' & GUICtrlRead( $filetxt ) & '"', @SystemDir, @SW_HIDE )
    EndIf
    GUICtrlSetData( $filetxt, "" )
    GetDriveLetters()
    GetDrives()
EndFunc

Func GetIndices()
    Dim $array[1]
    Dim $n
    For $n = 0 to _GUICtrlListViewGetItemCount( $listview ) -1
        If _GUICtrlListViewGetCheckedState( $listview, $n ) Then
            _ArrayAdd( $array, $n )
        EndIf
    Next
    Return $array
EndFunc

Func GetDrives()
    ClearDrives()
    Dim $foo = Run( @ComSpec & " /c subst", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD )
    Dim $drive = ""
    Dim $line = ""
    While 1
        $line = $line & StdoutRead( $foo )
        If @error Then ExitLoop
    Wend
    Dim $array = StringSplit( $line, Chr(10) & Chr(13) )
    For $drive = 1 To $array[0]
        If StringInStr( $array[$drive], ':\:' ) Then AddDriveToList( $array[$drive] )
    Next
EndFunc

Func ClearDrives()
    _GUICtrlListViewDeleteAllItems( $listview )
EndFunc

Func GetDriveLetters()
    ClearDriveLetters()
    Dim $taken = DriveGetDrive( "ALL" )
    Dim $all = StringSplit( "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "" )
    Dim $top = ""
    Dim $i
    For $i = 1 To $all[0]
        If _ArraySearch( $taken, $all[$i] & ":" ) = -1 Then
            If $top = "" Then $top = $all[$i]
            GUICtrlSetData( $driveletters, $all[$i], $top )
        EndIf
    Next
EndFunc

Func ClearDriveLetters()
    _GUICtrlComboResetContent ( $driveletters )
EndFunc

Func RemoveDrives()
    Dim $col, $n
    For $n = 0 to _GUICtrlListViewGetItemCount( $listview ) -1
        If _GUICtrlListViewGetCheckedState( $listview, $n ) Then
            $col = _GUICtrlListViewGetItemText ( $listview, $n, 1 )
            RunWait( @ComSpec & " /c subst " & $col & " /d", @SystemDir, @SW_HIDE )
        EndIf
    Next
    _GUICtrlListViewDeleteAllItems( $listview )
    GetDrives()
    GetDriveLetters()
EndFunc

Func OnClose()
    Dim $path = @SystemDir & "\" & "vdstor.bat"
    If Not FileExists( $path ) Then
        If Not _FileCreate( $path ) Then
            MsgBox( 4096, "Error", "Error setting drives to permenant. You may need to reassign the drives when you next reboot." )
            RegDelete( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "VDStor" )
            Return -1
        EndIf
    EndIf
    Dim $file = FileOpen( $path, 2 )
    If $file = -1 Then
        MsgBox( 4096, "Error", "Error setting drives to permenant. You may need to reassign the drives when you next reboot." )
        RegDelete( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "VDStor" )
        Return -1
    EndIf
    Dim $foo = Run( @ComSpec & " /c subst", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD )
    Dim $drive = ""
    Dim $line = ""
    While 1
        $line = $line & StdoutRead( $foo )
        If @error Then ExitLoop
    Wend
    Dim $array = StringSplit( $line, @CRLF )
    FileWriteLine( $file, "@ECHO OFF" )
    For $drive = 1 To $array[0]
        If StringInStr( $array[$drive], ':\:' ) Then
            Dim $farray = StringSplit( $array[$drive], '\: => ', 1 )
            If $farray[0] > 1 Then FileWriteLine( $file, "@subst " & $farray[1] & ' "' & $farray[2] & '"' )
        EndIf
    Next
    RegWrite( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "VDStor", "REG_SZ", @SystemDir & "\" & "vdstor.bat" )
EndFunc

GetDrives()
GetDriveLetters()

While 1
    Dim $msg = GUIGetMsg()
    
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $refresh_btn
            GetDrives()
        Case $delete_btn
            If MsgBox( 4, "Confirm...", "Are you sure you wish to delete the selected drives?" ) = 6 Then
                RemoveDrives()
            EndIf
        Case $fileopen
            GUICtrlSetData( $filetxt, StringStripCR( StringStripWS( FileSelectFolder( "Select a Path...", "" ), 3 ) ) )
        Case $create_btn
            AddDrive()
    EndSwitch
Wend

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Okay, I can't see why not.

Sorry if it sounded like I was doubting you intent, but script kiddies like to pack harmful stuff into exe's and post them.

As for virtual drives, I've used Daemon Tools for many years without any problems and there is a free version.

Edited by Fossil Rock

Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Share this post


Link to post
Share on other sites

Yes, but Daemon Tools is for Virtual CDROM drives. This tool creates virtual drives from directories on your hard drive. Therefore, instead of

C:\Documents and Settings\My Ridiculously long name\My Documents\Development\Some Company\Project 5\Website\source media\

You can have

W:\

That's quite a difference :)

Lee

Share this post


Link to post
Share on other sites

Nice one thanks ....


"Our deepest fear is not that we are inadequate.Our deepest fear is that we are powerful beyond measure.It is our light, not our darkness that most frightens us."

Share this post


Link to post
Share on other sites

Yes, but Daemon Tools is for Virtual CDROM drives. This tool creates virtual drives from directories on your hard drive. Therefore, instead of

C:\Documents and Settings\My Ridiculously long name\My Documents\Development\Some Company\Project 5\Website\source media\

You can have

W:\

That's quite a difference :)

Lee

Ah, my bad ...

Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Share this post


Link to post
Share on other sites

Ok, that is way cool! :) If this is from a noobie, can't wait to see what ya come up with in a couple more weeks.. LOL

Share this post


Link to post
Share on other sites

Ok, that is way cool! ;) If this is from a noobie, can't wait to see what ya come up with in a couple more weeks.. LOL

Thank you :) I've actually been playing with the idea of creating a PowerTools style app for XP users. Currently, I'm playing with a wizard idea for adding options to Windows Explorers context menus. I dunno. I guess I need to think hard about what Windows really needs.

Lee

Share this post


Link to post
Share on other sites

sounds great! Looking forward to seeing the results.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Wow man! Great work! <_<

I'm so gonna use this!

Just one thing... how do I make it so I can set a label to the new drive? :">

Edited by Nahuel

Share this post


Link to post
Share on other sites

It's a very nice program, which I'm using right now <_<

I made just a small change:

- Program is always in Tray Icon accesable, so I can use the right-mouse button and the program starts again.

And I noticed that the 'Virtual Drive' which is created is a Copy of your C: drive.

When you change the name of your C: drive, the name of your virtual drive will change in that one to.

I don't know if it is possible to assign it an own name, because it's not a fysical drive.

But, keep up the good work.

Neo


[center][font="Arial"]--- The Neo and Only --- [/font][font="Arial"]--Projects---[/font]Image to Text converterText to ASCII converter[/center]

Share this post


Link to post
Share on other sites

very handy util, thx for the code - nice work

Share this post


Link to post
Share on other sites

Clever, a frontend to subst. Can't complain.

:P<_<:):) eh eh eh... old wolf...

Share this post


Link to post
Share on other sites

lot of work for subst and subst /d.....


Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

Hi,

something off topic: subst soes not work quite ggod on NT based systems. Even ntsubst, which is reported to be a clone working better on NT systems, shows things like:

- Network shares connected as drives overwrite drives created by xxsubst

- removable media like memory card slots overwrite xxsubst drives

Does anybody know a well supported way to create virtual drives on NT systems?

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