| View previous topic :: View next topic |
| Author |
Message |
henrywood Contributor

Joined: 21 Sep 2004 Posts: 66 Location: Copenhagen, Denmark
|
Posted: Sat Mar 26, 2005 1:49 am Post subject: Listing all PCs in a Domain |
|
|
Hi guys !
I would like to get a list of IPs or Host names of all PCs in a domain. I found this API Call which I think can do the task (VB):
#Private Declare Function DsListServersForDomainInSite Lib "ntdsapi.dll" (ByVal hDS As Long, ByVal Domain As String, ByVal site As String, ByRef ppServers As PDS_NAME_RESULTA) As Long
How could this be converted into VDS code:
LOADLIB ntdsapi.dll
%A = @LIB("ntdsapi.dll", DsListServersForDomainInSite, <ret_val type>, args… )
FREELIB ntdsapi.dll
Henrik |
|
| Back to top |
|
 |
PGWARE Web Host

Joined: 29 Dec 2001 Posts: 1565
|
|
| Back to top |
|
 |
henrywood Contributor

Joined: 21 Sep 2004 Posts: 66 Location: Copenhagen, Denmark
|
Posted: Sat Mar 26, 2005 5:07 pm Post subject: Thanks PG ! |
|
|
Thanks for the info.
However I am not wether servers will include all PCs on a Microsoft Network. I appears that servers are only Windows 2000 and Windows 2003 or ?
Basically I am trying to do what this C function does
It should return a string of the form COMPUTERNAME1|COMPUTERNAME2|...
I found the function on the net somewhere and modified it somewhat but since I am that fluent in C anymore, I guess it will not compile - However I think you'd get the picture anyway.
Here goes:
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
// Find the servers in a domain
char* ScanDomain( char* userdomain )
{
char *returnstring;
char domname[200];
if (userdomain != NULL)
{
strncpy(domname, userdomain, 200);
TCHAR szDomain[32];
//GetWindowText(wndDomain, domname, sizeof(szDomain));
NETRESOURCE netres;
netres.dwScope = RESOURCE_GLOBALNET;
netres.dwDisplayType = RESOURCEDISPLAYTYPE_DOMAIN;
netres.dwUsage = RESOURCEUSAGE_CONTAINER;
netres.lpRemoteName = domname;
netres.lpProvider = NULL;
HANDLE henum;
DWORD res =
WNetOpenEnum(
RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
RESOURCEUSAGE_CONTAINER,
&netres,
&henum);
if (res == NO_ERROR) {
printf("Yay!\n");
} else {
return;
}
unsigned char bigbuf[16 * 1024];
DWORD things;
do {
things = 1;
DWORD bufsize = sizeof(bigbuf);
DWORD res = WNetEnumResource(
henum,
&things,
(LPVOID) bigbuf,
&bufsize);
if (res != NO_ERROR) {
break;
}
printf("Found a thing!\n");
NETRESOURCE *found = (NETRESOURCE *) bigbuf;
printf("Item:%s\n", found->lpRemoteName);
// Now take off the double backslash on the beginnig.
char buf [200];
strncpy(buf, & (found->lpRemoteName[2]), sizeof(buf));
// Add to window
//SendMessage(targetwnd, LB_ADDSTRING,0, (LPARAM) buf);
// Add to return string
returnstring+= buf + "|";
} while (things>0);
WNetCloseEnum(henum);
return returnstring;
} else {
return NULL;
}
}
Maybe some more knowledgable in C would like to take a look also ?
Henrik |
|
| Back to top |
|
 |
henrywood Contributor

Joined: 21 Sep 2004 Posts: 66 Location: Copenhagen, Denmark
|
Posted: Sat Mar 26, 2005 5:13 pm Post subject: Re: Thanks PG ! |
|
|
| henrywood wrote: |
I found the function on the net somewhere and modified it somewhat but since I am that fluent in C anymore, I guess it will not compile - However I think you'd get the picture anyway.
|
Of course what I meant was that I am NOT that fluent in C ....
Henrik[/b] |
|
| Back to top |
|
 |
ShinobiSoft Professional Member


Joined: 06 Nov 2002 Posts: 790 Location: Knoxville, Tn
|
Posted: Sat Mar 26, 2005 5:45 pm Post subject: |
|
|
Hi henrywood,
You do realize that the C code you posted prints to STDOUT, meaing that it
needs to be run ina dos box.
Let me tinker with this. _________________ Bill Weckel
ShinobiSoft Software
"The way is known to all, but not all know it." |
|
| Back to top |
|
 |
henrywood Contributor

Joined: 21 Sep 2004 Posts: 66 Location: Copenhagen, Denmark
|
Posted: Sat Mar 26, 2005 6:05 pm Post subject: Re: Listing all PCs |
|
|
Hi guys!
Yes I am aware - I guess I forgot to remove that line
Bill, just tinker away
Are you gonna wrap it into a DLL (would be very nice!)
A note though: Since I do not currently have a LAN setup at home I would not be able to test it before getting back to work on Tuesday.
Maybe somebody else are willing to test if it actually works
I would like to use it in conjunction with VDSREG to write to the registry of all PCs in the network
Henrik |
|
| Back to top |
|
 |
Aslan Valued Contributor


Joined: 31 May 2001 Posts: 589 Location: Memphis, TN USA
|
Posted: Mon Apr 04, 2005 1:38 am Post subject: |
|
|
See if this helps you.
| Code: | DIALOG CREATE,PClist,-1,0,497,353
DIALOG ADD,LIST,LIST1,22,20,458,316
DIALOG SHOW
runh cmd /c net view /domain:<DomainName>,pipe
List assign,List1,@pipe()
:evloop
wait event
goto @event()
:close
exit |
|
|
| Back to top |
|
 |
henrywood Contributor

Joined: 21 Sep 2004 Posts: 66 Location: Copenhagen, Denmark
|
Posted: Mon Apr 04, 2005 4:43 pm Post subject: Thanks ! |
|
|
Hi Aslan !
Thank you for the tip !
I would prefer a DLL and I think Bill is working on a DLL ? I always try to avoid running hidden system programs using RUNH as they fail on some systems.
However, I have tested the net view suggested by you and that works OK.
Henrik |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|