Delphi-PRAXiS
Seite 4 von 4   « Erste     234   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi USB - Autostart dynamisch unterbinden (https://www.delphipraxis.net/140555-usb-autostart-dynamisch-unterbinden.html)

Astat 1. Mär 2010 19:43

Re: USB - Autostart dynamisch unterbinden
 
Zitat:

Zitat von Schwedenbitter
Insgesamt bin ich aber an dem Thema immer noch interessiert. Falls also jemand eine einfach Lösung ohne Dienst etc. hat, dann bitte her damit.

Hallo Schwedenbitter, anbei Hook Template zum Abfangen und Ändern der WM_DEVICECHANGE message.
Das Teil setzt soweit unten an, dass die Windowsmessages hier Aufschlagen bevor diese an die zuständige WndProc
gesendet werden.


Verwendung:
DLL einfach mit CreateHook aufrufen.


PS. Dient als Template, habs nicht vollständig durchgetestet, Feintuning eventuell Manuelle Parametrisierung
sowie IPC noch notwendig.




Delphi-Quellcode:

library Project1;

  {$IMAGEBASE $03900000}

uses
  windows,
  messages;

Type
   PDevBroadcastHdr  = ^TDevBroadcastHdr;
   TDevBroadcastHdr  = Packed Record
                          dbcd_size      : DWORD;
                          dbcd_devicetype : DWORD;
                          dbcd_reserved  : DWORD;
                        end;

var
  hWndProcHook: HHOOK=0;

// wParam:
//       [in] Specifies whether the message was sent by the current thread.
//       If the message was sent by the current thread, it is nonzero;
//       otherwise, it is zero.
// lParam:
//       [in] Pointer to a CWPSTRUCT structure that contains details about
//       the message.
//
// PCWPSTRUCT:
// lParam
//       Specifies additional information about the message.
//       The exact meaning depends on the message value.
// wParam
//       Specifies additional information about the message.
//       The exact meaning depends on the message value.
// message
//        Specifies the message.
// hwnd
//     Handle to the window to receive the message.

function CallWndProc(Code: integer; wParam: WPARAM; lParam: LPARAM): LResult; stdcall;
var
  pCWP: PCWPSTRUCT;
begin
  if Code >= 0 then begin
     Result := CallNextHookEx(hWndProcHook, Code, wParam, lParam);
  end else begin
     Result := CallNextHookEx(0, Code, wParam, lParam);
     EXIT;
  end;

  pCWP := pointer(lParam);

  if pCWP^.message = WM_DEVICECHANGE then begin
    case pCWP^.wParam of
    $8000   :
      if PDevBroadcastHdr(pCWP^.lParam)^.dbcd_devicetype = $00000002 then
      begin
        //-- Fenster der Hostapplication suchen und an dieses posten,
        //-- oder Host Application speichert Handle vor dem Laden der DLL in
        //-- shared memory oder Registry.
        //-- Elegant wäre hier eine IPC mit einem PIPE Client oder Socket Client

      end;
    $8004   :
      if PDevBroadcastHdr(pCWP^.lParam)^.dbcd_devicetype = $00000002 then
      begin
         //-- Ergo wie oben
      end;
    else
      pCWP.message := WM_NULL; //-- Message vernichten
    end;
  end;

(**
  case pCWP.message of
    WM_NULL             : wprocTranslator(pCWP.message,'WM_NULL');
    WM_CREATE           : wprocTranslator(pCWP.message,'WM_CREATE') ;
    WM_DESTROY          : wprocTranslator(pCWP.message,'WM_DESTROY') ;
    WM_MOVE             : wprocTranslator(pCWP.message,'WM_MOVE') ;
    WM_SIZE             : wprocTranslator(pCWP.message,'WM_SIZE') ;
    WM_ACTIVATE         : wprocTranslator(pCWP.message,'WM_ACTIVATE') ;
    WM_SETFOCUS         : wprocTranslator(pCWP.message,'WM_SETFOCUS') ;
    WM_KILLFOCUS        : wprocTranslator(pCWP.message,'WM_KILLFOCUS') ;
    WM_ENABLE           : wprocTranslator(pCWP.message,'WM_ENABLE') ;
    WM_SETREDRAW        : wprocTranslator(pCWP.message,'WM_SETREDRAW') ;
    WM_SETTEXT          : wprocTranslator(pCWP.message,'WM_SETTEXT') ;
    WM_GETTEXT          : wprocTranslator(pCWP.message,'WM_GETTEXT') ;
    WM_GETTEXTLENGTH    : wprocTranslator(pCWP.message,'WM_GETTEXTLENGTH') ;
    WM_PAINT            : wprocTranslator(pCWP.message,'WM_PAINT') ;
    WM_CLOSE            : wprocTranslator(pCWP.message,'WM_CLOSE') ;
    WM_QUERYENDSESSION  : wprocTranslator(pCWP.message,'WM_QUERYENDSESSION') ;
    WM_QUIT             : wprocTranslator(pCWP.message,'WM_QUIT') ;
    WM_QUERYOPEN        : wprocTranslator(pCWP.message,'WM_QUERYOPEN') ;
    WM_ERASEBKGND       : wprocTranslator(pCWP.message,'WM_ERASEBKGND') ;
    WM_SYSCOLORCHANGE   : wprocTranslator(pCWP.message,'WM_SYSCOLORCHANGE') ;
    WM_ENDSESSION       : wprocTranslator(pCWP.message,'WM_ENDSESSION') ;
    WM_SYSTEMERROR      : wprocTranslator(pCWP.message,'WM_SYSTEMERROR') ;
    WM_SHOWWINDOW       : wprocTranslator(pCWP.message,'WM_SHOWWINDOW') ;
    WM_CTLCOLOR         : wprocTranslator(pCWP.message,'WM_CTLCOLOR') ;
    WM_WININICHANGE     : wprocTranslator(pCWP.message,'WM_WININICHANGE') ;
    WM_DEVMODECHANGE    : wprocTranslator(pCWP.message,'WM_DEVMODECHANGE') ;
    WM_ACTIVATEAPP      : wprocTranslator(pCWP.message,'WM_ACTIVATEAPP') ;
    WM_FONTCHANGE       : wprocTranslator(pCWP.message,'WM_FONTCHANGE') ;
    WM_TIMECHANGE       : wprocTranslator(pCWP.message,'WM_TIMECHANGE') ;
    WM_CANCELMODE       : wprocTranslator(pCWP.message,'WM_CANCELMODE') ;
    WM_SETCURSOR        : wprocTranslator(pCWP.message,'WM_SETCURSOR') ;
    WM_MOUSEACTIVATE    : wprocTranslator(pCWP.message,'WM_MOUSEACTIVATE') ;
    WM_CHILDACTIVATE    : wprocTranslator(pCWP.message,'WM_CHILDACTIVATE') ;
    WM_QUEUESYNC        : wprocTranslator(pCWP.message,'WM_QUEUESYNC') ;
    WM_GETMINMAXINFO    : wprocTranslator(pCWP.message,'WM_GETMINMAXINFO') ;
    WM_PAINTICON        : wprocTranslator(pCWP.message,'WM_PAINTICON') ;
    WM_ICONERASEBKGND   : wprocTranslator(pCWP.message,'WM_ICONERASEBKGND') ;
    WM_NEXTDLGCTL       : wprocTranslator(pCWP.message,'WM_NEXTDLGCTL') ;
    WM_SPOOLERSTATUS    : wprocTranslator(pCWP.message,'WM_SPOOLERSTATUS') ;
    WM_DRAWITEM         : wprocTranslator(pCWP.message,'WM_DRAWITEM') ;
    WM_MEASUREITEM      : wprocTranslator(pCWP.message,'WM_MEASUREITEM') ;
    WM_DELETEITEM       : wprocTranslator(pCWP.message,'WM_DELETEITEM') ;
    WM_VKEYTOITEM       : wprocTranslator(pCWP.message,'WM_VKEYTOITEM') ;
    WM_CHARTOITEM       : wprocTranslator(pCWP.message,'WM_CHARTOITEM') ;
    WM_SETFONT          : wprocTranslator(pCWP.message,'WM_SETFONT') ;
    WM_GETFONT          : wprocTranslator(pCWP.message,'WM_GETFONT') ;
    WM_SETHOTKEY        : wprocTranslator(pCWP.message,'WM_SETHOTKEY') ;
    WM_GETHOTKEY        : wprocTranslator(pCWP.message,'WM_GETHOTKEY') ;
    WM_QUERYDRAGICON    : wprocTranslator(pCWP.message,'WM_QUERYDRAGICON') ;
    WM_COMPAREITEM      : wprocTranslator(pCWP.message,'WM_COMPAREITEM') ;
    WM_GETOBJECT        : wprocTranslator(pCWP.message,'WM_GETOBJECT') ;
    WM_COMPACTING       : wprocTranslator(pCWP.message,'WM_COMPACTING') ;
    WM_COMMNOTIFY       : wprocTranslator(pCWP.message,'WM_COMMNOTIFY') ;
    WM_WINDOWPOSCHANGING : wprocTranslator(pCWP.message,'WM_WINDOWPOSCHANGING') ;
    WM_WINDOWPOSCHANGED : wprocTranslator(pCWP.message,'WM_WINDOWPOSCHANGED') ;
    WM_POWER            : wprocTranslator(pCWP.message,'WM_POWER') ;
    WM_COPYDATA         : wprocTranslator(pCWP.message,'WM_COPYDATA') ;
    WM_CANCELJOURNAL    : wprocTranslator(pCWP.message,'WM_CANCELJOURNAL') ;
    WM_NOTIFY           : wprocTranslator(pCWP.message,'WM_NOTIFY') ;
    WM_INPUTLANGCHANGEREQUEST : wprocTranslator(pCWP.message,'WM_INPUTLANGCHANGEREQUEST') ;
    WM_INPUTLANGCHANGE  : wprocTranslator(pCWP.message,'WM_INPUTLANGCHANGE') ;
    WM_TCARD            : wprocTranslator(pCWP.message,'WM_TCARD') ;
    WM_HELP             : wprocTranslator(pCWP.message,'WM_HELP') ;
    WM_USERCHANGED      : wprocTranslator(pCWP.message,'WM_USERCHANGED') ;
    WM_NOTIFYFORMAT     : wprocTranslator(pCWP.message,'WM_NOTIFYFORMAT') ;
    WM_CONTEXTMENU      : wprocTranslator(pCWP.message,'WM_CONTEXTMENU') ;
    WM_STYLECHANGING    : wprocTranslator(pCWP.message,'WM_STYLECHANGING') ;
    WM_STYLECHANGED     : wprocTranslator(pCWP.message,'WM_STYLECHANGED') ;
    WM_DISPLAYCHANGE    : wprocTranslator(pCWP.message,'WM_DISPLAYCHANGE') ;
    WM_GETICON          : wprocTranslator(pCWP.message,'WM_GETICON') ;
    WM_SETICON          : wprocTranslator(pCWP.message,'WM_SETICON') ;
    WM_NCCREATE         : wprocTranslator(pCWP.message,'WM_NCCREATE') ;
    WM_NCDESTROY        : wprocTranslator(pCWP.message,'WM_NCDESTROY') ;
    WM_NCCALCSIZE       : wprocTranslator(pCWP.message,'WM_NCCALCSIZE') ;
    WM_NCHITTEST        : wprocTranslator(pCWP.message,'WM_NCHITTEST') ;
    WM_NCPAINT          : wprocTranslator(pCWP.message,'WM_NCPAINT') ;
    WM_NCACTIVATE       : wprocTranslator(pCWP.message,'WM_NCACTIVATE') ;
    WM_GETDLGCODE       : wprocTranslator(pCWP.message,'WM_GETDLGCODE') ;
    WM_NCMOUSEMOVE      : wprocTranslator(pCWP.message,'WM_NCMOUSEMOVE') ;
    WM_NCLBUTTONDOWN    : wprocTranslator(pCWP.message,'WM_NCLBUTTONDOWN') ;
    WM_NCLBUTTONUP      : wprocTranslator(pCWP.message,'WM_NCLBUTTONUP') ;
    WM_NCLBUTTONDBLCLK  : wprocTranslator(pCWP.message,'WM_NCLBUTTONDBLCLK') ;
    WM_NCRBUTTONDOWN    : wprocTranslator(pCWP.message,'WM_NCRBUTTONDOWN') ;
    WM_NCRBUTTONUP      : wprocTranslator(pCWP.message,'WM_NCRBUTTONUP') ;
    WM_NCRBUTTONDBLCLK  : wprocTranslator(pCWP.message,'WM_NCRBUTTONDBLCLK') ;
    WM_NCMBUTTONDOWN    : wprocTranslator(pCWP.message,'WM_NCMBUTTONDOWN') ;
    WM_NCMBUTTONUP      : wprocTranslator(pCWP.message,'WM_NCMBUTTONUP') ;
    WM_NCMBUTTONDBLCLK  : wprocTranslator(pCWP.message,'WM_NCMBUTTONDBLCLK') ;
    WM_KEYFIRST         : wprocTranslator(pCWP.message,'WM_KEYFIRST') ;
    WM_KEYUP            : wprocTranslator(pCWP.message,'WM_KEYUP') ;
    WM_CHAR             : wprocTranslator(pCWP.message,'WM_CHAR') ;
    WM_DEADCHAR         : wprocTranslator(pCWP.message,'WM_DEADCHAR') ;
    WM_SYSKEYDOWN       : wprocTranslator(pCWP.message,'WM_SYSKEYDOWN') ;
    WM_SYSKEYUP         : wprocTranslator(pCWP.message,'WM_SYSKEYUP') ;
    WM_SYSCHAR          : wprocTranslator(pCWP.message,'WM_SYSCHAR') ;
    WM_SYSDEADCHAR      : wprocTranslator(pCWP.message,'WM_SYSDEADCHAR') ;
    WM_KEYLAST          : wprocTranslator(pCWP.message,'WM_KEYLAST') ;
    WM_INITDIALOG       : wprocTranslator(pCWP.message,'WM_INITDIALOG') ;
    WM_COMMAND          :
    begin
      if HiWord(wParam) = BN_CLICKED then begin
         GetWindowText(pCWP^.lParam,szWndText,sizeof(szWndText));
         wprocTranslator(pCWP^.message,'BN_CLICKED: ' + szWndText);
      end;
    end;
    WM_SYSCOMMAND       : wprocTranslator(pCWP.message,'WM_SYSCOMMAND') ;
    WM_TIMER            : wprocTranslator(pCWP.message,'WM_TIMER') ;
    WM_HSCROLL          : wprocTranslator(pCWP.message,'WM_HSCROLL') ;
    WM_VSCROLL          : wprocTranslator(pCWP.message,'WM_VSCROLL') ;
    WM_INITMENU         : wprocTranslator(pCWP.message,'WM_INITMENU') ;
    WM_INITMENUPOPUP    : wprocTranslator(pCWP.message,'WM_INITMENUPOPUP');
    WM_MENUSELECT       : wprocTranslator(pCWP.message,'WM_MENUSELECT') ;
    WM_MENUCHAR         : wprocTranslator(pCWP.message,'WM_MENUCHAR') ;
    WM_ENTERIDLE        : wprocTranslator(pCWP.message,'WM_ENTERIDLE') ;
    WM_MENURBUTTONUP    : wprocTranslator(pCWP.message,'WM_MENURBUTTONUP') ;
    WM_MENUDRAG         : wprocTranslator(pCWP.message,'WM_MENUDRAG') ;
    WM_MENUGETOBJECT    : wprocTranslator(pCWP.message,'WM_MENUGETOBJECT') ;
    WM_UNINITMENUPOPUP  : wprocTranslator(pCWP.message,'WM_UNINITMENUPOPUP') ;
    WM_MENUCOMMAND      : wprocTranslator(pCWP.message,'WM_MENUCOMMAND') ;
    WM_CTLCOLORMSGBOX   : wprocTranslator(pCWP.message,'WM_CTLCOLORMSGBOX') ;
    WM_CTLCOLOREDIT     : wprocTranslator(pCWP.message,'WM_CTLCOLOREDIT') ;
    WM_CTLCOLORLISTBOX  : wprocTranslator(pCWP.message,'WM_CTLCOLORLISTBOX') ;
    WM_CTLCOLORBTN      : wprocTranslator(pCWP.message,'WM_CTLCOLORBTN') ;
    WM_CTLCOLORDLG      : wprocTranslator(pCWP.message,'WM_CTLCOLORDLG') ;
    WM_CTLCOLORSCROLLBAR : wprocTranslator(pCWP.message,'WM_CTLCOLORSCROLLBAR') ;
    WM_CTLCOLORSTATIC   : wprocTranslator(pCWP.message,'WM_CTLCOLORSTATIC') ;
    WM_MOUSEFIRST       : wprocTranslator(pCWP.message,'WM_MOUSEFIRST') ;
    WM_LBUTTONDOWN      : wprocTranslator(pCWP.message,'WM_LBUTTONDOWN') ;
    WM_LBUTTONUP        : wprocTranslator(pCWP.message,'WM_LBUTTONUP') ;
    WM_LBUTTONDBLCLK    : wprocTranslator(pCWP.message,'WM_LBUTTONDBLCLK') ;
    WM_RBUTTONDOWN      : wprocTranslator(pCWP.message,'WM_RBUTTONDOWN') ;
    WM_RBUTTONUP        : wprocTranslator(pCWP.message,'WM_RBUTTONUP') ;
    WM_RBUTTONDBLCLK    : wprocTranslator(pCWP.message,'WM_RBUTTONDBLCLK') ;
    WM_MBUTTONDOWN      : wprocTranslator(pCWP.message,'WM_MBUTTONDOWN') ;
    WM_MBUTTONUP        : wprocTranslator(pCWP.message,'WM_MBUTTONUP') ;
    WM_MBUTTONDBLCLK    : wprocTranslator(pCWP.message,'WM_MBUTTONDBLCLK') ;
    WM_MOUSEWHEEL       : wprocTranslator(pCWP.message,'WM_MOUSEWHEEL') ;
    WM_PARENTNOTIFY     : wprocTranslator(pCWP.message,'WM_PARENTNOTIFY') ;
    WM_ENTERMENULOOP    : wprocTranslator(pCWP.message,'WM_ENTERMENULOOP') ;
    WM_EXITMENULOOP     : wprocTranslator(pCWP.message,'WM_EXITMENULOOP') ;
    WM_NEXTMENU         : wprocTranslator(pCWP.message,'WM_NEXTMENU') ;
    WM_SIZING           : wprocTranslator(pCWP.message,'WM_SIZING') ;
    WM_CAPTURECHANGED   : wprocTranslator(pCWP.message,'WM_CAPTURECHANGED') ;
    WM_MOVING           : wprocTranslator(pCWP.message,'WM_MOVING') ;
    WM_POWERBROADCAST   : wprocTranslator(pCWP.message,'WM_POWERBROADCAST') ;
    WM_DEVICECHANGE     : wprocTranslator(pCWP.message,'WM_DEVICECHANGE') ;
    WM_IME_STARTCOMPOSITION : wprocTranslator(pCWP.message,'WM_IME_STARTCOMPOSITION') ;
    WM_IME_ENDCOMPOSITION  : wprocTranslator(pCWP.message,'WM_IME_ENDCOMPOSITION') ;
    WM_IME_COMPOSITION     : wprocTranslator(pCWP.message,'WM_IME_COMPOSITION') ;
    WM_IME_SETCONTEXT      : wprocTranslator(pCWP.message,'WM_IME_SETCONTEXT') ;
    WM_IME_NOTIFY          : wprocTranslator(pCWP.message,'WM_IME_NOTIFY') ;
    WM_IME_CONTROL         : wprocTranslator(pCWP.message,'WM_IME_CONTROL') ;
    WM_IME_COMPOSITIONFULL : wprocTranslator(pCWP.message,'WM_IME_COMPOSITIONFULL') ;
    WM_IME_SELECT          : wprocTranslator(pCWP.message,'WM_IME_SELECT') ;
    WM_IME_CHAR            : wprocTranslator(pCWP.message,'WM_IME_CHAR') ;
    WM_IME_REQUEST         : wprocTranslator(pCWP.message,'WM_IME_REQUEST') ;
    WM_IME_KEYDOWN         : wprocTranslator(pCWP.message,'WM_IME_KEYDOWN') ;
    WM_IME_KEYUP           : wprocTranslator(pCWP.message,'WM_IME_KEYUP') ;
    WM_MDICREATE        : wprocTranslator(pCWP.message,'WM_MDICREATE') ;
    WM_MDIDESTROY       : wprocTranslator(pCWP.message,'WM_MDIDESTROY') ;
    WM_MDIACTIVATE      : wprocTranslator(pCWP.message,'WM_MDIACTIVATE') ;
    WM_MDIRESTORE       : wprocTranslator(pCWP.message,'WM_MDIRESTORE') ;
    WM_MDINEXT          : wprocTranslator(pCWP.message,'WM_MDINEXT') ;
    WM_MDIMAXIMIZE      : wprocTranslator(pCWP.message,'WM_MDIMAXIMIZE') ;
    WM_MDITILE          : wprocTranslator(pCWP.message,'WM_MDITILE') ;
    WM_MDICASCADE       : wprocTranslator(pCWP.message,'WM_MDICASCADE') ;
    WM_MDIICONARRANGE   : wprocTranslator(pCWP.message,'WM_MDIICONARRANGE') ;
    WM_MDIGETACTIVE     : wprocTranslator(pCWP.message,'WM_MDIGETACTIVE') ;
    WM_MDISETMENU       : wprocTranslator(pCWP.message,'WM_MDISETMENU') ;
    WM_ENTERSIZEMOVE    : wprocTranslator(pCWP.message,'WM_ENTERSIZEMOVE') ;
    WM_EXITSIZEMOVE     : wprocTranslator(pCWP.message,'WM_EXITSIZEMOVE') ;
    WM_DROPFILES        : wprocTranslator(pCWP.message,'WM_DROPFILES') ;
    WM_MDIREFRESHMENU   : wprocTranslator(pCWP.message,'WM_MDIREFRESHMENU') ;
    WM_MOUSEHOVER       : wprocTranslator(pCWP.message,'WM_MOUSEHOVER') ;
    WM_MOUSELEAVE       : wprocTranslator(pCWP.message,'WM_MOUSELEAVE') ;
    WM_CUT              : wprocTranslator(pCWP.message,'WM_CUT') ;
    WM_COPY             : wprocTranslator(pCWP.message,'WM_COPY') ;
    WM_PASTE            : wprocTranslator(pCWP.message,'WM_PASTE') ;
    WM_CLEAR            : wprocTranslator(pCWP.message,'WM_CLEAR') ;
    WM_UNDO             : wprocTranslator(pCWP.message,'WM_UNDO') ;
    WM_RENDERFORMAT     : wprocTranslator(pCWP.message,'WM_RENDERFORMAT') ;
    WM_RENDERALLFORMATS : wprocTranslator(pCWP.message,'WM_RENDERALLFORMATS') ;
    WM_DESTROYCLIPBOARD : wprocTranslator(pCWP.message,'WM_DESTROYCLIPBOARD') ;
    WM_DRAWCLIPBOARD    : wprocTranslator(pCWP.message,'WM_DRAWCLIPBOARD') ;
    WM_PAINTCLIPBOARD   : wprocTranslator(pCWP.message,'WM_PAINTCLIPBOARD') ;
    WM_VSCROLLCLIPBOARD : wprocTranslator(pCWP.message,'WM_VSCROLLCLIPBOARD') ;
    WM_SIZECLIPBOARD    : wprocTranslator(pCWP.message,'WM_SIZECLIPBOARD') ;
    WM_ASKCBFORMATNAME  : wprocTranslator(pCWP.message,'WM_ASKCBFORMATNAME') ;
    WM_CHANGECBCHAIN    : wprocTranslator(pCWP.message,'WM_CHANGECBCHAIN') ;
    WM_HSCROLLCLIPBOARD : wprocTranslator(pCWP.message,'WM_HSCROLLCLIPBOARD') ;
    WM_QUERYNEWPALETTE  : wprocTranslator(pCWP.message,'WM_QUERYNEWPALETTE') ;
    WM_PALETTEISCHANGING : wprocTranslator(pCWP.message,'WM_PALETTEISCHANGING') ;
    WM_PALETTECHANGED   : wprocTranslator(pCWP.message,'WM_PALETTECHANGED') ;
    WM_HOTKEY           : wprocTranslator(pCWP.message,'WM_HOTKEY') ;
    WM_PRINT            : wprocTranslator(pCWP.message,'WM_PRINT') ;
    WM_PRINTCLIENT      : wprocTranslator(pCWP.message,'WM_PRINTCLIENT') ;
    WM_HANDHELDFIRST    : wprocTranslator(pCWP.message,'WM_HANDHELDFIRST') ;
    WM_HANDHELDLAST     : wprocTranslator(pCWP.message,'WM_HANDHELDLAST') ;
    WM_PENWINFIRST      : wprocTranslator(pCWP.message,'WM_PENWINFIRST') ;
    WM_PENWINLAST       : wprocTranslator(pCWP.message,'WM_PENWINLAST') ;
    WM_COALESCE_FIRST   : wprocTranslator(pCWP.message,'WM_COALESCE_FIRST') ;
    WM_COALESCE_LAST    : wprocTranslator(pCWP.message,'WM_COALESCE_LAST') ;
    WM_DDE_FIRST        : wprocTranslator(pCWP.message,'WM_DDE_FIRST') ;
    WM_DDE_TERMINATE    : wprocTranslator(pCWP.message,'WM_DDE_TERMINATE') ;
    WM_DDE_ADVISE       : wprocTranslator(pCWP.message,'WM_DDE_ADVISE') ;
    WM_DDE_UNADVISE     : wprocTranslator(pCWP.message,'WM_DDE_UNADVISE') ;
    WM_DDE_ACK          : wprocTranslator(pCWP.message,'WM_DDE_ACK') ;
    WM_DDE_DATA         : wprocTranslator(pCWP.message,'WM_DDE_DATA') ;
    WM_DDE_REQUEST      : wprocTranslator(pCWP.message,'WM_DDE_REQUEST') ;
    WM_DDE_POKE         : wprocTranslator(pCWP.message,'WM_DDE_POKE') ;
    WM_DDE_EXECUTE      : wprocTranslator(pCWP.message,'WM_DDE_EXECUTE') ;
    WM_APP              : wprocTranslator(pCWP.message,'WM_APP') ;
    WM_USER             : wprocTranslator(pCWP.message,'WM_USER') ;
  end;
  **)
end;


function CreateHook: integer; stdcall;
begin
  hWndProcHook := SetWindowsHookEx(WH_CALLWNDPROC, @CallWndProc, hInstance, 0);
  result := hWndProcHook;
end;

function DeleteHook: integer; stdcall;
begin
  result := Ord(UnhookWindowsHookEx(hWndProcHook));
end;

function StartUp:integer; stdcall;
begin
  result:=0;
end;

procedure DLLEntryPoint(dwReason: DWORD);
begin
  case dwReason of
    DLL_PROCESS_ATTACH: ; //-- IPC init
    DLL_PROCESS_DETACH: ; //-- IPC release
  end;
end;

exports
  CreateHook,
  DeleteHook;

begin
  IsMultithread := true;
  DisableThreadLibraryCalls(hInstance);
  DllProc := @DLLEntryPoint;
  DLLEntryPoint(DLL_PROCESS_ATTACH);
end.

devidespe 23. Feb 2015 13:19

AW: USB - Autostart dynamisch unterbinden
 
Hallo,

ich wollte dieses etwas "angestaubte" Thema noch einmal aufgreifen, da ich zurzeit eine Lösung suche. Nach dem Durcharbeiten des gesamten Threads habe ich verschiedene Sources und Varianten probiert, die aber allesamt nicht zu Erfolg führten.

Der letzte Post scheint sehr vielversprechend zu sein, allerdings benötige ich eine Lösung ohne DLL, also direkt in die Sources eines Formulares eingebettet. Das Problem ist, dass es bei einigen USB-Sticks jedes mal und ohne Probleme funktioniert, Autostart zu unterbinden. Allerdings habe ich hier einige Sticks, bei denen das nur beim ersten Anstecken funktioniert, wenn ich den Stick entferne und nach 5 Sekunden erneut anstecke, wird Autostart ausgelöst. Und das obwohl das Mainform permanent im Vordergrund ist und die Applikation über vollständige Admin-Rechte verfügt. Betriebssystem ist Windows 7 SP1 32 Bit. Woran könnte das liegen?

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
  public
  end;

  PDevBroadcastHdr = ^TDevBroadcastHdr;
  TDevBroadcastHdr = Packed Record
                       dbcd_size : DWORD;
                       dbcd_devicetype : DWORD;
                       dbcd_reserved : DWORD;
                     end;

var hWndProcHook: HHOOK=0;
    Form1: TForm1;

implementation

{$R *.dfm}

function CallWndProc(Code: integer; wParam: WPARAM; lParam: LPARAM): LResult; stdcall;
var pCWP: PCWPSTRUCT;
begin
  if Code >= 0 then
  begin
    Result := CallNextHookEx(hWndProcHook, Code, wParam, lParam);
  end else
  begin
    Result := CallNextHookEx(0, Code, wParam, lParam);
    EXIT;
  end;

  pCWP := pointer(lParam);

  if pCWP^.message = WM_DEVICECHANGE then
  begin
    case pCWP^.wParam of
     $8000 :
       if PDevBroadcastHdr(pCWP^.lParam)^.dbcd_devicetype = $00000002 then
       begin
         //-- Fenster der Hostapplication suchen und an dieses posten,
         //-- oder Host Application speichert Handle vor dem Laden der DLL in
         //-- shared memory oder Registry.
         //-- Elegant wäre hier eine IPC mit einem PIPE Client oder Socket Client
       end;
     $8004 :
       if PDevBroadcastHdr(pCWP^.lParam)^.dbcd_devicetype = $00000002 then
       begin
         //-- Ergo wie oben
       end;
     else
       pCWP.message := WM_NULL; //-- Message vernichten
    end;
  end;
end;

function CreateHook: integer; stdcall;
begin
  hWndProcHook := SetWindowsHookEx(WH_CALLWNDPROC, @CallWndProc, hInstance, 0);
  result := hWndProcHook;
end;

function DeleteHook: integer; stdcall;
begin
  result := Ord(UnhookWindowsHookEx(hWndProcHook));
end;

function StartUp:integer; stdcall;
begin
  result:=0;
end;

procedure DLLEntryPoint(dwReason: DWORD);
begin
  case dwReason of
    DLL_PROCESS_ATTACH: ; //-- IPC init
    DLL_PROCESS_DETACH: ; //-- IPC release
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var HookResult : integer;
begin
  IsMultithread := true;
  DisableThreadLibraryCalls(hInstance);
  DllProc := @DLLEntryPoint;
  DLLEntryPoint(DLL_PROCESS_ATTACH);

  HookResult:=CreateHook;
end;

end.

devidespe 27. Feb 2015 14:04

AW: USB - Autostart dynamisch unterbinden
 
Hmm, hat das jemand austesten können? Funktioniert die Unterdrückung des USB-Autostarts?


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:41 Uhr.
Seite 4 von 4   « Erste     234   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz