Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PC sperren...

Empfohlene Antworten

Veröffentlicht

Hi!

Ich möchte ein Programm machen, mit dem man den PC sperren kann (auch übers Netzwerk).

Also muss ich irgendwie verhindern, dass die Nachrichten für die Tastatureingaben an Windows gelangen. Z.B. Wenn man "ALT+TAB" drückt oder "STRG+ALT+ENTF".

Schätze mal, es ist nicht damit getan, das ich die Nachricht WM_KEYDOWN abfange.

Geht das so ohne weiteres? Und kann mir vielleicht jemand helfen und das ein bisschen erklären??

Danke!!!

Ich denke ein systemweiter MessageHook wäre das richtige für diese Aufgabe.

Schau dir mal die Funktion SetWindowsHook an. Allerdings muss deine

Funktion in einer DLL liegen, sollte aber kein Problem sein.

Mit Hilfe des Hooks bekommst du alle Messages des Systems mit und kannst

die natürlich auch abfangen...

Wenn jemand ne andere elegantere Lösung kennt würde ich die gerne lesen.

Ich bilde mir ein es gibt da nähmlich ne API um Tastatureingaben abzufangen,

bin mir aber net sicher.

Diablo999

Scheint doch ein bisschen komplizierter zu sein, als ich dachte.

In der Library steht:

SetWindowsHookEx

The SetWindowsHookEx function installs an application-defined hook procedure into a hook chain. You would install a hook procedure to monitor the system for certain types of events. These events are associated either with a specific thread or with all threads in the system.

HHOOK SetWindowsHookEx(

int idHook, // type of hook to install

HOOKPROC lpfn, // address of hook procedure

HINSTANCE hMod, // handle to application instance

DWORD dwThreadId // identity of thread to install hook for

);

lpfn

Pointer to the hook procedure. If the dwThreadId parameter is zero or specifies the identifier of a thread created by a different process, the lpfn parameter must point to a hook procedure in a dynamic-link library (DLL). Otherwise, lpfn can point to a hook procedure in the code associated with the current process.

hMod

Handle to the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process.

dwThreadId

Specifies the identifier of the thread with which the hook procedure is to be associated. If this parameter is zero, the hook procedure is associated with all existing threads.

Die iDHook müsste WH_KEYBOARD sein.

Aber die anderen Parameter verstehe ich nicht ganz.

Und wie soll das mit der DLL gehen?

Ich hab noch nie eine angelegt. *schäm*

Hier eine FAST genaue Beschreibung:

Erstmal brauchst du ein Programm welches den Hook ausführt, des kann auch nur

eine Konsolenanwendung sein.

Das Programm lädt mittels LoadLibrary(...) deine eigene DLL und sucht sich mit

GetProcAddress(...) oder so ähnlich den Einsprungspunkt deiner HookCallBack-

Funktion.

Dann rufst du SetWindowsHook auf wobei du wie schon gesagt WH_KEYBOARD

übergibst, als lpfn übergibst du den Pointer auf die HookCallBack-Funktion, als

hMod das Handle das dir Loadlibrary zurückgegeben hat und als dwThreadID

übergibst du 0 weil du ja alle Threads im ganzen System überwachen willst.

In deiner HookCallBack-Funktion musst du das Ereignis an den nächsten Hook

weitergeben. Dafür brauchst du aber in deiner DLL dein eigenes Hookhandle.

Das übergibst du am besten von deinem Programm an die DLL.

Wenn dir das immer noch zuviel ist kann ich dir mal ein Projekt von mir schicken

das so was ähnliches macht. Kann ich aber erst heut abend wenn ich wieder

zuhause bin.

Herrje, ist dass kompliziert. Ich hab immer noch nicht kapiert, was ich in diese DLL reinschreiben soll. :(

Also, pass auf...

In der DLL liegt eine Funktion von dir die so aufgebaut ist:


LRESULT CALLBACK GetMsgProc(  int code, WPARAM wParam, LPARAM lParam)

{

   // Hier kommt der Code rein den du beim Tastenanschlag machen willst, so in etwa

   MSG* msg = (MSG*)lParam;

   if (msg->message == WM_KEYDOWN)

     msg->hwnd = 0;


  return CallNextHookEx(...);

}

Ein Pointer auf diese Funktion wird an die SetwindowsHook-Funktion übergeben,

das System ruft dann deine Funktion immer auf wenn irgendein Fenster eine

Nachricht bekommt. Du musst natürlich noch überprüfen welche Tasten gedrückt

sind aber das ist mit der MSG-Struktur ja kein Problem, schau dir dazu einfach

WM_KEYDOWN oder so ähnlich an, vielleicht musst du auch WM_KEYPRESS und WM_KEYUP abfangen...

Das muss jetzt erstmal genügen, aber wie gesagt ich schick dir heut abend mal

meinen code, dann kannst du es dir vielleicht besser vorstellen...

Viel Glück noch

Diablo999

Cool! Echt vielen Dank! :)

Jetzt hab ichs kapiert.

Mir war vorher der Zusammenhang net ganz klar.

Ich versuchs mal...

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.