locked
how programmatically track if device has locked? RRS feed

  • Question

  • Hello!

    I have a custom unlock screen but i dont know when to show it.I found a SystemState class that monitors a SystemState property.One of the properties is DeviceLocked property.

    SystemState state;

    .....

    state=new SystemState(SystemProperty.DeviceLocked,true);

    state+=(s,e)=>MessageBox.Show("Locked");//got NullReferenceException

    So how can i use it? Or is there other way to solve my problem?

    Thanks!


    MSP
    Tuesday, February 3, 2009 7:48 AM

Answers

  • Hi
    You can read periodically; the registry entry HKEY_LOCAL_MACHINE\System\State
    Have a look to this:
    http://social.msdn.microsoft.com/Forums/en-US/vssmartdevicesvbcs/thread/60625fac-94a9-43a8-bc73-62ee07cb07e5/ 

    Regards
    Tuesday, February 3, 2009 2:20 PM
  • Hi Guys,


    You can monitor the registry setting via callback event.

    public class abc
    {
            private static string RegistryPath = @"HKEY_LOCAL_MACHINE\System\State";
            private static string Command = "Lock";
            private RegistryState _regChangeState = null;
          
            public abc()
            {
                _regChangeState = new RegistryState(RegistryPath, Command);
                _regChangeState.Changed += new ChangeEventHandler(_regChangeState_Changed);
            }
            private void _regChangeState_Changed(object sender, ChangeEventArgs args)
            {
                       int regValue = (int)_regChangeState.CurrentValue;
                     //If changed show the lock;
            }
    }

    Cheers,

    Nitan
    • Marked as answer by Fromrus Wednesday, February 25, 2009 7:35 AM
    Wednesday, February 11, 2009 2:28 PM

All replies

  • Hi
    You can read periodically; the registry entry HKEY_LOCAL_MACHINE\System\State
    Have a look to this:
    http://social.msdn.microsoft.com/Forums/en-US/vssmartdevicesvbcs/thread/60625fac-94a9-43a8-bc73-62ee07cb07e5/ 

    Regards
    Tuesday, February 3, 2009 2:20 PM
  • Thanks for the code Hammadi!
    But how can i know if this key has changed?

    Thread t=new Thread(()=>IsLocked());
    t.Start();

    void IsLocked()
    {
    while(true){
    try{
    if(int.Parse(Microsoft.Win32.Registry.GetValue(/*path*/),"Lock","1").ToString());
        new Form2.Show()//This is my custom unlock window
    }
    Catch(){//}
    }

    it doesnt work...I mean i need to show this window if a user doesnt tap the screen or press any key for 60 seconds(as example)
    MSP
    Friday, February 6, 2009 6:59 AM
  • Hi Guys,


    You can monitor the registry setting via callback event.

    public class abc
    {
            private static string RegistryPath = @"HKEY_LOCAL_MACHINE\System\State";
            private static string Command = "Lock";
            private RegistryState _regChangeState = null;
          
            public abc()
            {
                _regChangeState = new RegistryState(RegistryPath, Command);
                _regChangeState.Changed += new ChangeEventHandler(_regChangeState_Changed);
            }
            private void _regChangeState_Changed(object sender, ChangeEventArgs args)
            {
                       int regValue = (int)_regChangeState.CurrentValue;
                     //If changed show the lock;
            }
    }

    Cheers,

    Nitan
    • Marked as answer by Fromrus Wednesday, February 25, 2009 7:35 AM
    Wednesday, February 11, 2009 2:28 PM