呵呵,我创建成功了。是用的是FilDisk.SYS作驱动,还对文件加了密,就像 WinDiskXP一样,不过没有搞出光驱和其他的驱动器,只有硬盘,我还要在研 究一下。对于CreateFile函数打开设备和DeviceIoControl函数不是很了解所 以还有得研究呢。我再告诉你一个命令:“Net”不错哟,还可以映像网络磁盘呢? Net use H: \\Server\D$ /user:administrator 12345 说明: Net 是命令名称 Use 是连接到共享资源的参数 H: 你要虚拟的盘符 \\Server\D$ 要连接的目标资源的网络地址 /User:用户名 登陆远程计算机的用户名(如果和你的计算机一样可以省略) 12345 登陆远程计算机的密码(如果没有可以省略)如果配合上面的Subst你将可以不论本地或是网络上的目录都可以映像成你的驱动器了。 但文件映像成驱动器嘛可能你暂时没办法啰,因为我也只能搞虚拟硬盘,还搞个乱七八 糟的,也没办法说给你听,等我搞清楚了再告诉你。
'模块 '------- Option ExplicitType NETRESOURCE dwScope As Long dwType As Long dwDisplayType As Long dwUsage As Long lpLocalName As String lpRemoteName As String lpComment As String lpProvider As String End Type Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Long, ByVal fForce As Long) As Long Declare Function WNetGetLastError Lib "mpr.dll" Alias "WNetGetLastErrorA" (lpError As Long, ByVal lpErrorBuf As String, ByVal nErrorBufSize As Long, ByVal lpNameBuf As String, ByVal nNameBufSize As Long) As LongPublic Const RESOURCE_PUBLICNET = &H2 Public Const RESOURCETYPE_ANY = &H0 Public Const RESOURCEDISPLAYTYPE_GENERIC = &H0 Public Const RESOURCEUSAGE_CONNECTABLE = &H1 Public Const CONNECT_UPDATE_PROFILE = &H1 Public Function AddConnection(ByVal RemoteLocation As String, ByVal LocalDriver As String, _ ByVal UserName As String, ByVal Passwd As String) As Boolean Dim ne As NETRESOURCE, i As Long Dim errstr As String, errpriv As String, erno As Longne.dwDisplayType = RESOURCEDISPLAYTYPE_GENERIC ne.dwScope = RESOURCE_PUBLICNET ne.dwType = RESOURCETYPE_ANY ne.dwUsage = RESOURCEUSAGE_CONNECTABLE ne.lpComment = vbNullString ne.lpLocalName = LocalDriver ne.lpProvider = vbNullString ne.lpRemoteName = RemoteLocationi = WNetAddConnection2(ne, Passwd, UserName, 0) If i = 0 Then AddConnection = True Else AddConnection = False errstr = String(256, 0) errpriv = String(256, 0) i = WNetGetLastError(erno, errstr, 256, errpriv, 256) errstr = Left(errstr, InStr(1, errstr, Chr(0)) - 1) 'MsgBox errstr, vbCritical End If End FunctionPublic Function CancelConnection(ByVal LocalDriver As String, ByVal ForceClose As Boolean) As Boolean Dim i As Long Dim errstr As String, errpriv As String, erno As Longi = WNetCancelConnection2(LocalDriver, 0, IIf(ForceClose, 1, 0)) If i = 0 Then CancelConnection = True Else CancelConnection = False errstr = String(256, 0) errpriv = String(256, 0) i = WNetGetLastError(erno, errstr, 256, errpriv, 256) errstr = Left(errstr, InStr(1, errstr, Chr(0)) - 1) 'MsgBox errstr, vbCritical End IfEnd Function '----------------------------------'调用 Option ExplicitPrivate Sub Command1_Click() '建立连接 MsgBox AddConnection("\\10.1.1.10\UploadFile", "x:", "administrator", "hyramwooaps") End SubPrivate Sub Command2_Click() '取消连接 MsgBox CancelConnection("x:", True)End Sub
Call Shell("subst z: f:\temp", vbHide)撤消
Call Shell("subst z: /d", vbHide)
好象是把f:\temp虚拟成磁盘,如果想用内存虚拟要怎么操作呀?
WinDiskXP一样,不过没有搞出光驱和其他的驱动器,只有硬盘,我还要在研
究一下。对于CreateFile函数打开设备和DeviceIoControl函数不是很了解所
以还有得研究呢。我再告诉你一个命令:“Net”不错哟,还可以映像网络磁盘呢?
Net use H: \\Server\D$ /user:administrator 12345
说明:
Net 是命令名称
Use 是连接到共享资源的参数
H: 你要虚拟的盘符
\\Server\D$ 要连接的目标资源的网络地址
/User:用户名 登陆远程计算机的用户名(如果和你的计算机一样可以省略)
12345 登陆远程计算机的密码(如果没有可以省略)如果配合上面的Subst你将可以不论本地或是网络上的目录都可以映像成你的驱动器了。
但文件映像成驱动器嘛可能你暂时没办法啰,因为我也只能搞虚拟硬盘,还搞个乱七八
糟的,也没办法说给你听,等我搞清楚了再告诉你。
'-------
Option ExplicitType NETRESOURCE
dwScope As Long
dwType As Long
dwDisplayType As Long
dwUsage As Long
lpLocalName As String
lpRemoteName As String
lpComment As String
lpProvider As String
End Type
Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long
Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Long, ByVal fForce As Long) As Long
Declare Function WNetGetLastError Lib "mpr.dll" Alias "WNetGetLastErrorA" (lpError As Long, ByVal lpErrorBuf As String, ByVal nErrorBufSize As Long, ByVal lpNameBuf As String, ByVal nNameBufSize As Long) As LongPublic Const RESOURCE_PUBLICNET = &H2
Public Const RESOURCETYPE_ANY = &H0
Public Const RESOURCEDISPLAYTYPE_GENERIC = &H0
Public Const RESOURCEUSAGE_CONNECTABLE = &H1
Public Const CONNECT_UPDATE_PROFILE = &H1
Public Function AddConnection(ByVal RemoteLocation As String, ByVal LocalDriver As String, _
ByVal UserName As String, ByVal Passwd As String) As Boolean
Dim ne As NETRESOURCE, i As Long
Dim errstr As String, errpriv As String, erno As Longne.dwDisplayType = RESOURCEDISPLAYTYPE_GENERIC
ne.dwScope = RESOURCE_PUBLICNET
ne.dwType = RESOURCETYPE_ANY
ne.dwUsage = RESOURCEUSAGE_CONNECTABLE
ne.lpComment = vbNullString
ne.lpLocalName = LocalDriver
ne.lpProvider = vbNullString
ne.lpRemoteName = RemoteLocationi = WNetAddConnection2(ne, Passwd, UserName, 0)
If i = 0 Then
AddConnection = True
Else
AddConnection = False
errstr = String(256, 0)
errpriv = String(256, 0)
i = WNetGetLastError(erno, errstr, 256, errpriv, 256)
errstr = Left(errstr, InStr(1, errstr, Chr(0)) - 1)
'MsgBox errstr, vbCritical
End If
End FunctionPublic Function CancelConnection(ByVal LocalDriver As String, ByVal ForceClose As Boolean) As Boolean
Dim i As Long
Dim errstr As String, errpriv As String, erno As Longi = WNetCancelConnection2(LocalDriver, 0, IIf(ForceClose, 1, 0))
If i = 0 Then
CancelConnection = True
Else
CancelConnection = False
errstr = String(256, 0)
errpriv = String(256, 0)
i = WNetGetLastError(erno, errstr, 256, errpriv, 256)
errstr = Left(errstr, InStr(1, errstr, Chr(0)) - 1)
'MsgBox errstr, vbCritical
End IfEnd Function
'----------------------------------'调用
Option ExplicitPrivate Sub Command1_Click()
'建立连接
MsgBox AddConnection("\\10.1.1.10\UploadFile", "x:", "administrator", "hyramwooaps")
End SubPrivate Sub Command2_Click()
'取消连接
MsgBox CancelConnection("x:", True)End Sub