本來可以用簡(jiǎn)單的dos命令的,但是影射成功與否返回不理想,建議用API,見下面
創(chuàng)新互聯(lián)公司長期為近千家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為慈溪企業(yè)提供專業(yè)的成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè),慈溪網(wǎng)站改版等技術(shù)服務(wù)。擁有10余年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。
Module?LocalNetConnect'模塊,直接復(fù)制即可
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
'設(shè)置驅(qū)動(dòng)器
NetR.lpLocalName?=?localDrive
'設(shè)置遠(yuǎn)程端口名字
NetR.lpRemoteName?=?sharePath
'設(shè)置連接
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
‘調(diào)用
Private?Sub?Button1_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button1.Click
'這里是映射調(diào)用,administrator為用戶名,根據(jù)實(shí)際用戶名
’如果將“Z:”設(shè)置為空就不會(huì)網(wǎng)絡(luò)盤映射但是已經(jīng)和172.26.120.47聯(lián)機(jī)了(返回真時(shí)成立)。
If?netconnect("Z:",?"\\172.26.120.47\c$",?"administrator",?"局域網(wǎng)電腦實(shí)際密碼")?=?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 根本就訪問不了內(nèi)存,只能通過調(diào)用api函數(shù)方式,不光是vb.net ,C#也是,主要是為了安全,微軟在net里面不容許直接訪問內(nèi)存。
文件鏡像功能吧, 監(jiān)控文件的變化然后實(shí)時(shí)同步就行了 .. 好像是叫那個(gè)filewatcher類,可以做