T tonycn Unregistered / Unconfirmed GUEST, unregistred user! 2002-09-05 #1 在Win98下登录到域后,怎样取得登录后的域名(Domain Name)<br>需列明使用的API,及取得域名的过程。<br>请指教,谢谢!
飘 飘摇客 Unregistered / Unconfirmed GUEST, unregistred user! 2002-09-05 #2 98下好像在注册表的 <br>HKEY_LOCAL_MACHINE/System <br>/CurrentControlSet/Services/VxD/MSTCP/,如果不是查找一下Domain<br>2000下在<br>HKEY_LOCAL_MACHINE/System/ControlSet001/Services/Tcpip/Parameters中.
98下好像在注册表的 <br>HKEY_LOCAL_MACHINE/System <br>/CurrentControlSet/Services/VxD/MSTCP/,如果不是查找一下Domain<br>2000下在<br>HKEY_LOCAL_MACHINE/System/ControlSet001/Services/Tcpip/Parameters中.
N NeiTech Unregistered / Unconfirmed GUEST, unregistred user! 2002-09-06 #3 procedure TForm1.Button2Click(Sender: TObject);<br>var<br> i: Integer;<br> ssGroupList: TStrings;<br> ssaUserList: array of TStrings;<br>begin<br> FpssPCInfo.Clear;<br> ssGroupList := TStringList.Create;<br> try<br> GetGroupList(ssGroupList);<br> SetLength(ssaUserList, ssGroupList.Count);<br> for i := 0 to ssGroupList.Count - 1 do<br> begin<br> ssaUserList := TStringList.Create;<br> GetUserList(ssGroupList, ssaUserList);<br> FpssPCInfo.AddObject(ssGroupList, ssaUserList);<br> end;<br> finally<br> ssGroupList.Free;<br> end;<br>end;<br><br>function TForm1.GetGroupList(assGroupNames: TStrings): Boolean;<br>var<br> NetResource : TNetResource;<br> Buf : Pointer;<br> Count,BufSize,Res : DWORD;<br> lphEnum : THandle;<br> p NetResource;<br> i,j : SmallInt;<br> NetworkTypeList : TList;<br>begin<br> Result := False;<br> NetworkTypeList := TList.Create;<br> assGroupNames.Clear;<br><br> //获取整个网络中的文件资源的句柄,lphEnum为返回名柄<br> Res := WNetOpenEnum( RESOURCE_GLOBALNET, RESOURCETYPE_DISK,<br> RESOURCEUSAGE_CONTAINER, Nil,lphEnum);<br> if Res <> NO_ERROR then Exit;//Raise Exception(Res);//执行失败<br><br> //获取整个网络中的网络类型信息<br> Count := $FFFFFFFF;//不限资源数目<br> BufSize := 8192;//缓冲区大小设置为8K<br> GetMem(Buf, BufSize);//申请内存,用于获取工作组信息<br> Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);<br> if ( Res = ERROR_NO_MORE_ITEMS )//资源列举完毕<br> or (Res <> NO_ERROR )//执行失败<br> then Exit;<br><br> P := PNetResource(Buf);<br> for I := 0 to Count - 1 do//记录各个网络类型的信息<br> begin<br> NetworkTypeList.Add(p);<br> Inc(P);<br> end;<br><br> //WNetCloseEnum关闭一个列举句柄<br> Res := WNetCloseEnum(lphEnum);//关闭一次列举<br> if Res <> NO_ERROR then Exit;<br><br> for J := 0 to NetworkTypeList.Count-1 do //列出各个网络类型中的所有工作组名称<br> begin//列出一个网络类型中的所有工作组名称<br> NetResource := TNetResource(NetworkTypeList.Items[J]^);//网络类型信息<br> //获取某个网络类型的文件资源的句柄,NetResource为网络类型信息,lphEnum为返回名柄<br> Res := WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY,<br> RESOURCEUSAGE_CONTAINER, @NetResource,lphEnum);<br> if Res <> NO_ERROR then Break;//执行失败<br><br> while True do//列举一个网络类型的所有工作组的信息<br> begin<br> Count := $FFFFFFFF;//不限资源数目<br> BufSize := 8192;//缓冲区大小设置为8K<br> GetMem(Buf, BufSize);//申请内存,用于获取工作组信息<br> //获取一个网络类型的文件资源信息,<br> Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);<br> if ( Res = ERROR_NO_MORE_ITEMS ) //资源列举完毕<br> or (Res <> NO_ERROR) //执行失败<br> then Break;<br><br> Memo1.Lines.Clear;<br> P := PNetResource(Buf);<br> for I := 0 to Count - 1 do//列举各个工作组的信息<br> begin<br> assGroupNames.Add( StrPAS( P^.lpRemoteName ));//取得一个工作组的名称<br> Memo1.Lines.Add(P^.lpRemoteName);<br> Inc(P);<br> end;<br> end;<br> Res := WNetCloseEnum(lphEnum);//关闭一次列举<br> if Res <>NO_ERROR then Break;//执行失败<br> end;<br> Result := True;<br> FreeMem(Buf);<br> NetworkTypeList.Destroy;<br>end;<br><br>function TForm1.GetUserList(asGroupName: string;<br> assPCNames: TStrings): Boolean;<br>var<br> NetResource: TNetResource;<br> Buf: Pointer;<br> Count,BufSize,Res: DWord;<br> Ind: Integer;<br> lphEnum: THandle;<br> Temp: PNetResource;<br>begin<br> Result := False;<br> Buf := nil;<br> assPCNames.Clear;<br><br> Memo2.Lines.Add(' ');<br> Memo2.Lines.Add('============================================================');<br> Memo2.Lines.Add(asGroupName);<br> Memo2.Lines.Add('============================================================');<br> FillChar(NetResource, SizeOf(NetResource), 0);//初始化网络层次信息<br> NetResource.lpRemoteName := @asGroupName[1];//指定工作组名称<br>// NetResource.dwDisplayType := RESOURCEDISPLAYTYPE_SERVER;//类型为服务器(工作组)<br> NetResource.dwDisplayType := RESOURCEDISPLAYTYPE_DOMAIN;//类型为服务器(工作组)<br> NetResource.dwUsage := RESOURCEUSAGE_CONTAINER;<br> NetResource.dwType := RESOURCETYPE_DISK;//列举文件资源信息<br> NetResource.dwScope := RESOURCE_GLOBALNET;<br> //获取指定工作组的网络资源句柄<br> Res := WNetOpenEnum( RESOURCE_GLOBALNET, RESOURCETYPE_DISK,<br> RESOURCEUSAGE_CONTAINER, @NetResource,lphEnum);<br> if Res <> NO_ERROR then Exit; //执行失败<br><br> while True do//列举指定工作组的网络资源<br> begin<br> Count := $FFFFFFFF;//不限资源数目<br> BufSize := 8192;//缓冲区大小设置为8K<br> GetMem(Buf, BufSize);//申请内存,用于获取工作组信息<br> //获取计算机名称<br> Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);<br> if Res = ERROR_NO_MORE_ITEMS then break;//资源列举完毕<br> if (Res <> NO_ERROR) then Exit;//执行失败<br> Temp := PNetResource(Buf);<br> for Ind := 0 to Count - 1 do//列举工作组的计算机名称<br> begin<br> //获取工作组的计算机名称,+2表示删除"/",如//wangfajun=>wangfajun<br> assPCNames.Add(Temp^.lpRemoteName + 2);<br> Memo2.Lines.Add(Temp^.lpRemoteName);<br> if (Trim(Label3.Caption) = Temp^.lpRemoteName+2) then Label4.Caption := asGroupName;<br> Inc(Temp);<br> end;<br> end;<br> Res := WNetCloseEnum(lphEnum);//关闭一次列举<br> if Res <> NO_ERROR then Exit;//执行失败<br><br> Result := True;<br> FreeMem(Buf);<br>end;<br>
procedure TForm1.Button2Click(Sender: TObject);<br>var<br> i: Integer;<br> ssGroupList: TStrings;<br> ssaUserList: array of TStrings;<br>begin<br> FpssPCInfo.Clear;<br> ssGroupList := TStringList.Create;<br> try<br> GetGroupList(ssGroupList);<br> SetLength(ssaUserList, ssGroupList.Count);<br> for i := 0 to ssGroupList.Count - 1 do<br> begin<br> ssaUserList := TStringList.Create;<br> GetUserList(ssGroupList, ssaUserList);<br> FpssPCInfo.AddObject(ssGroupList, ssaUserList);<br> end;<br> finally<br> ssGroupList.Free;<br> end;<br>end;<br><br>function TForm1.GetGroupList(assGroupNames: TStrings): Boolean;<br>var<br> NetResource : TNetResource;<br> Buf : Pointer;<br> Count,BufSize,Res : DWORD;<br> lphEnum : THandle;<br> p NetResource;<br> i,j : SmallInt;<br> NetworkTypeList : TList;<br>begin<br> Result := False;<br> NetworkTypeList := TList.Create;<br> assGroupNames.Clear;<br><br> //获取整个网络中的文件资源的句柄,lphEnum为返回名柄<br> Res := WNetOpenEnum( RESOURCE_GLOBALNET, RESOURCETYPE_DISK,<br> RESOURCEUSAGE_CONTAINER, Nil,lphEnum);<br> if Res <> NO_ERROR then Exit;//Raise Exception(Res);//执行失败<br><br> //获取整个网络中的网络类型信息<br> Count := $FFFFFFFF;//不限资源数目<br> BufSize := 8192;//缓冲区大小设置为8K<br> GetMem(Buf, BufSize);//申请内存,用于获取工作组信息<br> Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);<br> if ( Res = ERROR_NO_MORE_ITEMS )//资源列举完毕<br> or (Res <> NO_ERROR )//执行失败<br> then Exit;<br><br> P := PNetResource(Buf);<br> for I := 0 to Count - 1 do//记录各个网络类型的信息<br> begin<br> NetworkTypeList.Add(p);<br> Inc(P);<br> end;<br><br> //WNetCloseEnum关闭一个列举句柄<br> Res := WNetCloseEnum(lphEnum);//关闭一次列举<br> if Res <> NO_ERROR then Exit;<br><br> for J := 0 to NetworkTypeList.Count-1 do //列出各个网络类型中的所有工作组名称<br> begin//列出一个网络类型中的所有工作组名称<br> NetResource := TNetResource(NetworkTypeList.Items[J]^);//网络类型信息<br> //获取某个网络类型的文件资源的句柄,NetResource为网络类型信息,lphEnum为返回名柄<br> Res := WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY,<br> RESOURCEUSAGE_CONTAINER, @NetResource,lphEnum);<br> if Res <> NO_ERROR then Break;//执行失败<br><br> while True do//列举一个网络类型的所有工作组的信息<br> begin<br> Count := $FFFFFFFF;//不限资源数目<br> BufSize := 8192;//缓冲区大小设置为8K<br> GetMem(Buf, BufSize);//申请内存,用于获取工作组信息<br> //获取一个网络类型的文件资源信息,<br> Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);<br> if ( Res = ERROR_NO_MORE_ITEMS ) //资源列举完毕<br> or (Res <> NO_ERROR) //执行失败<br> then Break;<br><br> Memo1.Lines.Clear;<br> P := PNetResource(Buf);<br> for I := 0 to Count - 1 do//列举各个工作组的信息<br> begin<br> assGroupNames.Add( StrPAS( P^.lpRemoteName ));//取得一个工作组的名称<br> Memo1.Lines.Add(P^.lpRemoteName);<br> Inc(P);<br> end;<br> end;<br> Res := WNetCloseEnum(lphEnum);//关闭一次列举<br> if Res <>NO_ERROR then Break;//执行失败<br> end;<br> Result := True;<br> FreeMem(Buf);<br> NetworkTypeList.Destroy;<br>end;<br><br>function TForm1.GetUserList(asGroupName: string;<br> assPCNames: TStrings): Boolean;<br>var<br> NetResource: TNetResource;<br> Buf: Pointer;<br> Count,BufSize,Res: DWord;<br> Ind: Integer;<br> lphEnum: THandle;<br> Temp: PNetResource;<br>begin<br> Result := False;<br> Buf := nil;<br> assPCNames.Clear;<br><br> Memo2.Lines.Add(' ');<br> Memo2.Lines.Add('============================================================');<br> Memo2.Lines.Add(asGroupName);<br> Memo2.Lines.Add('============================================================');<br> FillChar(NetResource, SizeOf(NetResource), 0);//初始化网络层次信息<br> NetResource.lpRemoteName := @asGroupName[1];//指定工作组名称<br>// NetResource.dwDisplayType := RESOURCEDISPLAYTYPE_SERVER;//类型为服务器(工作组)<br> NetResource.dwDisplayType := RESOURCEDISPLAYTYPE_DOMAIN;//类型为服务器(工作组)<br> NetResource.dwUsage := RESOURCEUSAGE_CONTAINER;<br> NetResource.dwType := RESOURCETYPE_DISK;//列举文件资源信息<br> NetResource.dwScope := RESOURCE_GLOBALNET;<br> //获取指定工作组的网络资源句柄<br> Res := WNetOpenEnum( RESOURCE_GLOBALNET, RESOURCETYPE_DISK,<br> RESOURCEUSAGE_CONTAINER, @NetResource,lphEnum);<br> if Res <> NO_ERROR then Exit; //执行失败<br><br> while True do//列举指定工作组的网络资源<br> begin<br> Count := $FFFFFFFF;//不限资源数目<br> BufSize := 8192;//缓冲区大小设置为8K<br> GetMem(Buf, BufSize);//申请内存,用于获取工作组信息<br> //获取计算机名称<br> Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);<br> if Res = ERROR_NO_MORE_ITEMS then break;//资源列举完毕<br> if (Res <> NO_ERROR) then Exit;//执行失败<br> Temp := PNetResource(Buf);<br> for Ind := 0 to Count - 1 do//列举工作组的计算机名称<br> begin<br> //获取工作组的计算机名称,+2表示删除"/",如//wangfajun=>wangfajun<br> assPCNames.Add(Temp^.lpRemoteName + 2);<br> Memo2.Lines.Add(Temp^.lpRemoteName);<br> if (Trim(Label3.Caption) = Temp^.lpRemoteName+2) then Label4.Caption := asGroupName;<br> Inc(Temp);<br> end;<br> end;<br> Res := WNetCloseEnum(lphEnum);//关闭一次列举<br> if Res <> NO_ERROR then Exit;//执行失败<br><br> Result := True;<br> FreeMem(Buf);<br>end;<br>