'映射网络盘API函数 Public Const RESOURCETYPE_DISK = &H1 Public Declare Function WNetConnectionDialog Lib "mpr.dll" (ByVal hWnd As Long, ByVal dwType As Long) As LongPrivate Type BrowseInfo hWndOwner As Long pIDLRoot As Long pszDisplayName As Long lpszTitle As Long ulFlags As Long lpfnCallback As Long lParam As Long iImage As Long End TypePrivate Const BIF_RETURNONLYFSDIRS = 1 Private Const MAX_PATH = 260Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long) Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" _ (ByVal lpString1 As String, ByVal lpString2 As String) As Long Private Declare Function SHBrowseForFolder Lib "shell32" _ (lpbi As BrowseInfo) As Long Private Declare Function SHGetPathFromIDList Lib "shell32" _ (ByVal pidList As Long, ByVal lpBuffer As String) As Long 没事干的时候,我会望向白驼山。我清楚地记得曾经有一个女人在那边等着 我,其实“醉生梦死”只不过是她和我开的一个玩笑,你越想知道自己是不是忘 记的时候,你反而记得越清楚。 我曾经听人说过,当你不能够再拥有,你唯一可以做的,就是令自己不要忘 记。 不知道为什么,我常常会做同一个梦。没多久,我就离开了这个地方。
其实最简单的方法是用whs在windows下安装宿主脚本,引用wshom.ocx Dim x As IWshNetwork Set x = CreateObject("WScript.Network") x.MapNetworkDrive "x:", "\\server\vlum", , "username", "passwd"
wshom.ocx是m$的widnows scripting host,你的windows需要安装这个功能 如果你已经有了,那么,不是在控件中添加,而是直接引用,不引用似乎也可以 看看 ' Windows Script Host Sample Script ' ' ------------------------------------------------------------------------ ' Copyright (C) 1996 Microsoft Corporation ' ' You have a royalty-free right to use, modify, reproduce and distribute ' the Sample Application Files (and/or any modified version) in any way ' you find useful, provided that you agree that Microsoft has no warranty, ' obligations or liability for any Sample Application Files. ' ------------------------------------------------------------------------ ' ' This sample demonstrates how to use the WSHNetwork object. ' It reads network properties (username and computername), ' connects, disconnects, and enumerates network drives. L_Welcome_MsgBox_Message_Text = "此脚本显示如何使用 WSHNetwork 对象。" L_Welcome_MsgBox_Title_Text = "Windows Scripting Host 范例" Call Welcome()' ******************************************************************************** ' * ' * WSH Network Object. ' *Dim WSHNetwork Dim colDrives, SharePoint Dim CRLFCRLF = Chr(13) & Chr(10) Set WSHNetwork = WScript.CreateObject("WScript.Network") Function Ask(strAction) ' This function asks the user whether to perform a specific "Action" ' and sets a return code or quits script execution depending on the ' button that the user presses. This function is called at various ' points in the script below. Dim intButton intButton = MsgBox(strAction, _ vbQuestion + vbYesNo, _ L_Welcome_MsgBox_Title_Text ) Ask = intButton = vbYes End Function' ************************************************** ' * ' * Show WSHNetwork object properties ' * ' * MsgBox "UserDomain" & Chr(9) & "= " & WSHNetwork.UserDomain & CRLF & _ "UserName" & Chr(9) & "= " & WSHNetwork.UserName & CRLF & _ "ComputerName" & Chr(9) & "= " & WSHNetwork.ComputerName, _ vbInformation + vbOKOnly, _ "WSHNetwork 属性"' ************************************************** ' * ' * WSHNetwork.AddNetworkDrive ' * ' *Function TryMapDrive(intDrive, strShare) Dim strDrive strDrive = Chr(intDrive + 64) & ":" On Error Resume Next WSHNetwork.MapNetworkDrive strDrive, strShare TryMapDrive = Err.Number = 0 End FunctionIf Ask("要连接网络驱动器吗?") Then strShare = InputBox("请输入要连接的网络共享名称") For intDrive = 26 To 5 Step -1 If TryMapDrive(intDrive, strShare) Then Exit For Next If intDrive <= 5 Then MsgBox "无法连接到网络共享。 " & _ "现在没有可用的驱动器号。 " & _ CRLF & _ "请断开一个现存网络连接 " & _ "并重新运行此脚本。 ", _ vbExclamation + vbOkOnly, _ L_Welcome_MsgBox_Title_Text Else strDrive = Chr(intDrive + 64) & ":" MsgBox "已连接 " & strShare & " 到驱动器 " & strDrive, _ vbInformation + vbOkOnly, _ L_Welcome_MsgBox_Title_Text If Ask("要断开刚创建的网络驱动器吗?") Then WSHNetwork.RemoveNetworkDrive strDrive MsgBox "已断开驱动器 " & strDrive, _ vbInformation + vbOkOnly, _ L_Welcome_MsgBox_Title_Text End If End If End If ' ************************************************** ' * ' * WSHNetwork.EnumNetworkDrive ' * ' * 'Ask user whether to enumerate network drives If Ask("要列出已连接的网络驱动器吗?") Then 'Enumerate network drives into a collection object of type WshCollection Set colDrives = WSHNetwork.EnumNetworkDrives 'If no network drives were enumerated, then inform user, else display 'enumerated drives If colDrives.Count = 0 Then MsgBox "没有可列出的驱动器。", _ vbInformation + vbOkOnly, _ L_Welcome_MsgBox_Title_Text Else strMsg = "当前网络驱动器连接: " & CRLF For i = 0 To colDrives.Count - 1 Step 2 strMsg = strMsg & CRLF & colDrives(i) & Chr(9) & colDrives(i + 1) Next
MsgBox strMsg, _ vbInformation + vbOkOnly, _ L_Welcome_MsgBox_Title_Text End If End If' ******************************************************************************** ' * ' * Welcome ' * Sub Welcome() Dim intDoIt intDoIt = MsgBox(L_Welcome_MsgBox_Message_Text, _ vbOKCancel + vbInformation, _ L_Welcome_MsgBox_Title_Text ) If intDoIt = vbCancel Then WScript.Quit End If End Sub
Public Const RESOURCETYPE_DISK = &H1
Public Declare Function WNetConnectionDialog Lib "mpr.dll" (ByVal hWnd As Long, ByVal dwType As Long) As LongPrivate Type BrowseInfo
hWndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End TypePrivate Const BIF_RETURNONLYFSDIRS = 1
Private Const MAX_PATH = 260Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" _
(ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32" _
(lpbi As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32" _
(ByVal pidList As Long, ByVal lpBuffer As String) As Long
没事干的时候,我会望向白驼山。我清楚地记得曾经有一个女人在那边等着
我,其实“醉生梦死”只不过是她和我开的一个玩笑,你越想知道自己是不是忘
记的时候,你反而记得越清楚。
我曾经听人说过,当你不能够再拥有,你唯一可以做的,就是令自己不要忘
记。
不知道为什么,我常常会做同一个梦。没多久,我就离开了这个地方。
那天黄历上写着:驿马动,火逼金星,大利西方。
Set x = CreateObject("WScript.Network")
x.MapNetworkDrive "x:", "\\server\vlum", , "username", "passwd"
如果你已经有了,那么,不是在控件中添加,而是直接引用,不引用似乎也可以
看看
' Windows Script Host Sample Script
'
' ------------------------------------------------------------------------
' Copyright (C) 1996 Microsoft Corporation
'
' You have a royalty-free right to use, modify, reproduce and distribute
' the Sample Application Files (and/or any modified version) in any way
' you find useful, provided that you agree that Microsoft has no warranty,
' obligations or liability for any Sample Application Files.
' ------------------------------------------------------------------------
'
' This sample demonstrates how to use the WSHNetwork object.
' It reads network properties (username and computername),
' connects, disconnects, and enumerates network drives.
L_Welcome_MsgBox_Message_Text = "此脚本显示如何使用 WSHNetwork 对象。"
L_Welcome_MsgBox_Title_Text = "Windows Scripting Host 范例"
Call Welcome()' ********************************************************************************
' *
' * WSH Network Object.
' *Dim WSHNetwork
Dim colDrives, SharePoint
Dim CRLFCRLF = Chr(13) & Chr(10)
Set WSHNetwork = WScript.CreateObject("WScript.Network")
Function Ask(strAction) ' This function asks the user whether to perform a specific "Action"
' and sets a return code or quits script execution depending on the
' button that the user presses. This function is called at various
' points in the script below. Dim intButton
intButton = MsgBox(strAction, _
vbQuestion + vbYesNo, _
L_Welcome_MsgBox_Title_Text )
Ask = intButton = vbYes
End Function' **************************************************
' *
' * Show WSHNetwork object properties
' *
' *
MsgBox "UserDomain" & Chr(9) & "= " & WSHNetwork.UserDomain & CRLF & _
"UserName" & Chr(9) & "= " & WSHNetwork.UserName & CRLF & _
"ComputerName" & Chr(9) & "= " & WSHNetwork.ComputerName, _
vbInformation + vbOKOnly, _
"WSHNetwork 属性"' **************************************************
' *
' * WSHNetwork.AddNetworkDrive
' *
' *Function TryMapDrive(intDrive, strShare)
Dim strDrive
strDrive = Chr(intDrive + 64) & ":"
On Error Resume Next
WSHNetwork.MapNetworkDrive strDrive, strShare
TryMapDrive = Err.Number = 0
End FunctionIf Ask("要连接网络驱动器吗?") Then
strShare = InputBox("请输入要连接的网络共享名称")
For intDrive = 26 To 5 Step -1
If TryMapDrive(intDrive, strShare) Then Exit For
Next If intDrive <= 5 Then
MsgBox "无法连接到网络共享。 " & _
"现在没有可用的驱动器号。 " & _
CRLF & _
"请断开一个现存网络连接 " & _
"并重新运行此脚本。 ", _
vbExclamation + vbOkOnly, _
L_Welcome_MsgBox_Title_Text
Else
strDrive = Chr(intDrive + 64) & ":"
MsgBox "已连接 " & strShare & " 到驱动器 " & strDrive, _
vbInformation + vbOkOnly, _
L_Welcome_MsgBox_Title_Text If Ask("要断开刚创建的网络驱动器吗?") Then
WSHNetwork.RemoveNetworkDrive strDrive MsgBox "已断开驱动器 " & strDrive, _
vbInformation + vbOkOnly, _
L_Welcome_MsgBox_Title_Text
End If
End If
End If
' **************************************************
' *
' * WSHNetwork.EnumNetworkDrive
' *
' *
'Ask user whether to enumerate network drives
If Ask("要列出已连接的网络驱动器吗?") Then
'Enumerate network drives into a collection object of type WshCollection
Set colDrives = WSHNetwork.EnumNetworkDrives 'If no network drives were enumerated, then inform user, else display
'enumerated drives
If colDrives.Count = 0 Then
MsgBox "没有可列出的驱动器。", _
vbInformation + vbOkOnly, _
L_Welcome_MsgBox_Title_Text
Else
strMsg = "当前网络驱动器连接: " & CRLF
For i = 0 To colDrives.Count - 1 Step 2
strMsg = strMsg & CRLF & colDrives(i) & Chr(9) & colDrives(i + 1)
Next
MsgBox strMsg, _
vbInformation + vbOkOnly, _
L_Welcome_MsgBox_Title_Text End If
End If' ********************************************************************************
' *
' * Welcome
' *
Sub Welcome()
Dim intDoIt intDoIt = MsgBox(L_Welcome_MsgBox_Message_Text, _
vbOKCancel + vbInformation, _
L_Welcome_MsgBox_Title_Text )
If intDoIt = vbCancel Then
WScript.Quit
End If
End Sub