Process.Start an exe file on an network share as a

2019-07-05 03:18发布

问题:

I need to run an exe file that is located on an network drive in my domain. The drive is successfully attached to my PC as "M:\", but I know that Process.Start( string , string...) need to have URL paths to files when staring processes located on network share.

This is my code:

                string user = "user";
                string password = "Qwerty1";
                string domain = "nwtraderds";
                string open = "file://myshare\dir1\dir2\dir3\test.exe";

                string PwString = password;

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

                System.Diagnostics.Process.Start(open, user, Password, domain);

The funny thing is that:

                System.Diagnostics.Process.Start(open);

Works fine. I have run out of ideas, could someone help me please?

回答1:

while a network share is already mounted then Windows won't accept accessing it from the same desktop with a different user - you can even try that yourself: just mount it with user1 and then try to mount the same share a second time (in parallel) with a different user (user2) while it is still mounted (same machine, same windows explorer!).

UPDATE:

This file://myshare\dir1\dir2\dir3\test.exe won't work !

You either use \\myserver\myshare\dir1\dir2\dir3\test.exe (not sure if this works!) OR you use the drive letter M:\\dir1\dir2\dir3\test.exe !