Wolfgang Chien's Homepage | Delphi學習筆記 - 問答篇 |
I have a question to know how to get Win95 System User Name and Series Number, and how the delphi to get this information.
(更正: 若只是抓現行使用者名稱, WNetGetUser 的第一個引數要改成 nil)
![]() |
1. 可以用 WNetGetUser() 這個函數偵測 user name; |
![]() |
2. Windows 95 的產品序號可以用 TRegistry 到 Registry Database 中找出來; |
// // 取得使用者名稱 // 本函式包裝 WNetGetUser() API // 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 } // GetUserName() 使用示例 procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage(GetUserName); end; // // 取得 Windows 產品序號 // // uses ..., Registry; 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; // GetWindowsProductID() 使用示例 procedure TForm1.Button2Click(Sender: TObject); begin ShowMessage(GetWindowsProductID); end;
首頁 | 學習筆記 | 主題公園 | 軟體下載 | 關於本站 | 討論信群 | 相約下次 |