Tech Off Thread

11 posts

Stopping customers from using Alt-Tab and the Windows-Key in my application.

Back to Forum: Tech Off
  • User profile image
    intrepid

    I have a WPF application that I want to remain on the screen on the notebooks in my shop, and I don't want customers to exit out of it. I don't mind if they press Alt-F4 (as exiting the application locks the computer) but I don't want any other keys to do anything at all.

    I know this can be done, but not how it can be done in WPF/C#. Can someone provide samle code? Or does someone have a better solution?

    Thanks, Intrepid.

  • User profile image
    W3bbo

    It's possible, just set up a keyboard hook and don't pass on the messages for certain keys.

  • User profile image
    footballism

    I don't think you can do it in application code, since the alt-tab keystroke are system command which are processed by operating system before it gets dispatched and processed by your application's window procedure.

    Sheva

  • User profile image
    sushovande

    I am pretty sure that the DirectX API reference has an article on how to do it. I will chip in with an edit later telling the exact URL.

  • User profile image
    Massif

    Can't you just set the PCs so that your WPF app is the shell instead of explorer? Then there's nowhere for them to go if they manage to get out of your program.

    I know it can be done in XP, and although I imagine the settings are the same for vista I can't remember them anyway.

  • User profile image
    Cannot​Resolve​Symbol

    Massif wrote:
    Can't you just set the PCs so that your WPF app is the shell instead of explorer? Then there's nowhere for them to go if they manage to get out of your program.

    I know it can be done in XP, and although I imagine the settings are the same for vista I can't remember them anyway.


    Yeah, that would probably be the way to go.  You'll also want to restrict the Windows Security dialog (the one that pops up when you press control-alt-delete) using group policy so that Shut Down and Task Manager are disabled--  otherwise, anyone can turn off the computer or run arbitrary programs regardless of shell.

    To change the shell for the current user (make sure you have another user set up on the machine, otherwise, with task manager disabled, you'll have to format and reinstall to get back to normal), go to HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Winlogon, add a new string value called shell, and set its value to the path of the new shell.

    Just make sure you have a way back out of this...

  • User profile image
    footballism

        When I first read this post, I think Massif's answer should be the way to go if the original poster really wanna enable this kinda scenario, but from the deloyment perspective, this is something impossible. Yes, you can do it if the end-user's machine is at your disposal, but not otherwise.

    Sheva

  • User profile image
    saporis

    My suggest, albeit bruteforce, would be to have a timer that is triggered every 1 second.  If the program lost focus, have it bring it back.  Anyone alt-tabbing will be annoyed.

    Another method, would be a timer every 10 ms that checks for the alt modifier key ( if ( System.Windows.Forms.Control.ModifierKeys == System.Windows.Forms.Keys.Alt) ), and if so, pulls back the form to the front.  Again, annoyance to the alt-tab. 

    Both of these ways will only cause the program to be brought almost immediately back.  However, I'm sure the user will be quick to alt-F4...   

  • User profile image
    asharism

    saporis wrote:
    My suggest, albeit bruteforce, would be to have a timer that is triggered every 1 second.  If the program lost focus, have it bring it back.  Anyone alt-tabbing will be annoyed.

    Another method, would be a timer every 10 ms that checks for the alt modifier key ( if ( System.Windows.Forms.Control.ModifierKeys == System.Windows.Forms.Keys.Alt) ), and if so, pulls back the form to the front.  Again, annoyance to the alt-tab. 

    Both of these ways will only cause the program to be brought almost immediately back.  However, I'm sure the user will be quick to alt-F4...   


    Alt+F4 should be fine as you can handle that in your application...

  • User profile image
    asharism

    EDIT: Posted the message twice accidentally...

  • User profile image
    saporis

    Oh, I know that...but, from what I am reading, this app will be running on the "customers" end.  Thus, we need to finish our task infront, BUT, shouldn't lock down the "customers" computer...so we support a "failsafe"?


    ...is this correct?

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.