I'd like to programatically map a network drive. I tried the following code
but got the error: User credentials cannot be used for local connections.
Does anyone have any ideas of what is causing this?
PS: I can ping the machine to be mapped and I can map it in windows with a
good username and password.
Here is the code:
Dim options As New ConnectionOptio ns
options.Usernam e = strUserName
options.Passwor d = strPassword
Dim scope As New ManagementScope (strPathOfDrive ToBeMapped, options)
Try
scope.Connect()
Dim disk As New ManagementObjec t(scope, _
New ManagementPath( "Win32_logicald isk='c:'"), Nothing)
disk.Get()
Catch e As UnauthorizedAcc essException
MessageBox.Show ("Failed to connect: " + e.Message)
End Try
but got the error: User credentials cannot be used for local connections.
Does anyone have any ideas of what is causing this?
PS: I can ping the machine to be mapped and I can map it in windows with a
good username and password.
Here is the code:
Dim options As New ConnectionOptio ns
options.Usernam e = strUserName
options.Passwor d = strPassword
Dim scope As New ManagementScope (strPathOfDrive ToBeMapped, options)
Try
scope.Connect()
Dim disk As New ManagementObjec t(scope, _
New ManagementPath( "Win32_logicald isk='c:'"), Nothing)
disk.Get()
Catch e As UnauthorizedAcc essException
MessageBox.Show ("Failed to connect: " + e.Message)
End Try