Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I created a subroutine to map drives...</p> <pre><code> MapDrive "H:","\\server\share" Sub MapDrive(letter, uncpath) on error Resume Next dim drivetype, currentmapping dim objWMIService dim colDisks, objDisk 'Set wshnetwork = CreateObject("Wscript.Network") Set objWMIService = GetObject("winmgmts:" &amp; _ "{impersonationLevel=impersonate}!\\.\root\cimv2") Set colDisks = objWMIService.ExecQuery _ ("Select * from Win32_LogicalDisk Where Name = """ &amp; letter &amp; """") For Each objDisk In colDisks drivetype = objDisk.DriveType currentmapping = objDisk.ProviderName Next if (drivetype &lt;&gt; 4 and drivetype &lt;&gt; 0) then NotifyUser ucase(letter) &amp; " cannot be mapped due to a physical device already reserving that drive letter" &amp; vbcrlf &amp; _ "This is most frequently caused by a thumbdrive or external disk.",5 exit Function end if if (ucase(currentmapping) = ucase(uncpath)) then exit function end If if (drivemappings.Exists(uncpath)) then drivemappings.Add uncpath &amp; "(" &amp; letter &amp; ")", letter else drivemappings.Add uncpath, letter end if if (currentmapping &lt;&gt; "") then wshnetwork.RemoveNetworkDrive letter,,True end if wshnetwork.MapNetworkDrive letter, uncpath, true on Error goto 0 End Sub </code></pre> <p>I leave it up to you do handle error checking etc. Alternatively if you prefer the net use route you could do something like..</p> <pre><code>dim wshShell Set wshShell = CreateObject("WScript.Shell") wshshell.run "cmd /c net use H: ""\\server\share""",1,True </code></pre> <p>You can take it a step further to automagically use the next available drive letter to map drives using an example <a href="http://blogs.technet.com/b/heyscriptingguy/archive/2005/01/24/hey-scripting-guy-how-can-i-determine-the-next-available-drive-letter-on-a-computer.aspx">The Scripting Guys</a> created.</p> <pre><code>Set objDictionary = CreateObject("Scripting.Dictionary") strComputer = "." Set objWMIService = GetObject("winmgmts:\\" &amp; strComputer &amp; "\root\cimv2") Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk") For Each objDisk in colDisks objDictionary.Add objDisk.DeviceID, objDisk.DeviceID Next For i = 67 to 90 strDrive = Chr(i) &amp; ":" If objDictionary.Exists(strDrive) Then Else Wscript.Echo strDrive &amp; " is the next available drive letter." Wscript.Quit End If Next Wscript.Echo "There are no available drive letters on this computer.” </code></pre> <p>I hope this is helpful.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload