一种利用Windows未公开函数实现机器上所做的各种操作

2019-10-08 09:56:00王旭

  SHCNF_PATH = SHCNF_PATHW;
  SHCNF_PRINTER = SHCNF_PRINTERW;
  WM_SHNOTIFY = $401;
  NOERROR = 0;
  type
  TForm1 = class(TForm)
  Button1: TButton;
  Memo1: TMemo;
  procedure FormClose(Sender: TObject; var Action: TCloseAction);
  procedure Button1Click(Sender: TObject);
  procedure FormCreate(Sender: TObject);
  private
  { Private declarations }
  procedure WMShellReg(var Message:TMessage);message WM_SHNOTIFY;
  public
  { Public declarations }
  end;
  type PSHNOTIFYSTRUCT=^SHNOTIFYSTRUCT;
  SHNOTIFYSTRUCT = record
  dwItem1 : PItemIDList;
  dwItem2 : PItemIDList;
  end;
  Type PSHFileInfoByte=^SHFileInfoByte;
  _SHFileInfoByte = record
  hIcon :Integer;
  iIcon :Integer;
  dwAttributes : Integer;
  szDisplayName : array [0..259] of char;
  szTypeName : array [0..79] of char;
  end;
  SHFileInfoByte=_SHFileInfoByte;
  Type PIDLSTRUCT = ^IDLSTRUCT;
  _IDLSTRUCT = record
  pidl : PItemIDList;
  bWatchSubFolders : Integer;
  end;
  IDLSTRUCT =_IDLSTRUCT;
  function SHNotify_Register(hWnd : Integer) : Bool;
  function SHNotify_UnRegister:Bool;
  function SHEventName(strPath1,strPath2:string;lParam:Integer):string;
  Function SHChangeNotifyDeregister(hNotify:integer):integer;stdcall;
  external 'Shell32.dll ' index 4;
  Function SHChangeNotifyRegister(hWnd,uFlags,dwEventID,uMSG,cItems:LongWord;
  lpps:PIDLSTRUCT):integer;stdcall;external 'Shell32.dll ' index 2;
  Function SHGetFileInfoPidl(pidl : PItemIDList;
  dwFileAttributes : Integer;
  psfib : PSHFILEINFOBYTE;
  cbFileInfo : Integer;
  uFlags : Integer):Integer;stdcall;
  external 'Shell32.dll ' name 'SHGetFileInfoA ';
  var
  Form1: TForm1;
  m_hSHNotify:Integer;
  m_pidlDesktop : PItemIDList;
  implementation
  {$R *.DFM}
  function SHEventName(strPath1,strPath2:string;lParam:Integer):string;
  var
  sEvent:String;
  begin
  case lParam of //根据参数设置提示消息
  SHCNE_RENAMEITEM: sEvent := '重命名文件 '+strPath1+ '为 '+strpath2;
  SHCNE_Create: sEvent := '建立文件 文件名: '+strPath1;
  SHCNE_Delete: sEvent := '删除文件 文件名: '+strPath1;
  SHCNE_MKDIR: sEvent := '新建目录 目录名: '+strPath1;
  SHCNE_RMDIR: sEvent := '删除目录 目录名: '+strPath1;
  SHCNE_MEDIAInsertED: sEvent := strPath1+ '中插入可移动存储介质 ';
  SHCNE_MEDIAREMOVED: sEvent := strPath1+ '中移去可移动存储介质 '+strPath1+ ' '+strpath2;