Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to open a shared folder in my server and the code is:
C#
ProcessStartInfo si = new ProcessStartInfo("explorer.exe", @"/root,\\172.16.242.41\photos");
si.UserName = textEdit2.Text;
System.Security.SecureString ss = new System.Security.SecureString();
foreach (char c in textEdit4.Text.ToCharArray())
   ss.AppendChar(c);
si.Password = ss;
si.UseShellExecute = false;
Process.Start(si);

No matter how I try, I always get "Logon failure: unknown user name or bad password".

My server doesn't belong to any domain. It belongs to workgroup.
Is it the reason?
Posted
Updated 10-Jun-14 6:59am
v2
Comments
[no name] 10-Jun-14 13:02pm    
Why are you going through all of this at all? If the folder is shared, why are you not just doing "Process.Start(path-to-your-folder);"? None of the rest of the code should be necessary.
TcJoshJohnson 11-Jun-14 19:56pm    
You're trying to start the explorer process as the remote machine's user, which isn't possible. You need to PInvoke the WNetUseConnection method to authenticate with the remote server via username/password. WNetUseconnection Doc: http://msdn.microsoft.com/en-us/library/aa385482%28VS.85%29.aspx

1 solution

You should be able to do this using the code below to open the folder:
System.Diagnostics.Process.Start(networkPathHere)
 
Share this answer
 
Comments
TcJoshJohnson 27-Jun-14 13:06pm    
This won't work for orgilhp as the share in question is requiring a login, which needs to be provided programmatically.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900