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
'**************************************************************************************************
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
'**************************************************************************************************