public void UnLockWinStation(string username, string password, string other, int type) { //string User = Win32Sessions.GetActiveConsoleUserWithDomain(); //using (StreamWriter sw = File.AppendText("c:\\2\\run.log")) //{ // sw.WriteLine(DateTime.Now.ToString()+":"+ User); //} if (type != 0 && (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))) { //only type 0, support empty credential, and use default one, others won't, directly return return; } if (ClientWinService.m_SessionState != SessionChangeReason.SessionUnlock && ClientWinService.m_SessionState != SessionChangeReason.SessionLogon && ClientWinService.m_SessionState != SessionChangeReason.RemoteConnect) { Win32Helper.Win7AboveSendSAS(false); if (type == 0) { Utils.UnLockWinStation("", "", "", type); } else { Utils.SendUserNameAndPassword(username, password); } } }
public static bool UnLockWinStation(string username, string password, string others, int type) { bool bRet = true; if (type == 0) { //without username and password, use default encrypted ones //if (ClientWinService.m_SessionState == SessionChangeReason.RemoteConnect // || ClientWinService.m_SessionState == SessionChangeReason.SessionLogon // || ClientWinService.m_SessionState == SessionChangeReason.SessionUnlock // || ClientWinService.m_SessionState == SessionChangeReason.ConsoleConnect) SessionHelper shlp = new SessionHelper(); string user = shlp.GetConsoleUser(); bool bActive = shlp.IsConsoleActive(); if (bActive && shlp.IsConsoleSessionLocked() == false) { Utils.WriteLog("no need do actual action, as console is active with user " + user); return(true); } else { if (cfg == null) { string path = System.Reflection.Assembly.GetExecutingAssembly().Location; string directory = System.IO.Path.GetDirectoryName(path); if (File.Exists(directory + "\\" + "config.ini") == false) { WriteLog("The config.ini does not exist, so stop the default unlock action."); return(false); } cfg = new Config(); cfg.load(directory + "\\config.ini"); } string defaultUsername = CryptoEngine.Decrypt(cfg.getValue("username"), Config.cpuid()); string defaultPassword = CryptoEngine.Decrypt(cfg.getValue("password"), Config.cpuid()); //Utils.WriteLog("try to send username and password " + defaultUsername + defaultPassword); Win32Helper.Win7AboveSendSAS(false); SendUserNameAndPassword(defaultUsername, defaultPassword); //Utils.WriteLog("after send username and password, try to send sas"); } } return(bRet); }