drive letter 
Author Message
 drive letter

Hello all,

I am mapping a driver using the following

Shell.Run "net use /user:domain\username * \\remotemachine\share password"

I however need to delete the mapped driver after I am done with it but I can
not figure out how to get the drive letter it uses.

My question is Is there a way to get the drive letter (maybe the Drives
collection????) so I can use a "net use %driverletter% /d"

any help is much appreciated



Sun, 11 Jul 2004 02:47:40 GMT  
 drive letter
Set Network = wscript.createobject("wscript.network")
CreateShare "\\WAYSIDE\unix"
DisconnectShare

Function CreateShare(ShareName)
 Network.mapnetworkdrive "Z:", ShareName
 CreateShare = "Done"
End Function
'---------------------------------------------------------------------------
---------
Function DisconnectShare()
On Error Resume Next
  Network.removenetworkdrive "Z:"
End Function

Bryan Martin


Quote:
> Hello all,

> I am mapping a driver using the following

> Shell.Run "net use /user:domain\username * \\remotemachine\share password"

> I however need to delete the mapped driver after I am done with it but I
can
> not figure out how to get the drive letter it uses.

> My question is Is there a way to get the drive letter (maybe the Drives
> collection????) so I can use a "net use %driverletter% /d"

> any help is much appreciated



Sun, 11 Jul 2004 03:11:20 GMT  
 drive letter
Hi

If Bryan Martin's solution with a hardcoded drive letter (Z:) is not an option,
but you want to have the drive letter dynamicly assigned (using "net use"), you
can at delete time enumerate through all "networked" drive letters and find the
one that is mapped to \\remotemachine\share. Then you can use
Network.RemoveNetworkDrive <drive_letter_found> or "net use <drive_letter_found>
/d"

Alternativly, to dynamicly assigned drive letters using Network.MapNetworkDrive,
you can enumerate existing drive letters and let your script find the next free
one to use. You will then know which one to delete later.

--
torgeir

Quote:

> Hello all,

> I am mapping a driver using the following

> Shell.Run "net use /user:domain\username * \\remotemachine\share password"

> I however need to delete the mapped driver after I am done with it but I can
> not figure out how to get the drive letter it uses.

> My question is Is there a way to get the drive letter (maybe the Drives
> collection????) so I can use a "net use %driverletter% /d"

> any help is much appreciated



Sun, 11 Jul 2004 04:36:46 GMT  
 drive letter
sDriveLetter = FreeDrive()
MsgBox sDriveLetter

Function FreeDrive
  Dim I, oFso
  Set oFso = CreateObject("Scripting.FileSystemObject")
  For I = Asc("F") to Asc("U")
    If Not oFso.DriveExists(Chr(I)) Then
      Freedrive = Chr(I) & ":"
      Exit Function
    End If
  Next
End Function

--
Michael Harris
Microsoft.MVP.Scripting
--

Quote:

> Hi

> If Bryan Martin's solution with a hardcoded drive letter (Z:) is not an option,
> but you want to have the drive letter dynamicly assigned (using "net use"), you
> can at delete time enumerate through all "networked" drive letters and find the
> one that is mapped to \\remotemachine\share. Then you can use
> Network.RemoveNetworkDrive <drive_letter_found> or "net use <drive_letter_found>
> /d"

> Alternativly, to dynamicly assigned drive letters using Network.MapNetworkDrive,
> you can enumerate existing drive letters and let your script find the next free
> one to use. You will then know which one to delete later.

> --
> torgeir


> > Hello all,

> > I am mapping a driver using the following

> > Shell.Run "net use /user:domain\username * \\remotemachine\share password"

> > I however need to delete the mapped driver after I am done with it but I can
> > not figure out how to get the drive letter it uses.

> > My question is Is there a way to get the drive letter (maybe the Drives
> > collection????) so I can use a "net use %driverletter% /d"

> > any help is much appreciated



Sun, 11 Jul 2004 11:14:58 GMT  
 drive letter
Hi

Exactly what I had in mind but was to lazy to code ;-)

Any particular reason you start on drive F? I guess D would be the first one to test (but I see you stop
on U and not Z, so I guess you just took a "casual" selection).

--
torgeir

Quote:

> sDriveLetter = FreeDrive()
> MsgBox sDriveLetter

> Function FreeDrive
>   Dim I, oFso
>   Set oFso = CreateObject("Scripting.FileSystemObject")
>   For I = Asc("F") to Asc("U")
>     If Not oFso.DriveExists(Chr(I)) Then
>       Freedrive = Chr(I) & ":"
>       Exit Function
>     End If
>   Next
> End Function

> --
> Michael Harris
> Microsoft.MVP.Scripting
> --



Sun, 11 Jul 2004 11:35:17 GMT  
 drive letter
You could also examine the result of the use statement, it returns the drive
letter used, using stdout.
Joe


sDriveLetter = FreeDrive()
MsgBox sDriveLetter

Function FreeDrive
  Dim I, oFso
  Set oFso = CreateObject("Scripting.FileSystemObject")
  For I = Asc("F") to Asc("U")
    If Not oFso.DriveExists(Chr(I)) Then
      Freedrive = Chr(I) & ":"
      Exit Function
    End If
  Next
End Function

--
Michael Harris
Microsoft.MVP.Scripting
--

Quote:
> Hi

> If Bryan Martin's solution with a hardcoded drive letter (Z:) is not an
option,
> but you want to have the drive letter dynamicly assigned (using "net
use"), you
> can at delete time enumerate through all "networked" drive letters and
find the
> one that is mapped to \\remotemachine\share. Then you can use
> Network.RemoveNetworkDrive <drive_letter_found> or "net use

<drive_letter_found>
Quote:
> /d"

> Alternativly, to dynamicly assigned drive letters using

Network.MapNetworkDrive,
Quote:
> you can enumerate existing drive letters and let your script find the next
free
> one to use. You will then know which one to delete later.

> --
> torgeir


> > Hello all,

> > I am mapping a driver using the following

> > Shell.Run "net use /user:domain\username * \\remotemachine\share
password"

> > I however need to delete the mapped driver after I am done with it but I
can
> > not figure out how to get the drive letter it uses.

> > My question is Is there a way to get the drive letter (maybe the Drives
> > collection????) so I can use a "net use %driverletter% /d"

> > any help is much appreciated



Sun, 11 Jul 2004 19:23:18 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Drive letter driving me crazy!

2. Retrieving drive letter for user's cd-rom drive

3. Determining drive letter assigned to floppy drive?

4. local drive letter <> drive share name

5. Drive Letter Property

6. get mapped drive letter from UNC path

7. Specifying server directory without mapped drive letter

8. CD drive letter determination

9. HowTo: Get UNC path based on a drive letter

10. Finding CD-ROM Drive Letter

11. CD-ROM drive letter?

12. Drive Letter Assignment

 

 
Powered by phpBB® Forum Software