关闭所有正在运行的程序:<br>procedure TForm1.ButtonKillAllClick(Sender: TObject);<br>var<br> pTask : PTaskEntry;<br> Task : Bool;<br> ThisTask: THANDLE;<br>begin<br> GetMem (pTask, SizeOf (TTaskEntry));<br> pTask^.dwSize := SizeOf (TTaskEntry);<br> Task := TaskFirst (pTask);<br> while Task do<br> begin<br> if pTask^.hInst = hInstance then<br> ThisTask := pTask^.hTask<br> else<br> TerminateApp (pTask^.hTask, NO_UAE_BOX);<br> Task := TaskNext (pTask);<br> end;<br> TerminateApp (ThisTask, NO_UAE_BOX);<br>end;<br>重新启动Windows,不是重新启动机器!包含Thunk技术。<br><br>感谢http://www.experts-exchange.com/Q.10115419, 以下代码RestartWindows可以实现:<br>{$StackFrames On} //QT_Thunk needs a stack frame, Thunking call to 16-bit USER.EXE. The ThunkTrash argument allocates space on the stack for QT_Thunk<br>function LoadLibrary16(LibraryName: PChar): THandle; stdcall; external kernel32 index 35;<br>procedure FreeLibrary16(HInstance: THandle); stdcall; external kernel32 index 36;<br>function GetProcAddress16(Hinstance: THandle; ProcName: PChar): Pointer; stdcall; external kernel32 index 37;<br>procedure QT_Thunk; cdecl; external kernel32 name 'QT_Thunk';<br>var<br> hInst16: THandle;<br> GFSR: Pointer;<br>function RestartWindows: WordBool;<br>var<br> ThunkTrash: array[0..$20] of Word;<br> dw: DWord;<br> w: Word;<br>begin<br> if Win32Platform = VER_PLATFORM_WIN32_NT then<br> begin<br> Result := False;<br> Exit;<br> end;<br> ThunkTrash[0] := hInst16; //Prevent the optimizer from getting rid of ThunkTrash<br> hInst16 := LoadLibrary16('user.exe');<br> if hInst16 < 32 then<br> raise Exception.Create('Cannot load USER.EXE');<br> FreeLibrary16(hInst16); //Decrement the usage count. This doesn't really free the library, since USER.EXE is always loaded<br> GFSR := GetProcAddress16(hInst16, 'ExitWindows'); //Get the function pointer for the 16-bit function in USER.EXE<br> if GFSR = nil then<br> raise Exception.Create('Cannot get address of ExitWindows');<br> dw := EW_RestartWindows;<br> w := 0;<br> asm //Thunk down to USER.EXE<br> push dw { push arguments }<br> push w<br> mov edx, GFSR { load 16-bit procedure pointer }<br> call QT_Thunk { call thunk }<br> mov Result, ax { save the result }<br> end;<br>end;<br>{$StackFrames Off}<br><br>如何知道进程使用了多少内存<br>// Works only on Windows NT systems (WinNT, Win2000, WinXP) <br>uses psAPI;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> pmc: PPROCESS_MEMORY_COUNTERS;<br> cb: Integer;<br>begin<br> cb := SizeOf(_PROCESS_MEMORY_COUNTERS);<br> GetMem(pmc, cb);<br> pmc^.cb := cb;<br> if GetProcessMemoryInfo(GetCurrentProcess(), pmc, cb) then<br> Label1.Caption := IntToStr(pmc^.WorkingSetSize) + ' Bytes'<br> else<br> Label1.Caption := 'Unable to retrieve memory usage structure';<br><br> FreeMem(pmc);<br>end;<br>几个基本的例子,由此可演化得到许多硬件信息。<br>结果放在Memo1中。<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> systeminfo: SYSTEM_INFO;<br> memory: MEMORYSTATUS;<br> sector,byte,cluster,free: DWORD;<br> freespace,totalspace: longint;<br> CDtype: UINT;<br> name: CHAR;<br> drvname: string;<br> volname,filesysname: PCHAR;<br> sno,maxl,fileflag: DWORD;<br>begin<br> Memo1.Lines.Clear();<br> //获得CPU型号<br> GetSystemInfo(systeminfo);<br> Memo1.Lines.Add('您的CPU类型是:' + inttostr(systeminfo.dwProcessorType));<br><br> //获得内存状态<br> memory.dwLength := sizeof(memory); //初始化<br> GlobalMemoryStatus(memory);<br> Memo1.Lines.Add('您的物理内存是(' + inttostr(integer(memory.dwTotalPhys div 1024 div 1024)) + 'MB)。');<br> Memo1.Lines.Add('其中可用内存是(' + inttostr(integer(memory.dwTotalPhys div 1024)) + 'KB)。');<br><br> //获得C盘可用空间<br> GetDiskFreeSpace('C:', LPDWORD(@sector)^, LPDWORD(@byte)^, LPDWORD(@free)^, LPDWORD(@cluster)^); //获得返回参数<br> totalspace := cluster * byte * sector div 1024 div 1024; //计算总容量<br> freespace := free * byte * sector div 1024 div 1024; //计算可用空间<br> Memo1.Lines.Add('C盘总空间(' + inttostr(integer(totalspace)) + 'MB)。');<br> Memo1.Lines.Add('C盘可用空间(' + inttostr(integer(freespace)) + 'MB)。');<br><br> //检测CD-ROM,是否有光盘<br> GetMem(volname, 255);<br> GetMem(filesysname, 100);<br> for name :='C' to 'Z' do//循环检测A~Z<br> begin<br> drvname := name + ':';<br> CDtype := GetDriveType(PCHAR(@drvname[1])); //获得磁盘类型<br> if (CDtype = DRIVE_CDROM) then<br> begin<br> Memo1.Lines.Add('您的光驱盘符为[' + drvname + ']');<br> volname^ := Chr(0);<br> filesysname^ := Chr(0);<br> if ( not (GetVolumeInformation(PCHAR(@drvname[1]), volname, 250, LPDWORD(@sno), LPDWORD(@maxl)^, LPDWORD(@fileflag)^, filesysname,100))) then<br> Memo1.Lines.Add(drvname + '驱中没有发现光盘') //如果返回值为假<br> else //如果返回值为真<br> begin<br> Memo1.Lines.Add (drvname + '驱中光盘卷标为: [' + String(volname) + ']');<br> Memo1.Lines.Add (drvname + '驱中光盘序号为: [' + inttostr(sno) + ']');<br> end;<br> end;<br> end;<br> FreeMem(volname);<br> FreeMem(filesysname)<br>end;<br><br>