Esempio n. 1
0
        /// <summary>
        /// 快速直接注销
        /// </summary>
        private void Fast_Loginoff()
        {
            //直接返回参数不对
            if (g_find_user == null || g_find_user.Trim() == "")
            {
                return;
            }
            string ulist = "";

            try
            {
                int           count  = 0;
                IntPtr        buffer = IntPtr.Zero;
                StringBuilder userId = new StringBuilder();
                //提取会话信息
                TSControl.WTS_SESSION_INFO[] pSessionInfo = TSControl.SessionEnumeration();
                for (int i = 0; i < pSessionInfo.Length; i++)
                {
                    bool bsuccess = TSControl.WTSQuerySessionInformation(IntPtr.Zero, pSessionInfo[i].SessionID, TSControl.WTSInfoClass.WTSUserName, out userId, out count);
                    if (bsuccess && userId.ToString().Trim() != "")
                    {
                        //AddLog("va:"+userId.ToString().Trim());
                        //不符号就注销
                        if (userId.ToString().Trim().ToLower() != g_find_user.Trim().ToLower())
                        {
                            ulist += userId.ToString().Trim() + ",";
                            //直接注销
                            sys_Logoff(pSessionInfo[i].SessionID);
                        }
                    }
                    //AddLog("va:" + userId.ToString().Trim() + pSessionInfo.Length.ToString());
                }
            }
            catch (Exception ex)
            {
                AddLog("get_LoginUser异常,原因:" + ex.Message);
            }
            try
            {
                if (ulist.Trim() != "")
                {
                    if (ulist.EndsWith(","))
                    {
                        ulist = ulist.Substring(0, ulist.Length - 1);
                    }
                    string smsMemo = "发现新登陆用户:[" + ulist + "]时间:" + DateTime.Now.ToString();
                    //发送短信
                    SendSMS(smsMemo);
                }
            }
            catch (Exception ex)
            {
                AddLog("get_LoginUser_短信发送异常,原因:" + ex.Message);
            }
        }
Esempio n. 2
0
        //多个用户之间用|分开必须显示用户和会话ID.可以终端非法用户
        private string  get_LoginUser()
        {
            string ret = "";

            //清空
            al_session.Clear();
            try
            {
                int           count  = 0;
                IntPtr        buffer = IntPtr.Zero;
                StringBuilder userId = new StringBuilder();
                //提取会话信息
                TSControl.WTS_SESSION_INFO[] pSessionInfo = TSControl.SessionEnumeration();
                for (int i = 0; i < pSessionInfo.Length; i++)
                {
                    bool bsuccess = TSControl.WTSQuerySessionInformation(IntPtr.Zero, pSessionInfo[i].SessionID, TSControl.WTSInfoClass.WTSUserName, out userId, out count);
                    if (bsuccess && userId.ToString().Trim() != "")
                    {
                        LoginUser lu = new LoginUser();
                        lu.RunStatus   = pSessionInfo[i].state.ToString();
                        lu.UserId      = userId.ToString().Trim();
                        lu.SessionId   = pSessionInfo[i].SessionID;
                        lu.SessionName = pSessionInfo[i].pWinStationName;
                        //加入会话记录
                        al_session.Add(lu);
                        //非授权用户,记录所有登陆到本机器的账号名
                        ret += lu.UserId.ToString().Trim() + ",";
                    }
                }
            }
            catch (Exception ex)
            {
                AddLog("get_LoginUser异常,原因:" + ex.Message);
            }
            if (ret.EndsWith(","))
            {
                ret = ret.Substring(0, ret.Length - 1);
            }
            return(ret);
        }