Run mstsc.exe with specified username and password

前端 未结 7 1842
悲&欢浪女
悲&欢浪女 2020-12-04 16:06

I realize that in Windows 7, it is not possible to save different credentials for the same host, but I need some workaround.

Can I provide the username and password

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-04 16:21

    most of the answers are incorrect, it still request password and this because execute different processes on the same process instance.

    using command line works perfectly:

            string command = "/c cmdkey.exe /generic:" + ip 
            + " /user:" + user + " /pass:" + password + " & mstsc.exe /v " + ip;
    
            ProcessStartInfo info = new ProcessStartInfo("cmd.exe", command);
            info.WindowStyle = ProcessWindowStyle.Hidden;
            info.CreateNoWindow = true;
    
            Process proc = new Process();
            proc.StartInfo = info;
            proc.Start();
    

提交回复
热议问题