C# open file from network with specified user.

I am using these codes to open file from network with specified username of domain, but it shows error:

"The specified executable is not a valid application for this OS platform."

Please help me!

Process proc = new Process();
            proc.StartInfo = new ProcessStartInfo(@"\\\Shared\ExcelTest.xls");
            proc.StartInfo.UserName = "MyUserName";
            proc.StartInfo.Domain = "MYDOMAIN";

            string PwString = "PassWord";
            char[] PasswordChars = PwString.ToCharArray();
            SecureString Password = new SecureString();
            foreach (char c in PasswordChars)

            proc.StartInfo.Password = Password;
            proc.StartInfo.UseShellExecute = false;

Open in new window

Who is Participating?
Do you have Excel installed and in the path? Are you using an Excel Viewer? You need to specify the full path of the application you want to use to open the XLS file.

The shell normally does this for you but you lose that ability when using credentials over the network. If you still get stuck then I would suggest the following:
1. Instead of opening the file from the network, just copy it to a local temporary location first (http://stackoverflow.com/questions/659013/accessing-a-shared-file-unc-from-a-remote-non-trusted-domain-with-credentials).
2. Open the file from your local temp directory making sure UseShellExecute = true.

That way the shell can figure out how to open the file.
You need to have ShellExecute on so that it knows how to open the XLS files (with Excel):
proc.StartInfo.UseShellExecute = true;

Open in new window

If you must have this off then you should start Excel passing in the the file from the network as an argument:
proc.StartInfo = new ProcessStartInfo("Excel.exe", @"\\\Shared\ExcelTest.xls");

Open in new window

Since you are using Password you'll have to go for option 2 since you cannot shell execute when using this (according to the documentation), you must specify the executable to use when trying to open a specific file..
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

JameMeckAuthor Commented:
I did as you said, then here is the error:

The Process object must have the UseShellExecute property set to false in order to start a process as a user.
Check my second comment above :)
JameMeckAuthor Commented:
Dear brutaldev,
I did your second option, but here is the error:

 "The system cannot find the file specified"
JameMeckAuthor Commented:
Thanks! I will try your way.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.