在Win98下怎样取得登录后的域名(Domain Name)???!!!(100分)

  • 主题发起人 主题发起人 tonycn
  • 开始时间 开始时间
T

tonycn

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