public static void NewRDP(string username, string password) { string user = username; string pass = password; string path = System.Reflection.Assembly.GetExecutingAssembly().Location; string directory = System.IO.Path.GetDirectoryName(path); if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) { //always reload config file for different users //if (cfg == null) if (File.Exists(directory + "\\" + "mstsc2.exe") == false) { WriteLog("The mstsc2.exe does not exist, so stop the default unlock action."); return; } string filename = File.ReadAllText(directory + "\\unlock.txt"); if (File.Exists(directory + "\\" + filename)) { cfg = new Config(); cfg.load(directory + "\\" + filename); } else { if (File.Exists(directory + "\\" + "config.ini") == false) { WriteLog("The config.ini does not exist, so stop the default unlock action."); return; } cfg = new Config(); cfg.load(directory + "\\config.ini"); } user = CryptoEngine.Decrypt(cfg.getValue("username"), Config.cpuid()); pass = CryptoEngine.Decrypt(cfg.getValue("password"), Config.cpuid()); } //session 0 , need create rdp bool bNeedRDP = true; SessionHelper helper = new SessionHelper(); foreach (var s in helper.getsessionlist()) { if (s.username == user && s.sessionstate == SessionHelper.WTS_CONNECTSTATE_CLASS.WTSActive) { bool bExist = false; foreach (var p in Process.GetProcesses()) { if (p.ProcessName == "LogonUI") { //locked still need recreate rdp bExist = true; break; } } if (bExist) { bNeedRDP = true; } else { bNeedRDP = false; } break; } } if (bNeedRDP == false) { WriteLog("Already have active session without lock state, with user " + user + " so no need process this request"); return; } ProcessAsUser.Launch(directory + "\\mstsc2.exe " + "user:"******" pass:" + pass); }