问题
I have spend months now trying to get the Visual Basic 2010 codes on how to map a network drive, disconnect them, and re-map network driver.
I will need to be able to map it to the profile folder to something like this:
Full path; “\10.10.10.12\Profile folder".
I need to log in to have access to the network folder /user:Domainname\UserName Password
,
then confirm if mapping was successful with a message.
After the mapping I will request the profile name and check if such profile folder exists on the network. If it exists, return a message stating that the profile exists, and delete the profile folder overwriting any folder property like if reading only, etc.
There are other tasks but his is where I am hit a dead end.
回答1:
This question is old but maybe the OP is still looking. I wrote an HTA page awhile back to map a network address to a virtual drive. The code is VBScript and so uses the WScript library, which is not a native part of VB.net. See WScript in VB.Net on StackOverflow for more info on that.
The connect script:
SUB doLogOn()
Dim objNetwork, errNum, ojbFSO, strDrive, iNum
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists("\\MyServer\MyFolder\") = False Then
strDrive = "J:"
Set objNetwork = CreateObject("WScript.Network")
On Error Resume Next
objNetwork.MapNetworkDrive strDrive, "\\MyServer\MyFolder", False, "username", "password"
If Err.Number <> 0 Then
Err.Clear
End If
Set objFSO = Nothing
Set objNetwork = Nothing
End If
END SUB
Personally, I haven't found code to do the same thing in .Net. The VBScript shown above is pretty primitive; I hope it plus the info on binding WScript gives you an idea or two, though.
Edit: see Eric Dalnas' code, here
来源:https://stackoverflow.com/questions/12541310/map-network-drive-in-visual-basic-2010