예제 #1
0
    protected override void OnSessionChange(SessionChangeDescription changeDescription)
    {
        EventLog.WriteEntry("shp_service.OnSessionChange", DateTime.Now.ToLongTimeString() +
            " - Session change notice received: " +
            changeDescription.Reason.ToString() + "  Session ID: " +
            changeDescription.SessionId.ToString());

        switch (changeDescription.Reason) {
            case SessionChangeReason.SessionLock:
                EventLog.WriteEntry("shp_service.OnSessionChange: Lock");
                Report(changeDescription.Reason.ToString());
                break;

            case SessionChangeReason.SessionUnlock:
                EventLog.WriteEntry("shp_service.OnSessionChange: Unlock");
                Report(changeDescription.Reason.ToString());
                break;

            case SessionChangeReason.SessionLogon:
                EventLog.WriteEntry("shp_service.OnSessionChange: Logon");
                Report(changeDescription.Reason.ToString());
                break;

            case SessionChangeReason.SessionLogoff:
                EventLog.WriteEntry("shp_service.OnSessionChange Logoff");
                Report(changeDescription.Reason.ToString());
                break;
            default:
                Report(changeDescription.Reason.ToString());
                break;
        }
    }
예제 #2
0
 /// <summary>在终端服务器会话中接收的更改事件时执行</summary>
 /// <param name="changeDescription"></param>
 protected override void OnSessionChange(SessionChangeDescription changeDescription)
 {
     WriteLog(nameof(OnSessionChange) + " SessionId={0} Reason={1}", changeDescription.SessionId, changeDescription.Reason);
 }
예제 #3
0
 // https://stackoverflow.com/questions/44980/programmatically-determine-a-duration-of-a-locked-workstation
 protected override void OnSessionChange(SessionChangeDescription sessionChangeDescription)
 {
     SessionSwitchMonitor.SystemSessionSwitch(sessionChangeDescription.SessionId, (SessionSwitchReason)sessionChangeDescription.Reason);
 }
예제 #4
0
 public virtual void OnSessionChange(SessionChangeDescription changeDescription)
 {
     throw new NotSupportedException();
 }
예제 #5
0
 protected override void OnSessionChange(SessionChangeDescription change)
 {
     EventLog.WriteEntry("Recipe14_06 Session change..." +
                         change.Reason);
 }
예제 #6
0
 protected override void OnSessionChange(SessionChangeDescription changeDescription)
 => Common.WriteMsg(changeDescription);
예제 #7
0
        /// <summary>
        /// Executes when a change event is received from a Terminal Server session.
        /// </summary>
        /// <param name="changeDescription">
        /// Identifies the type of session change and the session to which it applies.
        /// </param>
        protected override void OnSessionChange(SessionChangeDescription changeDescription)
        {
            switch (changeDescription.Reason)
            {
            // The user has logged off from a session, either locally or remotely.
            case SessionChangeReason.SessionLogoff:

                EncryptedSettings encryptedSettings = new EncryptedSettings(EncryptedSettings.SettingsFilePath);
                System.Collections.Generic.List <SecurityIdentifier> sidsToRemove = new System.Collections.Generic.List <SecurityIdentifier>(encryptedSettings.AddedUserSIDs);

                int[] sessionIds = LsaLogonSessions.LogonSessions.GetLoggedOnUserSessionIds();

                // For any user that is still logged on, remove their SID from the list of
                // SIDs to be removed from Administrators. That is, let the users who are still
                // logged on stay in the Administrators group.
                foreach (int id in sessionIds)
                {
                    SecurityIdentifier sid = LsaLogonSessions.LogonSessions.GetSidForSessionId(id);
                    if (sid != null)
                    {
                        if (sidsToRemove.Contains(sid))
                        {
                            sidsToRemove.Remove(sid);
                        }
                    }
                }

                // Process the list of SIDs to be removed from Administrators.
                for (int i = 0; i < sidsToRemove.Count; i++)
                {
                    if (
                        // If the user is not remote.
                        (!(encryptedSettings.ContainsSID(sidsToRemove[i]) && encryptedSettings.IsRemote(sidsToRemove[i])))
                        &&
                        // If admin rights are to be removed on logoff, or the user's rights do not expire.
                        (Settings.RemoveAdminRightsOnLogout || !encryptedSettings.GetExpirationTime(sidsToRemove[i]).HasValue)
                        )
                    {
                        LocalAdministratorGroup.RemoveUser(sidsToRemove[i], RemovalReason.UserLogoff);
                    }
                }

                /*
                 * In theory, this code should remove the user associated with the logoff, but it doesn't work.
                 * SecurityIdentifier sid = LsaLogonSessions.LogonSessions.GetSidForSessionId(changeDescription.SessionId);
                 * if (!(UserList.ContainsSID(sid) && UserList.IsRemote(sid)))
                 * {
                 *  LocalAdministratorGroup.RemoveUser(sid, RemovalReason.UserLogoff);
                 * }
                 */

                break;

            // The user has logged on to a session, either locally or remotely.
            case SessionChangeReason.SessionLogon:

                WindowsIdentity userIdentity = LsaLogonSessions.LogonSessions.GetWindowsIdentityForSessionId(changeDescription.SessionId);

                if (userIdentity != null)
                {
                    NetNamedPipeBinding          binding          = new NetNamedPipeBinding(NetNamedPipeSecurityMode.Transport);
                    ChannelFactory <IAdminGroup> namedPipeFactory = new ChannelFactory <IAdminGroup>(binding, Settings.NamedPipeServiceBaseAddress);
                    IAdminGroup channel = namedPipeFactory.CreateChannel();
                    bool        userIsAuthorizedForAutoAdd = channel.UserIsAuthorized(Settings.AutomaticAddAllowed, Settings.AutomaticAddDenied);
                    namedPipeFactory.Close();

                    // If the user is in the automatic add list, then add them to the Administrators group.
                    if (
                        (Settings.AutomaticAddAllowed != null) &&
                        (Settings.AutomaticAddAllowed.Length > 0) &&
                        (userIsAuthorizedForAutoAdd /*UserIsAuthorized(userIdentity, Settings.AutomaticAddAllowed, Settings.AutomaticAddDenied)*/)
                        )
                    {
                        LocalAdministratorGroup.AddUser(userIdentity, null, null);
                    }
                }
                else
                {
                    ApplicationLog.WriteEvent(Properties.Resources.UserIdentifyIsNull, EventID.DebugMessage, System.Diagnostics.EventLogEntryType.Warning);
                }

                break;

                /*
                 * // The user has reconnected or logged on to a remote session.
                 * case SessionChangeReason.RemoteConnect:
                 *  ApplicationLog.WriteInformationEvent(string.Format("Remote connect. Session ID: {0}", changeDescription.SessionId), EventID.SessionChangeEvent);
                 *  break;
                 */

                /*
                 * // The user has disconnected or logged off from a remote session.
                 * case SessionChangeReason.RemoteDisconnect:
                 *  ApplicationLog.WriteInformationEvent(string.Format("Remote disconnect. Session ID: {0}", changeDescription.SessionId), EventID.SessionChangeEvent);
                 *  break;
                 */

                /*
                 * // The user has locked their session.
                 * case SessionChangeReason.SessionLock:
                 *  ApplicationLog.WriteInformationEvent(string.Format("Session lock. Session ID: {0}", changeDescription.SessionId), EventID.SessionChangeEvent);
                 *  break;
                 */

                /*
                 * // The user has unlocked their session.
                 * case SessionChangeReason.SessionUnlock:
                 *  ApplicationLog.WriteInformationEvent(string.Format("Session unlock. Session ID: {0}", changeDescription.SessionId), EventID.SessionChangeEvent);
                 *  break;
                 */
            }

            base.OnSessionChange(changeDescription);
        }
예제 #8
0
 protected override void OnSessionChange(SessionChangeDescription changeDescription)
 {
     logService.Log(LogLevel.Info, "Cambio de sesion: " + changeDescription.Reason);
 }
 	protected override void OnSessionChange(SessionChangeDescription desc)
 	{
 		CustomService.UserInformation(desc.SessionId);
 	}
예제 #10
0
 protected override void OnSessionChange(SessionChangeDescription sesionChangeDescription)
 {
     //com channel_.SessionChanged(sesionChangeDescription.SessionId);
     base.OnSessionChange(sesionChangeDescription);
 }
예제 #11
0
        protected override void OnSessionChange(SessionChangeDescription cd)
        {
            base.OnSessionChange(cd);

            _core.UserChange();
        }
예제 #12
0
        protected override void OnSessionChange(SessionChangeDescription changeDescription)
        {
            int      mode = 0, clockId = 0, clock = 0, id = 0;
            DateTime timestamp = DateTime.MaxValue;
            string   remarks   = string.Empty;
            string   username  = string.Empty;

            timestamp = DateTime.Now;
            string cQuery  = String.Empty;
            string idQuery = String.Empty;

            try
            {
                switch (changeDescription.Reason)
                {
                case SessionChangeReason.SessionLogon:
                    objCom.WriteToEventLog("session Log On Starting......");
                    int    mode_remote;
                    string un_remQue = "select mode from tblMutex Order By TimeStamp Desc Limit 1";
                    try
                    {
                        mode_remote = Convert.ToInt32(objSql.ExecuteScalar(objSql.connString(), CommandType.Text, un_remQue));
                        objCom.WriteToEventLog("mode_remote" + mode_remote);
                        if (mode_remote == 5)
                        {
                            string Query = "select username from tblMutex where mode = 5 Order By TimeStamp Desc Limit 1";
                            try
                            {
                                username = objSql.ExecuteScalar(objSql.connString(), CommandType.Text, Query).ToString();
                            }
                            catch (Exception h)
                            {
                                objCom.WriteToEventLog("cant get username in remote & logon..." + h.Message);
                            }
                        }
                        else
                        {
                            username = objCom.GetInfo();
                        }
                    }
                    catch (Exception f)
                    {
                        objCom.WriteToEventLog("Cant get mode_remote..." + f.Message);
                    }

                    cQuery  = "select ClockStatus from tblMutex Order By TimeStamp Desc Limit 1";
                    idQuery = "select Id from tblMutex where Mode = 0 order by TimeStamp Desc Limit 1";
                    try
                    {
                        clock = Convert.ToInt32(objSql.ExecuteScalar(objSql.connString(), CommandType.Text, cQuery));
                        id    = Convert.ToInt32(objSql.ExecuteScalar(objSql.connString(), CommandType.Text, idQuery));
                    }
                    catch (Exception q)
                    {
                        objCom.WriteToEventLog("Exception In Session LogIn Inner Exception..." + q.Message);
                    }
                    mode    = Convert.ToInt32(CommonModule.sessionEvents.Logon);
                    clockId = Convert.ToInt32(CommonModule.Clock.clockin);
                    if (clock == 1)
                    {
                        try
                        {
                            string updateQuery = "update tblMutex set ClockStatus = 0 where Id = " + id;
                            objSql.ExecuteNonQuery(objSql.connString(), CommandType.Text, updateQuery);
                        }
                        catch (Exception p)
                        {
                            objCom.WriteToEventLog("Cant Find ID in Session Log Event...." + p.Message);
                        }
                    }
                    try
                    {
                        string query = "insert into tblmutex (userName,TimeStamp,Mode,ClockStatus) values ('" + username + "','" + timestamp.ToString("yyyy-MM-dd HH:mm:ss") + "','" + mode + "','" + clockId + "')";
                        objSql.ExecuteNonQuery(objSql.connString(), CommandType.Text, query);
                        objuse.Mode        = mode;
                        objuse.UserName    = username;
                        objuse.TimeStamp   = timestamp;
                        objuse.ClockStatus = clockId;
                        objCom.WriteToEventLog("Property Got in WCF Login....");
                        try
                        {
                            obj.InsertUserDetails(objuse);
                        }
                        catch (Exception o)
                        {
                            objCom.WriteToEventLog("Error in SQLSERVER LogIn...." + o.Message);
                        }
                        //UserInfo.UserName = username;
                        //UserInfo.TimeStamp = timestamp;
                        //UserInfo.Mode = mode;
                        //UserInfo.ClockStatus = clockId;
                        //objService.InsertUserDetails(UserInfo);
                        //objService.InsertUserDetails(userinfo);
                    }
                    catch (Exception r)
                    {
                        objCom.WriteToEventLog("Cant Insert in to Table in Session Login..." + r.Message);
                    }
                    objCom.WriteToEventLog("session Log On : " + username, "Logs", EventLogEntryType.Information);
                    objCom.WriteToEventLog("session Log On Stop......");
                    break;

                case SessionChangeReason.SessionLogoff:
                    objCom.WriteToEventLog("session LogOff Starting......");
                    string user = String.Empty;
                    string Que1 = "select username from tblmutex order by timestamp desc limit 1 ";
                    cQuery = "select ClockStatus from tblmutex order by timestamp desc limit 1";

                    try
                    {
                        clock = Convert.ToInt32(objSql.ExecuteScalar(objSql.connString(), CommandType.Text, cQuery));
                    }
                    catch (Exception p)
                    {
                        objCom.WriteToEventLog("cant find ClockId in Session LogOff Event..." + p.Message);
                    }
                    mode    = Convert.ToInt32(CommonModule.sessionEvents.Logout);
                    clockId = Convert.ToInt32(CommonModule.Clock.clockout);
                    if (clock == 1)
                    {
                        try
                        {
                            user = objSql.ExecuteScalar(objSql.connString(), CommandType.Text, Que1).ToString();
                            string query1 = "insert into tblMutex (userName,TimeStamp,Mode,ClockStatus) values ('" + user + "','" + timestamp.ToString("yyyy-MM-dd HH:mm:ss") + "','" + mode + "','" + clockId + "')";
                            try
                            {
                                objSql.ExecuteNonQuery(objSql.connString(), CommandType.Text, query1);
                                objuse.Mode        = mode;
                                objuse.UserName    = username;
                                objuse.TimeStamp   = timestamp;
                                objuse.ClockStatus = clockId;
                                objCom.WriteToEventLog("Property Got in WCF logOff clock==1....");
                                try
                                {
                                    obj.InsertUserDetails(objuse);
                                }
                                catch (Exception o)
                                {
                                    objCom.WriteToEventLog("Error in SQLSERVER logOff clock==1...." + o.Message);
                                }
                            }
                            catch (Exception v)
                            {
                                objCom.WriteToEventLog("cant get name in sessssssssion log out...." + v.Message);
                            }
                        }
                        catch (Exception r)
                        {
                            objCom.WriteToEventLog("Cant Insert in to Table in Session LogOff Clock == 1..." + r.Message);
                        }
                    }
                    else
                    {
                        try
                        {
                            user = "******";
                            user = objSql.ExecuteScalar(objSql.connString(), CommandType.Text, user).ToString();
                            string query1 = "insert into tblMutex (userName,TimeStamp,Mode,ClockStatus) values ('" + user + "','" + timestamp.ToString("yyyy-MM-dd HH:mm:ss") + "','" + mode + "','" + clockId + "')";
                            objSql.ExecuteNonQuery(objSql.connString(), CommandType.Text, query1);
                            objuse.Mode        = mode;
                            objuse.UserName    = username;
                            objuse.TimeStamp   = timestamp;
                            objuse.ClockStatus = clockId;
                            objCom.WriteToEventLog("Property Got in WCF logOff clock!=1....");
                            try
                            {
                                obj.InsertUserDetails(objuse);
                            }
                            catch (Exception o)
                            {
                                objCom.WriteToEventLog("Error in SQLSERVER logOff clock!=1...." + o.Message);
                            }
                        }
                        catch (Exception z)
                        {
                            objCom.WriteToEventLog("Cant Insert in to Table in Session LogOff ClockStatus==1..." + z.Message);
                        }
                    }
                    objCom.WriteToEventLog("session Log Off i.e shutdown or signout : " + username, "Logs", EventLogEntryType.Information);
                    objCom.WriteToEventLog("Session LogOff Stop...");
                    break;

                case SessionChangeReason.SessionLock:
                    objCom.WriteToEventLog("Session Lock Is starting...");
                    try
                    {
                        string unnameQue = "select username from tblmutex order by timestamp desc";
                        string user_lock = objSql.ExecuteScalar(objSql.connString(), CommandType.Text, unnameQue).ToString();
                        mode    = Convert.ToInt32(CommonModule.sessionEvents.Lock);
                        clockId = Convert.ToInt32(CommonModule.Clock.clockin);
                        try
                        {
                            string query1 = "insert into tblMutex (userName,TimeStamp,Mode,ClockStatus) values ('" + user_lock + "','" + timestamp.ToString("yyyy-MM-dd HH:mm:ss") + "','" + mode + "','" + clockId + "')";
                            objSql.ExecuteNonQuery(objSql.connString(), CommandType.Text, query1);
                            objuse.Mode        = mode;
                            objuse.UserName    = user_lock;
                            objuse.TimeStamp   = timestamp;
                            objuse.ClockStatus = clockId;
                            objCom.WriteToEventLog("Property Got in WCF logck....");
                            try
                            {
                                obj.InsertUserDetails(objuse);
                            }
                            catch (Exception o)
                            {
                                objCom.WriteToEventLog("Error in SQLSERVER lock...." + o.StackTrace);
                            }
                        }
                        catch (Exception i)
                        {
                            objCom.WriteToEventLog("cant insert into table in lock ...." + i.Message);
                        }
                    }
                    catch (Exception u)
                    {
                        objCom.WriteToEventLog("Error in Session Lock username..." + u.Message);
                    }
                    objCom.WriteToEventLog("session Lock : " + username, "Logs", EventLogEntryType.Information);
                    objCom.WriteToEventLog("Session Lock Stop...");
                    break;

                //back up code....
                //try
                //{
                //    string que = "select mode from tblMutex order by timestamp desc limit 1";
                //    int lmode = Convert.ToInt32(objSql.ExecuteScalar(objSql.connString(),CommandType.Text,que));
                //    objCom.WriteToEventLog("lmode in session lock event////   " + lmode);
                //    if (lmode == 0)
                //    {
                //        try
                //        {
                //            username = objCom.GetInfo();
                //            clockId = Convert.ToInt32(CommonModule.Clock.clockin);
                //            mode = Convert.ToInt32(CommonModule.sessionEvents.Lock);
                //            string query2 = "insert into tblMutex (userName,TimeStamp,Mode,ClockStatus) values ('" + username + "','" + timestamp.ToString("yyyy-MM-dd HH:mm:ss") + "','" + mode + "','" + clockId + "')";
                //            objSql.ExecuteNonQuery(objSql.connString(), CommandType.Text, query2);
                //        }
                //        catch (Exception z)
                //        {
                //            objCom.WriteToEventLog("Cant Insert in to Table in SessionLock..." + z.Message);
                //        }
                //    }
                //    else
                //    {
                //        try
                //        {
                //            string query_uname = "select username from tblMutex order by timestamp desc limit 1";
                //            clockId = Convert.ToInt32(CommonModule.Clock.clockin);
                //            mode = Convert.ToInt32(CommonModule.sessionEvents.Lock);
                //            username = objSql.ExecuteScalar(objSql.connString(), CommandType.Text, query_uname).ToString();
                //            objCom.WriteToEventLog("username got in lock phase");
                //            try
                //            {
                //                mode = Convert.ToInt32(CommonModule.sessionEvents.Lock);
                //                clockId = Convert.ToInt32(CommonModule.Clock.clockin);
                //                string query2 = "insert into tblMutex (userName,TimeStamp,Mode,ClockStatus) values ('" + username + "','" + timestamp.ToString("yyyy-MM-dd HH:mm:ss") + "','" + mode + "','" + clockId + "')";
                //                objSql.ExecuteNonQuery(objSql.connString(), CommandType.Text, query2);
                //            }
                //            catch (Exception z)
                //            {
                //                objCom.WriteToEventLog("Cant Insert in to Table in SessionLock..." + z.Message);
                //            }
                //        }
                //        catch (Exception r)
                //        {
                //            objCom.WriteToEventLog("Cant get username in sessionlock else block..."+r.Message);
                //        }
                //    }
                //}
                //catch (Exception r)
                //{
                //    objCom.WriteToEventLog("Cant get mode in session lock for remote login ..."+r.Message);
                //}
                //objCom.WriteToEventLog("session Lock : " + username, "Logs", EventLogEntryType.Information);
                //objCom.WriteToEventLog("Session Lock Stop...");
                //break;
                case SessionChangeReason.SessionUnlock:
                    objCom.WriteToEventLog("Session Lock Is starting...");
                    string quelock = "select username from tblMutex order by timestamp desc limit 1";
                    //int lockmode = 0;
                    mode    = Convert.ToInt32(CommonModule.sessionEvents.UnLock);
                    clockId = Convert.ToInt32(CommonModule.Clock.clockin);
                    //username = objCom.GetInfo();
                    try
                    {
                        username = objSql.ExecuteScalar(objSql.connString(), CommandType.Text, quelock).ToString();
                        try
                        {
                            string query3 = "insert into tblMutex (userName,TimeStamp,Mode,ClockStatus) values ('" + username + "','" + timestamp.ToString("yyyy-MM-dd HH:mm:ss") + "','" + mode + "','" + clockId + "')";
                            objSql.ExecuteNonQuery(objSql.connString(), CommandType.Text, query3);
                            objuse.Mode        = mode;
                            objuse.UserName    = username;
                            objuse.TimeStamp   = timestamp;
                            objuse.ClockStatus = clockId;
                            objCom.WriteToEventLog("Property Got in WCF Unlock....");
                            try
                            {
                                obj.InsertUserDetails(objuse);
                            }
                            catch (Exception o)
                            {
                                objCom.WriteToEventLog("Error in SQLSERVER Unlock...." + o.StackTrace);
                            }
                        }
                        catch (Exception z)
                        {
                            objCom.WriteToEventLog("Cant Insert in to Table in SessionUnLock..." + z.Message);
                        }
                        objCom.WriteToEventLog("session unLock : " + username, "Logs", EventLogEntryType.Information);
                    }
                    catch (Exception o)
                    {
                        objCom.WriteToEventLog("Error in session lock username" + o.Message);
                    }
                    objCom.WriteToEventLog("Session Lock Is stop...");
                    break;



                //Back Up.....
                //objCom.WriteToEventLog("Session Lock Is starting...");
                //string quelock = "select mode from tblMutex order by timestamp desc limit 1";
                //int lockmode = 0;
                //clockId = Convert.ToInt32(CommonModule.Clock.clockin);
                //username = objCom.GetInfo();
                //mode = Convert.ToInt32(CommonModule.sessionEvents.UnLock);
                //try
                //{
                //    string query3 = "insert into tblMutex (userName,TimeStamp,Mode,ClockStatus) values ('" + username + "','" + timestamp.ToString("yyyy-MM-dd HH:mm:ss") + "','" + mode + "','" + clockId + "')";
                //    objSql.ExecuteNonQuery(objSql.connString(), CommandType.Text, query3);
                //}
                //catch (Exception z)
                //{
                //    objCom.WriteToEventLog("Cant Insert in to Table in SessionUnLock..." + z.Message);
                //}
                //objCom.WriteToEventLog("session unLock : " + username, "Logs", EventLogEntryType.Information);
                //objCom.WriteToEventLog("Session Lock Is stop...");
                //break;
                case SessionChangeReason.RemoteConnect:
                    objCom.WriteToEventLog("Session RemoteConnect Is starting...");
                    //username = objCom.GetInfo();
                    int cId = 0;
                    mode = Convert.ToInt32(CommonModule.sessionEvents.RemoteConnect);
                    string clockQue = "select ClockStatus from tblMutex order by timestamp desc limit 1";
                    try
                    {
                        cId = Convert.ToInt32(objSql.ExecuteScalar(objSql.connString(), CommandType.Text, clockQue));
                    }
                    catch (Exception t)
                    {
                        objCom.WriteToEventLog("Exception in Remoteconnect clockstatus Query..." + t.Message);
                    }
                    if (cId == 0)
                    {
                        string clockQueIn = "select UserName from tblMutex where Clockstatus = 1 order by timestamp desc limit 1 ";
                        string uname_In;

                        try
                        {
                            try
                            {
                                uname_In = objSql.ExecuteScalar(objSql.connString(), CommandType.Text, clockQueIn).ToString();
                                try
                                {
                                    clockId = Convert.ToInt32(CommonModule.Clock.clockin);
                                    string query4 = "insert into tblMutex (userName,TimeStamp,Mode,ClockStatus) values ('" + uname_In + "','" + timestamp.ToString("yyyy-MM-dd HH:mm:ss") + "','" + mode + "','" + clockId + "')";
                                    objSql.ExecuteNonQuery(objSql.connString(), CommandType.Text, query4);
                                    objuse.Mode        = mode;
                                    objuse.UserName    = username;
                                    objuse.TimeStamp   = timestamp;
                                    objuse.ClockStatus = clockId;
                                    objCom.WriteToEventLog("Property Got in WCF Remote cId == 0....");
                                    try
                                    {
                                        obj.InsertUserDetails(objuse);
                                    }
                                    catch (Exception o)
                                    {
                                        objCom.WriteToEventLog("Error in SQLSERVER Remote cId == 0........" + o.Message);
                                    }
                                }
                                catch (Exception i)
                                {
                                    objCom.WriteToEventLog("Cant insert in to CID= 0 Inner block..." + i.Message);
                                }
                            }
                            catch (Exception y)
                            {
                                objCom.WriteToEventLog("Username is not found in remote connect" + y.Message);
                            }
                        }
                        catch (Exception t)
                        {
                            objCom.WriteToEventLog("Exception in Remoteconnect clockstatus=0 Query..." + t.Message);
                        }
                    }
                    else
                    {
                        string clockQueIn = "select UserName from tblMutex where Clockstatus = 1 order by timestamp desc limit 1 ";
                        string uname_In   = String.Empty;
                        clockId = Convert.ToInt32(CommonModule.Clock.clockin);
                        try
                        {
                            uname_In = objSql.ExecuteScalar(objSql.connString(), CommandType.Text, clockQueIn).ToString();
                            try
                            {
                                string query4 = "insert into tblMutex (userName,TimeStamp,Mode,ClockStatus) values ('" + uname_In + "','" + timestamp.ToString("yyyy-MM-dd HH:mm:ss") + "','" + mode + "','" + clockId + "')";
                                objSql.ExecuteNonQuery(objSql.connString(), CommandType.Text, query4);
                                objuse.Mode        = mode;
                                objuse.UserName    = username;
                                objuse.TimeStamp   = timestamp;
                                objuse.ClockStatus = clockId;
                                objCom.WriteToEventLog("Property Got in WCF Remote cId !=0........");
                                try
                                {
                                    obj.InsertUserDetails(objuse);
                                }
                                catch (Exception o)
                                {
                                    objCom.WriteToEventLog("Error in SQLSERVER Remote cId !=0...." + o.Message);
                                }
                            }
                            catch (Exception r)
                            {
                                objCom.WriteToEventLog("Cant insert in to Remote Connect clockstatus=1 ..." + r.Message);
                            }
                        }
                        catch (Exception t)
                        {
                            objCom.WriteToEventLog("Exception in Remoteconnect clockstatus=1 Query..." + t.Message);
                        }
                    }
                    objCom.WriteToEventLog("session RemoteConnect : " + username, "Logs", EventLogEntryType.Information);
                    objCom.WriteToEventLog("Session RemoteConnect Is Stopp...");
                    break;

                case SessionChangeReason.RemoteDisconnect:
                    objCom.WriteToEventLog("Session RemoteDisconnect Is Started...");
                    mode    = Convert.ToInt32(CommonModule.sessionEvents.RemoteDisconnect);
                    clockId = Convert.ToInt32(CommonModule.Clock.clockin);
                    try
                    {
                        string unQue = string.Empty;
                        string uname = string.Empty;
                        unQue = "select username from tblMutex where mode = 5 order by timestamp desc limit 1";
                        try
                        {
                            uname = objSql.ExecuteScalar(objSql.connString(), CommandType.Text, unQue).ToString();
                        }
                        catch (Exception i)
                        {
                            objCom.WriteToEventLog("Exception in remote disconnect username is not found..." + i.Message);
                        }
                        try
                        {
                            string query5 = "insert into tblMutex (userName,TimeStamp,Mode,ClockStatus) values ('" + uname + "','" + timestamp.ToString("yyyy-MM-dd HH:mm:ss") + "','" + mode + "','" + clockId + "')";
                            objSql.ExecuteNonQuery(objSql.connString(), CommandType.Text, query5);
                            objuse.Mode        = mode;
                            objuse.UserName    = username;
                            objuse.TimeStamp   = timestamp;
                            objuse.ClockStatus = clockId;
                            objCom.WriteToEventLog("Property Got in WCF RemoteDis....");
                            try
                            {
                                obj.InsertUserDetails(objuse);
                            }
                            catch (Exception o)
                            {
                                objCom.WriteToEventLog("Error in SQLSERVER RemoteDis...." + o.Message);
                            }
                        }
                        catch (Exception i)
                        {
                            objCom.WriteToEventLog("Exception in remote disconnect NonQuery is not found..." + i.Message);
                        }
                    }
                    catch (Exception p)
                    {
                        objCom.WriteToEventLog("Cant Insert in to Table in Remote Disconnect..." + p.Message);
                    }
                    objCom.WriteToEventLog("session RemoteDisconnect : " + username, "Logs", EventLogEntryType.Information);
                    objCom.WriteToEventLog("Session RemoteDisconnect Is Stopp...");
                    break;

                default:
                    string   modeQue = "Select mode from tblMutex order by timestamp desc limit 1";
                    string   unm = "select username from tblMutex order by timestamp desc limit 1";
                    string   time_rcon = "select timestamp from tblMutex where mode = 5 order by timestamp desc limit 1;";
                    string   time_rdiscon = "select timestamp from tblMutex where mode = 5 order by timestamp desc limit 1;";
                    DateTime remcon, remdiscon;
                    try
                    {
                        try
                        {
                            remcon = (DateTime)(objSql.ExecuteScalar(objSql.connString(), CommandType.Text, time_rcon));
                            try
                            {
                                remdiscon = (DateTime)(objSql.ExecuteScalar(objSql.connString(), CommandType.Text, time_rdiscon));
                                if (remcon.Second - remdiscon.Second == 1)
                                {
                                    objCom.WriteToEventLog("remconn and rem discconn error thrown...");
                                    break;
                                }
                                else
                                {
                                    int    mode_deflt   = Convert.ToInt32(objSql.ExecuteScalar(objSql.connString(), CommandType.Text, modeQue));
                                    int    clock_in     = Convert.ToInt32(CommonModule.Clock.clockin);
                                    int    mode_remote1 = Convert.ToInt32(CommonModule.sessionEvents.Logon);
                                    string user_name    = string.Empty;
                                    try
                                    {
                                        user_name = objSql.ExecuteScalar(objSql.connString(), CommandType.Text, unm).ToString();
                                    }
                                    catch (Exception f)
                                    {
                                        objCom.WriteToEventLog("cant find user name in default case..." + f.Message);
                                    }
                                    switch (mode_deflt)
                                    {
                                    case 6:

                                        string query6 = "insert into tblMutex (userName,TimeStamp,Mode,ClockStatus) values ('" + user_name + "','" + timestamp.ToString("yyyy-MM-dd HH:mm:ss") + "','" + mode_remote1 + "','" + clock_in + "')";
                                        objSql.ExecuteNonQuery(objSql.connString(), CommandType.Text, query6);
                                        objCom.WriteToEventLog("Default Statement : Data Entered in default Statement.....");
                                        objuse.Mode        = mode;
                                        objuse.UserName    = username;
                                        objuse.TimeStamp   = timestamp;
                                        objuse.ClockStatus = clockId;
                                        objCom.WriteToEventLog("Property Got in WCF case6 default....");
                                        try
                                        {
                                            obj.InsertUserDetails(objuse);
                                        }
                                        catch (Exception o)
                                        {
                                            objCom.WriteToEventLog("Error in SQLSERVER case6 default...." + o.Message);
                                        }
                                        break;

                                    default:
                                        break;
                                    }
                                }
                            }
                            catch (Exception y)
                            {
                                objCom.WriteToEventLog("Error in getting remdiscon ..." + y.Message);
                            }
                        }
                        catch (Exception e)
                        {
                            objCom.WriteToEventLog("error to get remcon...in default" + e.Message);
                        }
                    }
                    catch (Exception e)
                    {
                        objCom.WriteToEventLog("Error in gettin time of connect and disconnect...." + e.Message);
                    }


                    objCom.WriteToEventLog("Default Statement :" + username, "Logs", EventLogEntryType.Information);
                    break;
                }
            }
            catch (Exception z)
            {
                objCom.WriteToEventLog("OnSessionChange Z : " + z.Message, "Logs", EventLogEntryType.Error);
            }
        }
예제 #13
0
 /// <summary>
 /// OnSessionChange(): To handle a change event from a Terminal Server session.
 ///   Useful if you need to determine when a user logs in remotely or logs off,
 ///   or when someone logs into the console.
 /// </summary>
 /// <param name="changeDescription"></param>
 public void OnSessionChange(SessionChangeDescription changeDescription)
 {
 }
예제 #14
0
 internal void OnSessionChangeService(SessionChangeDescription changeDescription)
 {
     OnSessionChange(changeDescription);
 }
 public bool Equals(SessionChangeDescription changeDescription)
 {
 }
예제 #16
0
 /// <summary>
 /// OnSessionChange(): To handle a change event
 ///   from a Terminal Server session.
 ///   Useful if you need to determine
 ///   when a user logs in remotely or logs off,
 ///   or when someone logs into the console.
 /// </summary>
 /// <param name="changeDescription">The Session Change
 /// Event that occured.</param>
 protected override void OnSessionChange(
     SessionChangeDescription changeDescription)
 {
     base.OnSessionChange(changeDescription);
 }
 public static bool op_Inequality(SessionChangeDescription a, SessionChangeDescription b)
 {
 }
예제 #18
0
 protected override void OnSessionChange(SessionChangeDescription changeDescription)
 {
     WriteLog(nameof(OnSessionChange) + " change=" + changeDescription.ToString());
     base.OnSessionChange(changeDescription);
 }
예제 #19
0
 public WindowsSessionChangedArguments(SessionChangeDescription changeDescription)
 {
     ReasonCode = (SessionChangeReasonCode)Enum.ToObject(typeof(SessionChangeReasonCode), (int)changeDescription.Reason);
     SessionId  = changeDescription.SessionId;
 }
 public void OnSessionChange(SessionChangeDescription changeDescription)
 {
     Console.WriteLine("OnSessionChange");
 }
예제 #21
0
        //Logs the session if it's a LogOn or LogOff event.
        public bool Log(SessionChangeDescription changeDescription, SessionProperties properties)
        {
            if (m_conn == null)
            {
                throw new InvalidOperationException("No MySQL Connection present.");
            }

            string username = "******";

            if (properties != null)
            {
                UserInformation ui = properties.GetTrackedSingle <UserInformation>();
                if ((bool)Settings.Store.UseModifiedName)
                {
                    username = ui.Username;
                }
                else
                {
                    username = ui.OriginalUsername;
                }
            }

            //Logon Event
            if (changeDescription.Reason == SessionChangeReason.SessionLogon)
            {
                if (m_conn.State != System.Data.ConnectionState.Open)
                {
                    m_conn.Open();
                }

                string table = Settings.Store.SessionTable;

                //Update the existing entry for this machine/ip if it exists.
                string updatesql = string.Format("UPDATE {0} SET logoutstamp=NOW() " +
                                                 "WHERE logoutstamp=0 and machine=@machine and ipaddress=@ipaddress", table);

                MySqlCommand cmd = new MySqlCommand(updatesql, m_conn);
                cmd.Prepare();
                cmd.Parameters.AddWithValue("@machine", Environment.MachineName);
                cmd.Parameters.AddWithValue("@ipaddress", getIPAddress());
                cmd.ExecuteNonQuery();

                //Insert new entry for this logon event
                string insertsql = string.Format("INSERT INTO {0} (dbid, loginstamp, logoutstamp, username,machine,ipaddress) " +
                                                 "VALUES (NULL, NOW(), 0, @username, @machine, @ipaddress)", table);
                cmd = new MySqlCommand(insertsql, m_conn);
                cmd.Prepare();
                cmd.Parameters.AddWithValue("@username", username);
                cmd.Parameters.AddWithValue("@machine", Environment.MachineName);
                cmd.Parameters.AddWithValue("ipaddress", getIPAddress());
                cmd.ExecuteNonQuery();

                m_logger.DebugFormat("Logged LogOn event for {0} at {1}", username, getIPAddress());
            }

            //LogOff Event
            else if (changeDescription.Reason == SessionChangeReason.SessionLogoff)
            {
                if (m_conn.State != System.Data.ConnectionState.Open)
                {
                    m_conn.Open();
                }

                string table = Settings.Store.SessionTable;

                string updatesql = string.Format("UPDATE {0} SET logoutstamp=NOW() " +
                                                 "WHERE logoutstamp=0 AND username=@username AND machine=@machine " +
                                                 "AND ipaddress=@ipaddress", table);

                MySqlCommand cmd = new MySqlCommand(updatesql, m_conn);
                cmd.Prepare();
                cmd.Parameters.AddWithValue("@username", username);
                cmd.Parameters.AddWithValue("@machine", Environment.MachineName);
                cmd.Parameters.AddWithValue("@ipaddress", getIPAddress());
                cmd.ExecuteNonQuery();

                m_logger.DebugFormat("Logged LogOff event for {0} at {1}", username, getIPAddress());
            }

            return(true);
        }
예제 #22
0
 public ChoServiceSessionChangeEventArgs(SessionChangeDescription changeDescription)
 {
     ChangeDescription = changeDescription;
 }
 /// <summary>
 /// Executes when a change event is received from a Terminal Server session.
 /// </summary>
 /// <param name="changeDescription">A <see cref="T:System.ServiceProcess.SessionChangeDescription" /> structure that identifies the change type.</param>
 protected override void OnSessionChange(SessionChangeDescription changeDescription)
 {
     this.WindowsService.OnSessionChange(changeDescription);
 }
예제 #24
0
		public bool Equals (SessionChangeDescription changeDescription)
		{
			return reason == changeDescription.reason && id == changeDescription.id;
		}
예제 #25
0
파일: Servo.cs 프로젝트: LSTANCZYK/Servo
 protected override void OnSessionChange(SessionChangeDescription changeDescription)
 {
     try { _scaffold.OnSessionChange(changeDescription); }
     catch (NotImplementedException) { base.OnSessionChange(changeDescription); }
 }
예제 #26
0
        //Logs the session if it's a LogOn or LogOff event.
        public bool Log(SessionChangeDescription changeDescription, SessionProperties properties)
        {
            if (m_conn == null)
            {
                throw new InvalidOperationException("No SQL Connection present.");
            }

            string username    = "******";
            string strClientIP = null;

            strClientIP = TSManager.ListSessions(changeDescription.SessionId);

            if (properties != null)
            {
                UserInformation ui = properties.GetTrackedSingle <UserInformation>();
                if (true)
                {
                    username = ui.Username;
                }
                else
                {
                    username = ui.OriginalUsername;
                }
            }


            //Logon Event
            if (changeDescription.Reason == SessionChangeReason.SessionLogon)
            {
                if (m_conn.State != System.Data.ConnectionState.Open)
                {
                    m_conn.Open();
                }

                string table = "UAMS_SessionLog";

                //Update the existing entry for this machine/ip if it exists.
                string updatesql = string.Format("UPDATE {0} SET LogoutStamp = GETDATE() " +
                                                 "WHERE LogoutStamp IS NULL and Machine = '" + Environment.MachineName + "' and IpAddress = '" + getIPAddress() + "' and SessionID = " + changeDescription.SessionId + " and ClientIP = '" + strClientIP + "'", table);

                SqlCommand cmd = new SqlCommand(updatesql, m_conn);
                cmd.Prepare();
                cmd.ExecuteNonQuery();

                //Insert new entry for this logon event
                string insertsql = string.Format("INSERT INTO {0} (LoginStamp, LogoutStamp, UserName, Machine, IpAddress, SessionID, ClientIP) " +
                                                 "VALUES (GETDATE(), NULL, '" + username + "', '" + Environment.MachineName + "', '" + getIPAddress() + "', " + changeDescription.SessionId + ", '" + strClientIP + "')", table);

                cmd = new SqlCommand(insertsql, m_conn);
                cmd.Prepare();
                cmd.ExecuteNonQuery();

                m_logger.DebugFormat("Logged LogOn event for {0} at {1}", username, strClientIP);
            }

            //LogOff Event
            else if (changeDescription.Reason == SessionChangeReason.SessionLogoff)
            {
                if (m_conn.State != System.Data.ConnectionState.Open)
                {
                    m_conn.Open();
                }

                string table = "UAMS_SessionLog";

                string updatesql = string.Format("UPDATE {0} SET LogoutStamp = GETDATE() " +
                                                 "WHERE LogoutStamp IS NULL AND UserName = '******' AND Machine = '" + Environment.MachineName + "' AND IpAddress = '" + getIPAddress() + "' and SessionID = " + changeDescription.SessionId + "", table); //and ClientIP = '" + strClientIP + "'
                //m_logger.DebugFormat("Logoff:{0}", updatesql);
                SqlCommand cmd = new SqlCommand(updatesql, m_conn);
                cmd.Prepare();
                cmd.ExecuteNonQuery();

                m_logger.DebugFormat("Logged LogOff event for {0} at {1}", username, strClientIP);
            }

            return(true);
        }
예제 #27
0
 public bool Equals(SessionChangeDescription changeDescription)
 {
     return((_reason == changeDescription._reason) && (_id == changeDescription._id));
 }
예제 #28
0
 protected override void OnSessionChange(SessionChangeDescription reason)
 {
     DoAction(reason.Reason);
 }
        protected override void OnSessionChange(SessionChangeDescription changeDescription)
        {         // handle a session change notice
            // if service has paused do nothing
            if (servicepaused)
            {
                return;
            }

            if ((loglevel > 1) || forceverbose)
            {             // print session information only in verbose mode
                // GetSessionCount() is "expensive", so first check for verbose mode
                WriteToLog("Session change notice received: " + changeDescription.Reason.ToString() + ", session ID: " + changeDescription.SessionId.ToString());
                WriteToLog(GetSessionCount().ToString() + " users are logged on.");
            }

            if (changeDescription.Reason == SessionChangeReason.SessionLogon)
            {             // action only for logon
                string userName = GetUserFromSession((uint)changeDescription.SessionId);

                // get user profile path in registry
                string directoryName = GetUserProfilePath((uint)changeDescription.SessionId);
                if (directoryName != "")
                {                 // profile found, append path to start menu
                    directoryName += "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\StartupElevated";
                }
                else
                {                 // not found, try standard path
                    directoryName = "C:\\Users\\" + userName + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\StartupElevated";
                    WriteVerboseToLog("Could not retrieve user profile from operating system, trying '" + directoryName + "'");
                }
                WriteToLog("Session logon by user " + userName + " to session id " + changeDescription.SessionId.ToString() + ".");
                if (Directory.Exists(directoryName))
                {
                    WriteVerboseToLog("Directory '" + directoryName + "' found.");
                    string[] fileList = Directory.GetFiles(directoryName);
                    if (fileList.Length > 0)
                    {
                        foreach (string command in fileList)
                        {                         // compute list of programs to start
                            if (command.ToLower().EndsWith("\\desktop.ini"))
                            {                     // do not start desktop.ini!
                                WriteVerboseToLog("Ignoring '" + command + "'.");
                            }
                            else
                            {
                                WriteVerboseToLog("Starting '" + command + "'.");
                                StartProcessInSession((uint)changeDescription.SessionId, command);
                            }
                        }
                    }
                    else
                    {
                        WriteVerboseToLog("Directory '" + directoryName + "' is empty.");
                    }
                }
                else
                {
                    WriteVerboseToLog("Directory '" + directoryName + "' not found.");
                }
            }
        }
예제 #30
0
        // Handle a session change notice
        protected override void OnSessionChange(SessionChangeDescription changeDescription)
        {
#if LOGEVENTS
            EventLog.WriteEntry("SimpleService.OnSessionChange", DateTime.Now.ToLongTimeString() +
                                " - Session change notice received: " +
                                changeDescription.Reason.ToString() + "  Session ID: " +
                                changeDescription.SessionId.ToString());
#endif

            switch (changeDescription.Reason)
            {
            case SessionChangeReason.SessionLogon:
                userCount += 1;
#if LOGEVENTS
                EventLog.WriteEntry("SimpleService.OnSessionChange",
                                    DateTime.Now.ToLongTimeString() +
                                    " SessionLogon, total users: " +
                                    userCount.ToString());
#endif
                break;

            case SessionChangeReason.SessionLogoff:

                userCount -= 1;
#if LOGEVENTS
                EventLog.WriteEntry("SimpleService.OnSessionChange",
                                    DateTime.Now.ToLongTimeString() +
                                    " SessionLogoff, total users: " +
                                    userCount.ToString());
#endif
                break;

            case SessionChangeReason.RemoteConnect:
                userCount += 1;
#if LOGEVENTS
                EventLog.WriteEntry("SimpleService.OnSessionChange",
                                    DateTime.Now.ToLongTimeString() +
                                    " RemoteConnect, total users: " +
                                    userCount.ToString());
#endif
                break;

            case SessionChangeReason.RemoteDisconnect:

                userCount -= 1;
#if LOGEVENTS
                EventLog.WriteEntry("SimpleService.OnSessionChange",
                                    DateTime.Now.ToLongTimeString() +
                                    " RemoteDisconnect, total users: " +
                                    userCount.ToString());
#endif
                break;

            case SessionChangeReason.SessionLock:
#if LOGEVENTS
                EventLog.WriteEntry("SimpleService.OnSessionChange",
                                    DateTime.Now.ToLongTimeString() +
                                    " SessionLock");
#endif
                break;

            case SessionChangeReason.SessionUnlock:
#if LOGEVENTS
                EventLog.WriteEntry("SimpleService.OnSessionChange",
                                    DateTime.Now.ToLongTimeString() +
                                    " SessionUnlock");
#endif
                break;

            default:

                break;
            }
        }
 public bool Equals(SessionChangeDescription changeDescription)
 {
     return((Reason == changeDescription.Reason) && (SessionId == changeDescription.SessionId));
 }
예제 #32
0
 protected override async void OnSessionChange(SessionChangeDescription changeDescription)
 {
     await Socket.SendHeartbeat();
 }
예제 #33
0
 protected override void OnSessionChange(SessionChangeDescription changeDescription)
 {
     base.OnSessionChange(changeDescription);
     WaitForServiceInit();
     m_serviceThreadObj.SessionChange(changeDescription);
 }
예제 #34
0
 protected virtual void OnSessionChange(SessionChangeDescription changeDescription)
 {
 }