tags:

views:

52

answers:

2

I just want open a mapped network drive from C# code ,it is apssword protected, so when i try to launch directly it gives exception. Can some one throw light on providing username password while opening the this drive

at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start() at System.Diagnostics.Process.Start(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start(String fileName)

I am just Calling System.Diagnostics.Process.Start("Z:")

+2  A: 

Z: is not a file name. [edit: it's ok if it's not password protected, tried executing your code and it worked]

Try using a ProcessStartInfo object as a parameter, as it allows setting a username and password.

And about the FileName parameter from here:

The file name is any application or document. A document is defined to be any file type that has an open or default action associated with it. You can view registered file types and their associated applications for your computer by using the Folder Options dialog box, which is available through the operating system. The Advanced button leads to a dialog box that shows whether there is an open action associated with a specific registered file type.

Rox
Incorrect!If you try accessing any other folder for ex d: it works perfectly fine.This process.start() is just like command line execution of start command
Ravisha
Please see what I added about the FileName parameter
Rox
Thanks Rox this is what i was looking for.
Ravisha
A: 

Perhaps you might consider instead opening the UNC path that your "z drive" is meant to point to. A reminder that a PC user can disconnect the Z: and replace it with whatever path they wanted to...

It's not entirely clear what you mean by "launch directly" and "opening this drive" but if as your code snip suggests you're trying to launch the Explorer for the drive's folder then you could use the ProcessStartInfo as a mechanism to provide credentials.

If you're trying to programmatically get access to a file(s) on that share, then you might look into the term impersonation to run your file access code blocks under a different credential. This http://stackoverflow.com/questions/659013/accessing-a-shared-file-unc-from-a-remote-non-trusted-domain-with-credentials looks particularly promising.

If you're trying to actually create the network drive using pre-specified credentials then there's another solution over here - http://serverfault.com/questions/47005/specifying-username-pass-as-part-of-a-unc-path-or-map-network-drives-for-a-window/47008#47008 (don't forget to disconnect it after).

Reddog