如何得到Windows的用戶名稱和產品序列號呢? 1. 可以用 WNetGetUser() 這個函數來得到 user name; 2. Windows 95 的產品序號可以用 TRegistry 到 Registry Database 中找出來;
// 取得用戶名稱 function GetUserName: AnsiString; var lpName: PAnsiChar; lpUserName: PAnsiChar; lpnLength: DWord; begin Result := ''; lpnLength := 0; WNetGetUser(nil, nil, lpnLength); // 取得字串長度 if lpnLength > 0 then begin GetMem(lpUserName, lpnLength); if WNetGetUser(lpName, lpUserName, lpnLength) = NO_ERROR then Result := lpUserName; FreeMem(lpUserName, lpnLength); end; end; { GetUserName }
// 取得 Windows 產品序號 function GetWindowsProductID: string; var reg: TRegistry; begin Result := ''; reg := TRegistry.Create; with reg do begin RootKey := HKEY_LOCAL_MacHINE; OpenKey('Software\Microsoft\Windows\CurrentVersion', False); Result := ReadString('ProductID'); end; reg.Free; end;
var HWndCalculator : HWnd; begin // find the exist calculator window HWndCalculator := Winprocs.FindWindow(nil, '計算器'); // close the exist Calculator if HWndCalculator <> 0 then SendMessage(HWndCalculator, WM_CLOSE, 0, 0); end;