I finally found this C ++ code in CodeProject, which works well on startup as a System User . So I converted the code to dll and called the function from my code.
Here is the C ++ code (you can use the ErrorExit example function, which uses GetLastErrorfrom MSDN in case of a problem):
#include "windows.h"
#include <strsafe.h>
__declspec(dllexport) BOOL SimulateAltControlDel()
{
HDESK hdeskCurrent;
HDESK hdesk;
HWINSTA hwinstaCurrent;
HWINSTA hwinsta;
hwinstaCurrent = GetProcessWindowStation();
if (hwinstaCurrent == NULL)
return FALSE;
hdeskCurrent = GetThreadDesktop(GetCurrentThreadId());
if (hdeskCurrent == NULL)
return FALSE;
hwinsta = OpenWindowStation("winsta0", FALSE,
WINSTA_ACCESSCLIPBOARD |
WINSTA_ACCESSGLOBALATOMS |
WINSTA_CREATEDESKTOP |
WINSTA_ENUMDESKTOPS |
WINSTA_ENUMERATE |
WINSTA_EXITWINDOWS |
WINSTA_READATTRIBUTES |
WINSTA_READSCREEN |
WINSTA_WRITEATTRIBUTES);
if (hwinsta == NULL)
return FALSE;
if (!SetProcessWindowStation(hwinsta))
return FALSE;
hdesk = OpenDesktop("Winlogon", 0, FALSE,
DESKTOP_CREATEMENU |
DESKTOP_CREATEWINDOW |
DESKTOP_ENUMERATE |
DESKTOP_HOOKCONTROL |
DESKTOP_JOURNALPLAYBACK |
DESKTOP_JOURNALRECORD |
DESKTOP_READOBJECTS |
DESKTOP_SWITCHDESKTOP |
DESKTOP_WRITEOBJECTS);
if (hdesk == NULL)
return FALSE;
if (!SetThreadDesktop(hdesk))
return FALSE;
PostMessage(HWND_BROADCAST,WM_HOTKEY,0,MAKELPARAM(MOD_ALT|MOD_CONTROL,VK_DELETE));
if (!SetProcessWindowStation(hwinstaCurrent))
return FALSE;
if (!SetThreadDesktop(hdeskCurrent))
return FALSE;
if (!CloseWindowStation(hwinsta))
return FALSE;
if (!CloseDesktop(hdesk))
return FALSE;
return TRUE;
}
.def , ( AltCtrlDelCpp) ,
;altctrldel.def
LIBRARY AltCtrlDelCpp
;CODE PRELOAD MOVEABLE DISCARDABLE
;DATA PRELOAD MOVEABLE
EXPORTS
SimulateAltControlDel
.NET- DLL , , , DllImport :
#
[DllImport(@"AltCtrlDelCpp.dll")]
static extern bool SimulateAltControlDel();
VB.NET
<DllImport("AltCtrlDelCpp.dll")> _
Private Function SimulateAltControlDel() As Boolean
VB.NET Sub Main:
<MTAThread()> _
Sub Main()
SimulateAltControlDel, . , , winform.