2

I'm trying to use Process.Start() to start a lnk file. it's fine when credentials are not provided, but throws an exception when I do. here's the sample code:

This works fine

var processStartInfo = new ProcessStartInfo
{
    FileName = @"F:\abc.lnk",
};

using (var process = new Process())
{
    process.StartInfo = processStartInfo;
    process.Start();
}

But this code throws a Win32Exception: 'The specified executable is not a valid application for this OS platform'.

var processStartInfo = new ProcessStartInfo
{
    FileName = @"F:\abc.lnk",
    UserName = userName,
    Password = securePassword,
    Domain = domain,
    UseShellExecute = false,
};

using (var process = new Process())
{
    process.StartInfo = processStartInfo;
    process.Start();
}

My OS is 32bit and the program is too

I'll need those credentials as the file is on a network drive.

Any help will be greatly appreciated!!

Mo Patel
  • 2,321
  • 4
  • 22
  • 37
codebomb
  • 23
  • 1
  • 1
  • 3

2 Answers2

4

The docs say "When UseShellExecute is false, you can start only executables with the Process component", so passing it a .lnk file you should expect to fail.

Similar problem here: Run application via shortcut using Process.Start C#

Community
  • 1
  • 1
Bryan
  • 11,398
  • 3
  • 53
  • 78
0
Process process = new Process();
process.StartInfo.FileName = "F:\abc.lnk";
process.StartInfo.Arguments = "use \\\\computerName\\share password /user:UserName";
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.UseShellExecute = false;
process.Start();
process.WaitForExit();
process.Dispose();
go..
  • 958
  • 7
  • 15
  • how do I use this? "use \\\\computerName\\share" the F drive is on a network. I'm assuming that it goes like this: process.StartInfo.Arguments = "use \\\\computerName\\share /user:";? – codebomb Dec 18 '13 at 12:17