2008年9月10日 星期三

用Win32 API 得到 電腦名稱和登入使用者名稱

今天老闆請我找這個API

直覺就是在MSDN上鍵入 GetComputerName, 結果 竟然有這個API (會不會運氣太好了)
就研究一下 (MSDN 介紹在此)

這個 API 剛好就是我要的

Syntax

BOOL WINAPI GetComputerName(
__out LPTSTR lpBuffer,
__inout LPDWORD lpnSize
);

Parameters

lpBuffer [out]

A pointer to a buffer that receives the computer name or the cluster virtual server name. The buffer size should be large enough to contain MAX_COMPUTERNAME_LENGTH + 1 characters.

lpnSize [in, out]

On input, specifies the size of the buffer, in TCHARs. On output, the number of TCHARs copied to the destination buffer, not including the terminating null character.

If the buffer is too small, the function fails and GetLastError returns ERROR_BUFFER_OVERFLOW. The lpnSize parameter specifies the size of the buffer required, not including the terminating null character.

Return Value

If the function succeeds, the return value is a nonzero value.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

就這樣 滿足了老闆的要求

沒有留言: