C# open file from network with specified user.

Posted on 2011-10-18
Medium Priority
Last Modified: 2013-12-16
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

Question by:JameMeck
  • 4
  • 3
LVL 11

Expert Comment

ID: 36990732
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

LVL 11

Expert Comment

ID: 36990739
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..

Author Comment

ID: 36990751
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.
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

LVL 11

Expert Comment

ID: 36990755
Check my second comment above :)

Author Comment

ID: 36997461
Dear brutaldev,
I did your second option, but here is the error:

 "The system cannot find the file specified"
LVL 11

Accepted Solution

brutaldev earned 2000 total points
ID: 36998020
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.

Author Closing Comment

ID: 37186708
Thanks! I will try your way.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question