Generate Ctrl-Alt-Del programmatically

This is a discussion on Generate Ctrl-Alt-Del programmatically within the Windows Programming forums, part of the Platform Specific Boards category; Hello guys, I want to generate Ctrl-Alt-Del key sequence programmatically. I have searched a lot on net but don't get ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    70

    Generate Ctrl-Alt-Del programmatically

    Hello guys,

    I want to generate Ctrl-Alt-Del key sequence programmatically.

    I have searched a lot on net but don't get any solution.

    I have tried to fill keyboard buffer with 'keybd_event()' function. But it is also not working. It seems that it fills application's key buffer.

    Anyway......can anybody help me to solve this problem ?

    Thanking You,
    Chintan R Naik

  2. #2
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Lightbulb Try SendMessage ...

    If you haven't tried the SendMessage function yet, then try this:

    Code:
    // Process keys being pressed
    SendMessage(NULL, WM_KEYDOWN, (WPARAM) VK_CONTROL);
    SendMessage(NULL, WM_KEYDOWN, (WPARAM) VK_ALT);
    SendMessage(NULL, WM_KEYDOWN, (WPARAM) VK_DELETE);
    // Process release of keys
    SendMessage(NULL, WM_KEYUP, (WPARAM) VK_CONTROL);
    SendMessage(NULL, WM_KEYUP, (WPARAM) VK_ALT);
    SendMessage(NULL, WM_KEYUP, (WPARAM) VK_DELETE);
    That may work, but I am not 100% sure. I hope it does .

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    I read somewhere that CTRL ALT DEL actually generates a hardware interrupt in the keyboard.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278

    Re: Try SendMessage ...

    WM_KEYDOWN and WM_KEYDOWN are notification messages, so sending messages with them will not work. Basically, a notification message is something that tells you something happened... it doesn't make it happen. Take a look at this thread for a good example of the difference between sending a message that does something or sending a notification (something you should never do, since all it does is fool your program into believing something happened that did not really happen).

  5. #5
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Originally posted by XSquared
    I read somewhere that CTRL ALT DEL actually generates a hardware interrupt in the keyboard.
    I believe this is correct, and this is one reason Ctrl+alt+delete is used fow WinNT logins-- it's difficult to intercept, because it is processed differently.

    However, I do know it IS possible to do this -- I've used software like pcAnywhere that let you send Ctrl+alt+delete to the remote machine. So you can do it, but my feeling is that their solution is lower level.

    In general, I think you will find that methods normally used to send keystrokes won't work in this case; this key combination is special and not handled like any other.

  6. #6
    Registered User
    Join Date
    Jun 2003
    Posts
    70
    Ya, you are right,

    I have tried most of the function and trick to fill key buffer such as : SendMessage(), PostMessage(), BroadcastSystemMessage(), WM_KEYDOWM, WH_HOTKEY, keybd_event() and so on. But they all are not working...

    Still I don't get solution...
    Chintan R Naik

  7. #7
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    SendInput() will do what you require.

  8. #8
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    MSDN states that "The SendInput function inserts the events ... serially into the keyboard or mouse input stream". By serially, doesn't that mean not at the same time? That means it wouldn't be able to simulate CTRL-ALT-DELETE all at the same time.

    I haven't tried implementing the function, but I just found that interesting.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  9. #9
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Okay, I tried using SendInput() and it didn't work. Here's my code:

    Code:
    int main(void)
    {
    	INPUT inp;
    	KEYBDINPUT kbi;
    	int a=0;
    
    	kbi.wScan=0;
    	kbi.dwFlags=0;
    	kbi.time=0;
    	kbi.dwExtraInfo=0;
    	inp.type=INPUT_KEYBOARD;
    
    	kbi.wVk=VK_CONTROL;
    	inp.ki=kbi;
    	a+=SendInput(1,&inp,sizeof(INPUT));
    
    	kbi.wVk=VK_MENU;
    	inp.ki=kbi;
    	a+=SendInput(1,&inp,sizeof(INPUT));
    
    	kbi.wVk=VK_DELETE;
    	inp.ki=kbi;
    	a+=SendInput(1,&inp,sizeof(INPUT));
    
    	cout << a << endl;
    
    	a=0;
    
    	kbi.dwFlags=KEYEVENTF_KEYUP;
    
    	kbi.wVk=VK_CONTROL;
    	inp.ki=kbi;
    	a+=SendInput(1,&inp,sizeof(INPUT));
    
    	kbi.wVk=VK_MENU;
    	inp.ki=kbi;
    	a+=SendInput(1,&inp,sizeof(INPUT));
    
    	kbi.wVk=VK_DELETE;
    	inp.ki=kbi;
    	a+=SendInput(1,&inp,sizeof(INPUT));
    
    	cout << a << endl;
    
    	getch();
    	return 0;
    }
    So basically, I send CTRL-ALT-DELETE keydowns then CTRL-ALT-DELETE keyups. Nothing happens. The output tells me that all 6 events have been successfully inserted into the input stream. Have I done something wrong, or is this just not the way to do it?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  10. #10
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    Originally posted by XSquared
    I read somewhere that CTRL ALT DEL actually generates a hardware interrupt in the keyboard.
    If this is true, then you will have to issue this hardware interrupt yourself to emulate it. This is easy to do in good 'ol MS-DOS, but Windows is purposely made so that this is not so easy to do...

  11. #11
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Ctrl-Alt-Del is Windows's "Secure Attention Sequence". It is designed to be non "hookable" etc., the reason being that when one presses Ctrl-Alt-Del one is sure one is talking to the OS rather than any kind of trojan. This is Orange Book stuff.

    It seems reasonable to me that this being the case, generating this sequence would also be restricted/pointless. I cannot find a specific prohibition, but I have tried to generate it, and used some really rather deep hacks. None have worked - I have given up trying.

    I have never had a legit reason for doing so, it was an intellectual challenge which, it would seem, I was not up too!
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  12. #12
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Get a copy of PCAnywhere and break down the code if you can. Expanding on what adrianxw said, there are few legit reasons to do this.

    One thing you could do is under your switch (message) put a default: that prints ALL of the messages and parameters to a window and then press ctrl - alt - delete and see if there are any messages. But be prepared for spam and to not find the answer

  13. #13
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    The messages your application receives are the ones that Windows has chosen to send you. If you press Ctrl-Alt-Del, there is no reason why Windows should send you anything, apart possibly, from a loss of primary focus. At that point, you are now communicating with Windows, not the application which had focus before the sequence was pressed.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  14. #14
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    never said it would work. In fact I agree that it most likely wouldn't, but it wouldn't hurt to try

  15. #15
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Sending Ctrl-Alt-Del to a co-operating task on another machine is not the same as pressing it locally. When you tell PCAnyWhere to send Ctrl-Alt-Del to a remote client, it is sending a message saying it would like to press Ctrl-Alt-Del to a co-operating task on the local machine. This task can then instigate a reboot or whatever. Different case.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

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

Similar Threads

  1. Ctrl Alt Del
    By cboard_member in forum A Brief History of Cprogramming.com
    Replies: 27
    Last Post: 07-20-2005, 07:36 AM
  2. how to capture CTRL, SHIFT and ALT ?
    By goldenrock in forum C Programming
    Replies: 3
    Last Post: 11-06-2003, 12:20 AM
  3. Trapping Ctrl Alt Delete
    By emus21 in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 09-17-2003, 12:10 PM
  4. how to trap Ctrl + Alt + Del
    By samudrala_99 in forum Windows Programming
    Replies: 5
    Last Post: 12-16-2002, 12:01 AM
  5. Ctrl + Alt +Delete
    By golfinguy4 in forum Windows Programming
    Replies: 4
    Last Post: 10-27-2002, 06:46 PM

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