Solved

HOW CAN I GET THE USERNAME AND IP

Posted on 2001-09-04
4
171 Views
Last Modified: 2010-04-06
HI,
HOW CAN I GET THE IP ADDREASS'S AND USER NAMES OF ALL WORKING MACHINEDS IN MY DOMAIN,
THIS PROGGRAME WILL INSTALL AT MY BOSS MACHINE HE IS NOT ADMINISTARTOR ON THE DOMAIN.
THANKS
AHMED RAGAB
0
Comment
Question by:RAGAB2000
4 Comments
 
LVL 3

Expert Comment

by:VSF
Comment Utility
Interesting!
0
 
LVL 14

Accepted Solution

by:
DragonSlayer earned 50 total points
Comment Utility
Here's a unit that might be helpful:

unit Unit2;

interface

uses
 classes,sysutils,windows,Forms,Dialogs,FileCtrl;

type
 TenEnumKind  = (ekNetwork,ekDomain,ekServer,ekShare);
const
 kasEnumKind  : array[TenEnumKind] of string[20] =
                         (
                           'Network',
                           'Domain',
                           'Server',
                           'Share'
                           );

procedure EnumNetRes(aScope,aType,aUsage : integer; prNetRes :
PNetResource; sl : TStringList; ek : TenEnumKind);
procedure GetDomainList(const sNetwork : string; sl : TStringList);
procedure GetNetworkList(sl : TStringList);
procedure GetExtendedError(iWinErr : integer);
procedure GetServerList(const sDomain,sNetwork : string; sl :
TStringList);

function GetItAll(Target:String):String;

implementation

function GetItAll(Target:String):String;
  function TakeOutSemiAndAddSlash(InVal:String):String;
  var F:Integer;
  begin
       Result:='';
       For F:= 1 to Length(InVal) do
           begin
               if InVal[F]<>':' then
                  Result:=Result+(InVal[F]);
           end;
       Result:='\'+Result;
  end;
Var
 AllNetwork,
 AllDomains,
 AllServers:TStringList;
 I,J,K:Integer;
 NetworkName,DomainName,Servername:String;
begin
 Result:='';
 AllNetwork:=TStringList.Create;
 GetNetworkList(AllNetwork);
 For I:=0 to AllNetwork.Count-1 do
     begin
          NetworkName:=(AllNetwork[i]);
          {ShowMessage('Looking into the ['+NetworkName+'] Network'); }
          AllDomains:=TStringList.Create;
          Application.Processmessages;
          GetDomainList(NetworkName,AllDomains);
          For J:=0 to AllDomains.Count-1 do
              begin
                   DomainName:=(AllDomains[i]);
                   {ShowMessage('Looking at the '+DomainName+' domain');
}
                   AllServers:=TStringList.Create;
                   GetServerList(DomainName,NetworkName,AllServers);
                   For K:=0 to AllServers.Count-1 do
                       begin
                            Servername:=(AllServers[k]);
                            {ShowMessage('Looking at the '+Servername+'
server');}
                            if DirectoryExists
                               (
                               Servername+TakeOutSemiAndAddSlash
                               (
                               ExtractFilePath(Application.ExeName)
                               )
                               ) then
                                 begin
                                      Result:=Servername+Target;
                                      {ShowMessage('Found: '+Result); }
                                      AllServers.Free;
                                      AllDomains.Free;
                                      AllNetwork.Free;
                                      Exit;
                                 end;
                       end;
                   AllServers.Free;
              end;
          AllDomains.Free;
     end;
 AllNetwork.Free;
end;

procedure GetNetworkList(sl : TStringList);
begin
 if sl = nil then exit;
 sl.BeginUpdate;
 try
   sl.Clear;

EnumNetRes(RESOURCE_GLOBALNET,RESOURCETYPE_ANY,RESOURCEUSAGE_CONTAINER,nil,sl,ekNetwork);   finally
   sl.EndUpdate;
 end;
end;


procedure GetDomainList(const sNetwork : string; sl : TStringList);
var
 rNetRes          : PNetResource;
begin
 if sl = nil then exit;
 sl.BeginUpdate;
   sl.Clear;
   New(rNetRes);
   { Start here }
   with rNetRes^ do begin
     dwScope := RESOURCE_GLOBALNET;
     dwType := RESOURCETYPE_ANY ;
     dwDisplayType := RESOURCEDISPLAYTYPE_GENERIC;
     dwUsage := RESOURCEUSAGE_CONNECTABLE;
     lpLocalName := nil;
     lpRemoteName := 0;
     lpComment := nil;
     lpProvider := pChar(sNetwork);
   end;

EnumNetRes(RESOURCE_GLOBALNET,RESOURCETYPE_ANY,RESOURCEDISPLAYTYPE_GENERIC,rNetRes,sl,ekDomain);
   sl.EndUpdate;
   Dispose(rNetRes);
end;



procedure GetServerList(const sDomain,sNetwork : string; sl :
TStringList);
var
 rNetRes          : PNetResource;
begin
 if sl = nil then exit;
 sl.BeginUpdate;
   sl.Clear;
   New(rNetRes);
   with rNetRes^ do begin
     dwScope := RESOURCE_GLOBALNET;
     dwType := RESOURCETYPE_ANY;
     dwDisplayType := RESOURCEDISPLAYTYPE_SERVER;
     dwUsage := RESOURCEUSAGE_CONNECTABLE;
     lpLocalName := nil;
     lpRemoteName := pChar(sDomain);
     lpComment := nil;
     lpProvider := pChar(sNetwork);
   end;


EnumNetRes(RESOURCE_GLOBALNET,RESOURCETYPE_ANY,RESOURCEDISPLAYTYPE_SERVER,rNetRes,sl,ekServer);
   Dispose(rNetRes);
   sl.EndUpdate;
end;



procedure EnumNetRes(aScope,aType,aUsage : integer; prNetRes :
PNetResource; sl : TStringList; ek : TenEnumKind);
const
 kiNetResCount = 1024;
type
 TarNetRes  = array[0..pred(kiNetResCount)] of TNetResource;

 procedure FillEntries(arNetRes : TarNetRes; iCount : integer);   var
   i      : integer;
   Thething:String;
 begin
   for i := 0 to pred(iCount) do begin
     TheThing:=arNetRes[i].lpRemoteName;
     if sl<>Nil then
        begin
             Try
             sl.Add(TheThing);
             Except
             End;
        end;
   end;  // for  i
 end;
 procedure DoEnum(hEnum : THandle);
 var
   iWinErr           :  integer;
   arNetRes          :  TarNetRes;
   iCount            :  DWORD;
   dwBufSize         :  DWord;
 begin
   iCount := 20;
   fillchar(arNetRes,sizeof(arNetRes),0);
   dwBufSize := SizeOf(arNetRes);
   iWinErr := WNetEnumResource( hEnum,
                               iCount,
                               @arNetRes[0],
                               dwBufSize);
   case iWinErr of
     No_Error                  : FillEntries(arNetRes,iCount);
     ERROR_NO_MORE_ITEMS,
     ERROR_INVALID_PARAMETER  : ;
     ERROR_ACCESS_DENIED      : sl.Add('Access denied');
     else GetExtendedError(iWinErr);
   end; // case
 end;

var
 iWinErr          : Integer;
 hEnum            : THandle;
begin
 iWinErr := WNetOpenEnum(aScope,aType,aUsage,prNetRes,hEnum);
 try
   case iWinErr of
     NO_ERROR                  : DoEnum(hEnum);
     ERROR_NO_MORE_ITEMS,
     ERROR_INVALID_PARAMETER  : ;
     ERROR_ACCESS_DENIED      : sl.Add('Access denied');
   end;  // case
   if iWinErr=ERROR_EXTENDED_ERROR then GetExtendedError(iWinErr);
 finally
   WNetCloseEnum(hEnum);
 end;
end;

procedure GetExtendedError(iWinErr : integer);
const
 kiDesc      = 255;
 kiProvider  = 255;
var
 iNetErr      : DWORD;
 zDesc        : array[0..255] of char;
 zProvider    : array[0..255] of char;
 sDesc        : String;
 sProvider    : string;
begin
 setLength(sDesc,kiDesc);
 SetLength(sProvider,kiProvider);
 WNetGetLastError(iNetErr,zDesc,kiDesc,zProvider,kiProvider);
 sDesc := StrPas(zDesc);
 sProvider := StrPas(zProvider);
 Showmessage(sDesc);
end;

end.
0
 

Expert Comment

by:eddie_kho
Comment Utility
you should use ServerSocket-ClientSocket.... or try find some windows API function..
0
 
LVL 17

Expert Comment

by:geobul
Comment Utility
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

accept DragonSlayer's comment as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Thanks,

geobul
EE Cleanup Volunteer
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Save pdf file to other location 3 72
code issue 8 84
Delphi: how to implement a User Shortcut mapper? 1 81
Delphi inherited method 6 36
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now