重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
本来可以用简单的dos命令的,但是影射成功与否返回不理想,建议用API,见下面
10年积累的成都做网站、成都网站制作经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计后付款的网站建设流程,更有晋宁免费网站建设让你可以放心的选择与我们合作。
Module LocalNetConnect'模块,直接复制即可
Public Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (ByRef lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Integer) As Integer
Public Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Integer, ByVal fForce As Integer) As Integer
Public Structure NETRESOURCE
Dim dwScope As Integer
Dim dwType As Integer
Dim dwDisplayType As Integer
Dim dwUsage As Integer
Dim lpLocalName As String
Dim lpRemoteName As String
Dim lpComment As String
Dim lpProvider As String
End Structure
Public Function netconnect(ByVal localDrive As String, ByVal sharePath As String, ByVal userName As String, ByVal UserPassword As String) As Boolean
Dim NetR As New NETRESOURCE
Dim ErrInfo As Integer
NetR.dwScope = 2
NetR.dwType = 1
NetR.dwDisplayType = 3
NetR.dwUsage = 1
'设置驱动器
NetR.lpLocalName = localDrive
'设置远程端口名字
NetR.lpRemoteName = sharePath
'设置连接
ErrInfo = WNetAddConnection2(NetR, UserPassword, userName, 1)
If ErrInfo = 0 Then
Return True
Else
Return False
End If
End Function
Public Function netdisconnect(ByVal localDrive As String) As Boolean
Dim ErrInfo As Integer
ErrInfo = WNetCancelConnection2(localDrive, 1, False)
If ErrInfo = 0 Then
Return True
Else
Return False
End If
End Function
End Module
‘调用
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'这里是映射调用,administrator为用户名,根据实际用户名
’如果将“Z:”设置为空就不会网络盘映射但是已经和172.26.120.47联机了(返回真时成立)。
If netconnect("Z:", "\\172.26.120.47\c$", "administrator", "局域网电脑实际密码") = True Then
MsgBox("success")
Else
MsgBox("Faile")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click'这里是取消映射
If netdisconnect("Z:") = True Then
MsgBox("success")
Else
MsgBox("Faile")
End If
End Sub
vb.net是vb的升级。
vb.net基于.net框架,是vb发展的必然趋势。
vb功能非常强大,但是也存在众多的缺点,所以微软才会开发vb.net。
随着时间的发展,vb.net完全取代vb是必然的
VB术语简介
说明下面的代码举例说明了用 Drive 对象来访问驱动器属性:Sub ShowFreeSpace(drvPath) Dim fs, d, s Set fs = CreateObject("Scripting.FileSystemObject") Set d = fs.GetDrive(fs.GetDriveName(drvPath)) s = "Drive " UCase(drvPath) " - " s = s d.VolumeName vbCrLf s = s "Free Space: " FormatNumber(d.FreeSpace/1024, 0) s = s " Kbytes" MsgBox sEnd Sub.
Sub RenameVolume()
'利用Shell函数在命令提示符下执行Diskpart命令的脚本,并存入日志文件
'达到替换逻辑盘符的目的
'在WindowsXp系统下测试成功
'获取临时文件路径
Temp = Environ("TEMP") "\"
'获取命令提示符路径
Cmd = Environ("ComSpec")
'设置脚本文件和日志文件路径
ScriptFile = Temp "DiskpartScript.txt"
ScriptLog = Temp "DiskpartScript.log"
'回车符和换行符
vbLfCr = vbLf vbCr
'脚本文件内容
'选择卷e
'移除盘符e
'分配盘符m
'退出Diskpart
ScriptTxt = "select volume e" vbLf vbCr _
"Remove letter = e" vbLf vbCr _
"assign letter = m" vbLf vbCr _
"exit" vbLf vbCr
'打开脚本文件并读取内容
Open ScriptFile For Output As #1
Print #1, ScriptTxt
Close #1
'打开错误处理
On Error Resume Next
'删除原有日志文件
Kill ScriptLog
'关闭错误处理
On Error GoTo 0
'执行脚本
ShellTxt = Cmd " /c ""diskpart.exe /S " ScriptFile " " ScriptLog """"
Shell ShellTxt
'打开错误处理
On Error Resume Next
Do
Err.Number = 0
'打开日志文件并读取内容,因日志文件存取速度慢,必须以锁定方式打开,否则会出错
Open ScriptLog For Input Lock Read Write As #1
DoEvents
Loop Until Err.Number = 0
'关闭错误处理
On Error GoTo 0
'日志文件中含有中文字符,必须以InputB函数以字节方式读取,否则长度会超出
LogTxt = InputB(LOF(1), #1)
Close #1
'转换以字节方式读取的日志文件内容
LogTxt = StrConv(LogTxt, vbUnicode)
'如果日志中出现两次成功,则认为执行成功,否则认为失败
If Len(LogTxt) - Len(Replace(LogTxt, "成功", "", 1)) = 4 Then
MsgBox "盘符替换成功!"
Else
MsgBox "盘符替换失败!"
End If
'删除临时文件
Kill ScriptFile
Kill ScriptLog
End Sub
IIS需要一个XP系统自带的文件才能安装,不记得叫什么名字了
如果你没有安装盘的话建议它跳出提示框的时候你点击【浏览】
看到那个文件的名字以后去网上搜一下,可能需要的还不止一个文件,你慢慢找吧
另外Vista系统没用过,你可以随便找个系统盘试一下,跟盗版正版没关系,都可以装