Process.Start an exe file on an network share as another user

我是研究僧i 提交于 2020-01-24 11:04:38

问题


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 !



来源:https://stackoverflow.com/questions/9189170/process-start-an-exe-file-on-an-network-share-as-another-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!