By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,313 Members | 2,798 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,313 IT Pros & Developers. It's quick & easy.

programatically map network drive

P: n/a
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 ConnectionOptions
options.Username = strUserName
options.Password = strPassword
Dim scope As New ManagementScope(strPathOfDriveToBeMapped, options)

Try
scope.Connect()
Dim disk As New ManagementObject(scope, _
New ManagementPath("Win32_logicaldisk='c:'"), Nothing)
disk.Get()
Catch e As UnauthorizedAccessException
MessageBox.Show("Failed to connect: " + e.Message)
End Try
Jul 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.