process.start() throws win32Exception when credentials are given

10,248

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#

Share:
10,248
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    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!!