Sending Ctrl-Alt-Del Keys

C

clu

I have been trying to reproduce the Ctrl-Alt-Del Key Press for quite
some time without success. After my research I have put together the
following code. I started with the VNC source code which uses
PostMessage to fake this key combination. When run, this code opens
the Run command dialog box. I feel that I am on the right track but
may have used incorrect constant values.

To put this in perspective, I am trying to automate a reboot and logon
of remote Windows XP computers. While it may be possible to reproduce
this key combination as VNC and other programs do my next challenge
will be to do so over a network on a remote PC. I am unable to use
third party application and was focusing on using VBScript but used
Excel VBA to try this API approach.

I am open to other solutions but would love to see the below code or
something like it actually work as I have been working on this for a
very long time. I greatly appreciate any and all assistance.

'*******************************************************************************************************
Option Explicit

Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpDest As
Any, lpSource As Any, ByVal nCount As Long)
Declare Function PostMessage Lib "user32" _
Alias "PostMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Sub CtlAltDlt2()
Dim x As Long
Const HWND_BROADCAST = &HFFFF
Const WM_HOTKEY = &H312
Const MOD_ALT = &H1
Const MOD_CONTROL = &H2
Const VK_DELETE = &H2E
x = PostMessage(HWND_BROADCAST, WM_HOTKEY, 0, MAKELONG(MOD_ALT Or
MOD_CONTROL, VK_DELETE))
End Sub


Public Function HIWORD(ByVal dwValue As Long) As Long
Call CopyMemory(HIWORD, ByVal VarPtr(dwValue) + 2, 2)
End Function


Public Function LOWORD(ByVal dwValue As Long) As Long
Call CopyMemory(LOWORD, dwValue, 2)
End Function


Public Function MAKELONG(ByVal wLow As Long, ByVal wHi As Long) As Long
If (wHi And &H8000&) Then
MAKELONG = (((wHi And &H7FFF&) * 65536) Or (wLow And &HFFFF&))
Or -2147483648#
Else
MAKELONG = LOWORD(wLow) Or (&H10000 * LOWORD(wHi))
End If
End Function
'**************************************************************************************************
 
D

Dave Patrick

To what end?

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

:
|I have been trying to reproduce the Ctrl-Alt-Del Key Press for quite
| some time without success. After my research I have put together the
| following code. I started with the VNC source code which uses
| PostMessage to fake this key combination. When run, this code opens
| the Run command dialog box. I feel that I am on the right track but
| may have used incorrect constant values.
|
| To put this in perspective, I am trying to automate a reboot and logon
| of remote Windows XP computers. While it may be possible to reproduce
| this key combination as VNC and other programs do my next challenge
| will be to do so over a network on a remote PC. I am unable to use
| third party application and was focusing on using VBScript but used
| Excel VBA to try this API approach.
|
| I am open to other solutions but would love to see the below code or
| something like it actually work as I have been working on this for a
| very long time. I greatly appreciate any and all assistance.
|
|
'*******************************************************************************************************
| Option Explicit
|
| Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpDest As
| Any, lpSource As Any, ByVal nCount As Long)
| Declare Function PostMessage Lib "user32" _
| Alias "PostMessageA" (ByVal hwnd As Long, _
| ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
|
| Sub CtlAltDlt2()
| Dim x As Long
| Const HWND_BROADCAST = &HFFFF
| Const WM_HOTKEY = &H312
| Const MOD_ALT = &H1
| Const MOD_CONTROL = &H2
| Const VK_DELETE = &H2E
| x = PostMessage(HWND_BROADCAST, WM_HOTKEY, 0, MAKELONG(MOD_ALT Or
| MOD_CONTROL, VK_DELETE))
| End Sub
|
|
| Public Function HIWORD(ByVal dwValue As Long) As Long
| Call CopyMemory(HIWORD, ByVal VarPtr(dwValue) + 2, 2)
| End Function
|
|
| Public Function LOWORD(ByVal dwValue As Long) As Long
| Call CopyMemory(LOWORD, dwValue, 2)
| End Function
|
|
| Public Function MAKELONG(ByVal wLow As Long, ByVal wHi As Long) As Long
| If (wHi And &H8000&) Then
| MAKELONG = (((wHi And &H7FFF&) * 65536) Or (wLow And &HFFFF&))
| Or -2147483648#
| Else
| MAKELONG = LOWORD(wLow) Or (&H10000 * LOWORD(wHi))
| End If
| End Function
|
'**************************************************************************************************
|
 
S

Steve Yandl

If all the computers are running Windows XP, use WMI with VBS. In the
example below, strComputer is the name of the computer to be rebooted. If
you use a single period "." as strComputer, the script will act on the local
machine the script is running on.

strComputer = "atl-dc-01"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Reboot()
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top