2011-09-07 69 views

回答

3

在您運行以下命令VBScript文件:

net use [NetDrive:] [Network Path] 

例如:

net use Z: \\Hadi\temp 

示例命令將映射\哈迪\ TEMP到Z:

而且看看在this VBScript文件映射網絡驅動器。

5

我創建了一個子程序映射驅動器...

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:" & _ 
      "{impersonationLevel=impersonate}!\\.\root\cimv2") 
     Set colDisks = objWMIService.ExecQuery _ 
      ("Select * from Win32_LogicalDisk Where Name = """ & letter & """") 
     For Each objDisk In colDisks   
      drivetype = objDisk.DriveType  
      currentmapping = objDisk.ProviderName 
     Next  


     if (drivetype <> 4 and drivetype <> 0) then 
      NotifyUser ucase(letter) & " cannot be mapped due to a physical device already reserving that drive letter" & vbcrlf & _ 
         "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 & "(" & letter & ")", letter 
     else 
      drivemappings.Add uncpath, letter 
     end if 

     if (currentmapping <> "") then 
       wshnetwork.RemoveNetworkDrive letter,,True 
     end if 

     wshnetwork.MapNetworkDrive letter, uncpath, true 

     on Error goto 0 
    End Sub 

我把它留給你做處理錯誤檢查等。另外,如果你喜歡的網絡使用路線,你可以不喜歡..

dim wshShell 
Set wshShell = CreateObject("WScript.Shell") 
wshshell.run "cmd /c net use H: ""\\server\share""",1,True 

您可以進一步自動使用下一個可用的驅動器號來映射驅動器,例如使用創建的The Scripting Guys示例。

Set objDictionary = CreateObject("Scripting.Dictionary") 

strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\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) & ":" 
    If objDictionary.Exists(strDrive) Then 
    Else 
     Wscript.Echo strDrive & " is the next available drive letter." 
     Wscript.Quit 
    End If 
Next 
Wscript.Echo "There are no available drive letters on this computer.」 

我希望這是有幫助的。

相關問題