How get system window handle ?

This is a discussion on How get system window handle ? within the C Programming forums, part of the General Programming Boards category; Hello, I'm programming an autologon script by card-reading, and I need to post user login and pass into the log-on ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    14

    How get system window handle ?

    Hello,

    I'm programming an autologon script by card-reading, and I need to post user login and pass into the log-on window fields.
    -> http://pangea.stanford.edu/facilitie...windows.03.jpg

    But to do this, I need to know handle window and controls IDs.

    I've made a code which do this perfectly on any windows. But it doesn't function on the Microsoft logon window... It cannot find main window handle by name.

    This is my code :
    Code:
    handleFenetre = FindWindow(NULL,"Log On to Windows"); // Retrieve window handle
    Sleep(100);
        
    handleControle = GetWindow(handleFenetre,GW_CHILD); // Retrieve editbox handle        
    idControle = GetDlgCtrlID(handleControle); // Retrieve control ID
    SendDlgItemMessage(handleFenetre, idControle, WM_SETTEXT, 0, (WPARAM)"MyLogin");
    So, main window handle cannot be retrieved.
    I decided to enum all windows and childwindows on the desktop by a new code which generate a txt file. In this file there is NO window called Log On to Windows

    -------------------------------------------------------
    HandleWnd = 65890
    NomWnd = TF_FloatingLangBar_WndTitle

    -------------------------------------------------------
    HandleWnd = 65892
    NomWnd = CiceroUIWndFrame

    -------------------------------------------------------
    HandleWnd = 65674
    NomWnd =

    -------------------------------------------------------
    HandleWnd = 65660
    NomWnd =

    -------------------------------------------------------
    HandleWnd = 65676
    NomWnd =

    -------------------------------------------------------
    HandleWnd = 65658
    NomWnd =

    -------------------------------------------------------
    HandleWnd = 131258
    NomWnd =

    -------------------------------------------------------
    HandleWnd = 131216
    NomWnd = Menu Démarrer

    HandleChildWnd = 131254
    NomChlidWnd =

    HandleChildWnd = 131256
    NomChlidWnd = Clement

    HandleChildWnd = 131246
    NomChlidWnd =

    HandleChildWnd = 131248
    NomChlidWnd =

    HandleChildWnd = 131242
    NomChlidWnd =

    HandleChildWnd = 131244
    NomChlidWnd =

    HandleChildWnd = 131230
    NomChlidWnd = &Tous les programmes

    HandleChildWnd = 131236
    NomChlidWnd =

    HandleChildWnd = 131240
    NomChlidWnd =

    HandleChildWnd = 131228
    NomChlidWnd =

    HandleChildWnd = 131250
    NomChlidWnd =

    HandleChildWnd = 131238
    NomChlidWnd =

    -------------------------------------------------------
    HandleWnd = 196680
    NomWnd =

    -------------------------------------------------------
    HandleWnd = 1572968
    NomWnd =

    -------------------------------------------------------
    HandleWnd = 262198
    NomWnd =

    HandleChildWnd = 196670
    NomChlidWnd = démarrer

    HandleChildWnd = 196668
    NomChlidWnd =

    HandleChildWnd = 196672
    NomChlidWnd = 20:45

    HandleChildWnd = 196674
    NomChlidWnd =

    HandleChildWnd = 196676
    NomChlidWnd = Zone de notification

    HandleChildWnd = 196678
    NomChlidWnd =

    HandleChildWnd = 65662
    NomChlidWnd =

    HandleChildWnd = 65668
    NomChlidWnd = Applications en cours d'exécution

    HandleChildWnd = 65672
    NomChlidWnd = Applications en cours d'exécution

    HandleChildWnd = 65666
    NomChlidWnd = Quick Launch

    -------------------------------------------------------
    HandleWnd = 65688
    NomWnd =

    -------------------------------------------------------
    HandleWnd = 131218
    NomWnd =

    -------------------------------------------------------
    HandleWnd = 131252
    NomWnd =

    -------------------------------------------------------
    HandleWnd = 328126
    NomWnd = C:\Documents and Settings\Clement\Bureau\Copie de clavier\clavier.exe

    -------------------------------------------------------
    HandleWnd = 65882
    NomWnd =

    -------------------------------------------------------
    HandleWnd = 65952
    NomWnd =

    -------------------------------------------------------
    HandleWnd = 65950
    NomWnd = DAEMON Tools Agent window

    -------------------------------------------------------
    HandleWnd = 65946
    NomWnd = DDE Server Window

    -------------------------------------------------------
    HandleWnd = 65932
    NomWnd = DccMan

    -------------------------------------------------------
    HandleWnd = 65928
    NomWnd = RAPIMgr

    -------------------------------------------------------
    HandleWnd = 65922
    NomWnd =

    -------------------------------------------------------
    HandleWnd = 65888
    NomWnd =

    -------------------------------------------------------
    HandleWnd = 131390
    NomWnd = MS_WebcheckMonitor

    -------------------------------------------------------
    HandleWnd = 65846
    NomWnd = CAvastTrayIcon

    -------------------------------------------------------
    HandleWnd = 65842
    NomWnd =

    -------------------------------------------------------
    HandleWnd = 131368
    NomWnd = avast! UI Control Window

    -------------------------------------------------------
    HandleWnd = 65812
    NomWnd =

    -------------------------------------------------------
    HandleWnd = 131316
    NomWnd = Dialog

    HandleChildWnd = 65798
    NomChlidWnd = OK

    HandleChildWnd = 65800
    NomChlidWnd = Cancel

    -------------------------------------------------------
    HandleWnd = 65896
    NomWnd = Connections Tray

    -------------------------------------------------------
    HandleWnd = 196800
    NomWnd =

    -------------------------------------------------------
    HandleWnd = 262426
    NomWnd = Jauge d'énergie

    HandleChildWnd = 65874
    NomChlidWnd = État de l'alimentation

    HandleChildWnd = 65876
    NomChlidWnd = Toujours &afficher l'icône sur la barre des tâches.

    HandleChildWnd = 65878
    NomChlidWnd = Afficher les détails pour chaque &batterie.

    HandleChildWnd = 65880
    NomChlidWnd =

    -------------------------------------------------------
    HandleWnd = 65736
    NomWnd = Management - O&O Defrag

    HandleChildWnd = 65740
    NomChlidWnd =

    HandleChildWnd = 65744
    NomChlidWnd = xtpBarTop

    HandleChildWnd = 65752
    NomChlidWnd = Typical

    HandleChildWnd = 65746
    NomChlidWnd = xtpBarBottom

    HandleChildWnd = 65748
    NomChlidWnd = xtpBarLeft

    HandleChildWnd = 65750
    NomChlidWnd = xtpBarRight

    -------------------------------------------------------
    HandleWnd = 65734
    NomWnd = MediaCenter

    -------------------------------------------------------
    HandleWnd = 65730
    NomWnd =

    -------------------------------------------------------
    HandleWnd = 65664
    NomWnd =

    -------------------------------------------------------
    HandleWnd = 327754
    NomWnd =

    -------------------------------------------------------
    HandleWnd = 131150
    NomWnd =

    -------------------------------------------------------
    HandleWnd = 131154
    NomWnd =

    -------------------------------------------------------
    HandleWnd = 65578
    NomWnd = NVSVCPMMWindowClass

    -------------------------------------------------------
    HandleWnd = 65690
    NomWnd =

    -------------------------------------------------------
    HandleWnd = 65678
    NomWnd = Program Manager

    HandleChildWnd = 65684
    NomChlidWnd =

    HandleChildWnd = 65686
    NomChlidWnd = FolderView

    -------------------------------------------------------
    HandleWnd = 196666
    NomWnd = M

    -------------------------------------------------------
    HandleWnd = 196664
    NomWnd = Default IME

    -------------------------------------------------------
    HandleWnd = 65884
    NomWnd = Default IME

    -------------------------------------------------------
    HandleWnd = 65948
    NomWnd = Default IME

    -------------------------------------------------------
    HandleWnd = 65934
    NomWnd = Default IME

    -------------------------------------------------------
    HandleWnd = 65930
    NomWnd = Default IME

    -------------------------------------------------------
    HandleWnd = 65924
    NomWnd = Default IME

    -------------------------------------------------------
    HandleWnd = 131366
    NomWnd = Default IME

    -------------------------------------------------------
    HandleWnd = 65804
    NomWnd = M

    -------------------------------------------------------
    HandleWnd = 65738
    NomWnd = Default IME

    -------------------------------------------------------
    HandleWnd = 65872
    NomWnd = Default IME

    -------------------------------------------------------
    HandleWnd = 65732
    NomWnd = Default IME

    -------------------------------------------------------
    HandleWnd = 65698
    NomWnd = M

    -------------------------------------------------------
    HandleWnd = 131152
    NomWnd = Default IME
    I don't know what doing.
    Can you help me ?
    Last edited by theclem35; 06-18-2011 at 02:40 PM.

  2. #2
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    612
    You write a GINA for XP and a credential provider for Vista+, search MSDN and the SDK for examples.
    What you don't do is call SetWindowText with the password in plaintext.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    The logon window handle can be gotten from GetForegroundWindow();

    You can send your characters using either PostMessage(), SendInput() or keybrd_event() and simply pass fake keystrokes from your card reader into the foreground window...

    With PostMessage() use WM_KEYDOWN and WM_KEYUP messages with virtual key codes or ASCII values.

    With SendInput() or keybrd_event create packets with Virtual key codes and ASCII values to be sent to the foreground window.
    Last edited by CommonTater; 06-18-2011 at 03:17 PM.

  4. #4
    Registered User
    Join Date
    Apr 2011
    Posts
    14
    Hello,

    My previous program was made with kebrd_event but I don't like that because I used tab key to change editbox, but if user select cancel button, program enter password in login field, so it's not very good...

    I'm not sure about GetForegroundWIndow -> How To Use GetForegroundWindow() When Desktop Is Not Active :
    Other desktops include the logon and screen saver desktops. If GetForegroundWindow() returned a handle to the logon dialog box, it would be possible to create an application that could get user passwords. This would violate Windows NT security.

    For this reason, it is not possible to create screen savers that melt or drop out.

    :/

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by theclem35 View Post
    Hello,

    My previous program was made with kebrd_event but I don't like that because I used tab key to change editbox, but if user select cancel button, program enter password in login field, so it's not very good...
    That has nothing to do with the card reader that's the login window doing what it's programmed to do.

    I'm not sure about GetForegroundWIndow -> How To Use GetForegroundWindow() When Desktop Is Not Active :
    Other desktops include the logon and screen saver desktops. If GetForegroundWindow() returned a handle to the logon dialog box, it would be possible to create an application that could get user passwords. This would violate Windows NT security.
    Ok... then don't use it, continue to struggle with your current failed code.


    For this reason, it is not possible to create screen savers that melt or drop out.
    Irrelevent.

  6. #6
    Registered User
    Join Date
    Apr 2011
    Posts
    14
    My program reads RS232 data (so datas in the card) it convert it into chars, and after I sent character by character into logon window and simulate a Enter key.

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by theclem35 View Post
    My program reads RS232 data (so datas in the card) it convert it into chars, and after I sent character by character into logon window and simulate a Enter key.
    Yes... so what's your problem with that? You do not need window handles to use keybd_event()... send it the username string, a tab, the password, and enter... It should be over in a couple of milliseconds...

  8. #8
    Registered User
    Join Date
    Apr 2011
    Posts
    14
    Yes this is exactly what I made!
    But.. If user before introducing its card, select the cancel button with TAB key, the keybd_event() will send the username into cancel button.. but when TAB virtual key will be sent, pointer will go on username field and keybd_event() will send password into username field, in clear text....

    How can you send string with keybd_event() ???

    I made this (so character by character) :
    keybd_event('C',0,0,0);
    keybd_event('C',0,KEYEVENTF_KEYUP,0);
    keybd_event('L',0,0,0);
    keybd_event('L',0,KEYEVENTF_KEYUP,0);
    Last edited by theclem35; 06-18-2011 at 04:07 PM.

  9. #9
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by theclem35 View Post
    How can you send string with keybd_event() ???
    Code:
    for (i = 0; i < strlen(str); i++)
      { keybd_event(str[i], 0, 0, 0);
         Sleep(1);
         keybd_event(str[i],0,KEYEVENTF_KEYUP,0); }

  10. #10
    Registered User
    Join Date
    Apr 2011
    Posts
    14
    Thank you,

    How to manage upper/lower case, numbers and others special characters from a string ?

    Example : string = "abcdABCD1234,;^µ"

  11. #11
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    If they will fit in a string you can send them with the code I provided.

  12. #12
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    612
    Quote Originally Posted by theclem35 View Post
    the keybd_event() will send the username into cancel button.. but when TAB virtual key will be sent, pointer will go on username field and keybd_event() will send password into username field, in clear text....
    So do it the right way then. Otherwise your system is about as secure as writing the passwords on a post-it note on the side of the computer. I doubt the higher ups will be particularly pleased that they spent x amount of local currency on a new security system that can be foiled by clicking cancel.

  13. #13
    Registered User
    Join Date
    Apr 2011
    Posts
    14
    Hello,

    With your code if I put "abcdABCD1234,;^µ" as string it write me : 1234abcd&é"' with opening vlc media player .. :/

    I think I must looking for a modified gina.dll but it seems to be complicated..

  14. #14
    Registered User
    Join Date
    Apr 2011
    Posts
    14
    I've launch my app with GetForegroundWindow(); into SYSTEM account, and same thing it returns NULL.

  15. #15
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,852
    Since you know what a GINA is, how about some google action to read more about it?
    alternative windows gina authentication - Google Search

    I mean, the links at the bottom of the wiki page (top hit) all point to the Microsoft site, with rather useful titles such as

    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting window handle from HDC
    By maxorator in forum Windows Programming
    Replies: 2
    Last Post: 01-02-2007, 03:07 PM
  2. PID from window handle.
    By Brian in forum Windows Programming
    Replies: 0
    Last Post: 11-23-2004, 07:42 AM
  3. Locating A Window Handle For...
    By DeepBlackMagic in forum Windows Programming
    Replies: 4
    Last Post: 08-30-2003, 02:23 PM
  4. Max Window By Handle
    By DeepBlackMagic in forum Windows Programming
    Replies: 1
    Last Post: 08-29-2003, 07:05 PM
  5. Retrieving the window handle of a window a control resides in
    By -leech- in forum Windows Programming
    Replies: 7
    Last Post: 08-09-2003, 09:55 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21