指定用户名和密码启动指定文件

编辑本文章

指定用户名和密码启动指定文件

public Process RunExe(string filePath,string user="",string pwd="", string argument = "")
        {
            Process p = new Process();
            if (!string.IsNullOrEmpty(user) && !string.IsNullOrEmpty(pwd)) {
                p.StartInfo.UserName = user;
                p.StartInfo.Password = getSecureString(pwd);
                //Process.Start(filePath, user, pwd);
            }
            p.StartInfo.FileName = filePath;
            p.StartInfo.Arguments = argument;
            p.StartInfo.UseShellExecute = false;
            p.Start();
            return p;
        }
        public SecureString getSecureString(string pwd)
        {
            SecureString securePwd = new SecureString();
            for (var i = 0; i < pwd.Length; i++)
            {
                securePwd.AppendChar(pwd[i]);
            }
            return securePwd;
        }

 

posted @ 2020-05-21 22:42  丫丫625202  阅读(206)  评论(0编辑  收藏  举报