K
kenny_liao
Unregistered / Unconfirmed
GUEST, unregistred user!
女友给我的任务,由于她公司的电脑总是被一些人偷窥,
她很想把那些人揪出...
我出点子用dos命令(Net session)
或计算机管理中的功能,
但都不是很方便,于是叫我这个搞程序的给她写一个,
本以为是一件很简单的事,可还是写不出来.
下面是网上拿来的,可是Win2000无法成功获取与本机连接的用户清单...
找不出原因.
const
MaxNetArrayItems = 512;
type
TSessionInfo50 = packed record
sesi50_cname: PChar; //remote computer name (connection id in Netware)
sesi50_username: PChar;
sesi50_key: DWORD; // used to delete session (not used in Netware)
sesi50_num_conns: Word;
sesi50_num_opens: Word; //not available in Netware
sesi50_time: DWORD;
sesi50_idle_time: DWORD; //not available in Netware
sesi50_protocol: Char;
padl: Char;
end;
TNetSessionEnum = function (const pszServer: PChar; sLevel: SmallInt;
pbBuffer: Pointer; cbBuffer: Word; var pcEntriesRead: Word;
var pcTotalAvail: Word): DWORD; stdcall;
procedure GetNetSessions(ComputerNames: TStrings);
var
SessionInfo: array[0..MaxNetArrayItems] of TSessionInfo50;
EntriesRead, TotalAvail: Word;
I: Integer;
Str: string;
NetSessionEnum: TNetSessionEnum;
LibHandle: THandle;
begin
ComputerNames.Clear;
LibHandle := LoadLibrary('NETAPI32.DLL');
if LibHandle <> 0 then
begin
try
@NetSessionEnum := GetProcAddress(LibHandle, 'NetSessionEnum');
if (@NetSessionEnum <> nil) then
if NetSessionEnum(nil, 50, @SessionInfo, Sizeof(SessionInfo), EntriesRead, TotalAvail) = 0 then
begin
for I := 0 to EntriesRead - 1 do
with SessionInfo do
begin
SetString(Str, sesi50_cname, StrLen(sesi50_cname));
ComputerNames.Add(Str);
end;
end;
finally
FreeLibrary(LibHandle);
end;
end;
end;
她很想把那些人揪出...
我出点子用dos命令(Net session)
或计算机管理中的功能,
但都不是很方便,于是叫我这个搞程序的给她写一个,
本以为是一件很简单的事,可还是写不出来.
下面是网上拿来的,可是Win2000无法成功获取与本机连接的用户清单...
找不出原因.
const
MaxNetArrayItems = 512;
type
TSessionInfo50 = packed record
sesi50_cname: PChar; //remote computer name (connection id in Netware)
sesi50_username: PChar;
sesi50_key: DWORD; // used to delete session (not used in Netware)
sesi50_num_conns: Word;
sesi50_num_opens: Word; //not available in Netware
sesi50_time: DWORD;
sesi50_idle_time: DWORD; //not available in Netware
sesi50_protocol: Char;
padl: Char;
end;
TNetSessionEnum = function (const pszServer: PChar; sLevel: SmallInt;
pbBuffer: Pointer; cbBuffer: Word; var pcEntriesRead: Word;
var pcTotalAvail: Word): DWORD; stdcall;
procedure GetNetSessions(ComputerNames: TStrings);
var
SessionInfo: array[0..MaxNetArrayItems] of TSessionInfo50;
EntriesRead, TotalAvail: Word;
I: Integer;
Str: string;
NetSessionEnum: TNetSessionEnum;
LibHandle: THandle;
begin
ComputerNames.Clear;
LibHandle := LoadLibrary('NETAPI32.DLL');
if LibHandle <> 0 then
begin
try
@NetSessionEnum := GetProcAddress(LibHandle, 'NetSessionEnum');
if (@NetSessionEnum <> nil) then
if NetSessionEnum(nil, 50, @SessionInfo, Sizeof(SessionInfo), EntriesRead, TotalAvail) = 0 then
begin
for I := 0 to EntriesRead - 1 do
with SessionInfo do
begin
SetString(Str, sesi50_cname, StrLen(sesi50_cname));
ComputerNames.Add(Str);
end;
end;
finally
FreeLibrary(LibHandle);
end;
end;
end;