|
See here.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
1) See WNetOpenEnum , WNetEnumResource and WNetCloseEnum .
|
|
|
|
|
but function WNetOpenEnum() returns all computer in network. But I need
1) list of all workgroups
2) list of computer from specified workgroup
So I can't get it using WNetOpenEnum()
------------------------------------------
gouranga
JID badzio(at)chrome(dot)pl
------------------------------------------
|
|
|
|
|
badzio wrote:
but function WNetOpenEnum() returns all computer in network
Look at the dwUsage parameter passed into WNetOpenEnum - you need RESOURCEUSAGE_CONTAINER . We have an app here that uses this API, and it enumerates domains (classic NT and AD, workgroups and individual computers. You have to give it appropriate parameters depending on what you want to enumerate.
|
|
|
|
|
hmmm... first, I try enumerate domain (NT/AD/workgroups)
<br />
DWORD dwScope = RESOURCE_CONTEXT;<br />
DWORD dwUsage = RESOURCEUSAGE_CONTAINER;<br />
DWORD dwType = RESOURCETYPE_ANY;<br />
NETRESOURCE *NetResource = NULL;<br />
HANDLE hEnum;<br />
WNetOpenEnum( dwScope, dwType, dwUsage, NetResource, &hEnum );<br />
DWORD Count = 0xFFFFFFFF;<br />
DWORD BufferSize = 2048;<br />
LPVOID Buffer = new char[2048];<br />
WNetEnumResource( hEnum, &Count, Buffer, &BufferSize );<br />
NetResource = (NETRESOURCE*)Buffer;<br />
for ( unsigned int i = 0; i < BufferSize/sizeof(NETRESOURCE); i++, NetResource++ )<br />
{<br />
}<br />
but still I got all resources from network. I'd like to get list of domains - can you show me some code's example?
------------------------------------------
gouranga
JID badzio(at)chrome(dot)pl
------------------------------------------
|
|
|
|
|
You'll need to test the dwDisplayType and dwUsage fields of the NETRESOURCE structure for each item you get back.
|
|
|
|
|
ok, i checked... it seems to work... but... some problem
My LAN:
Microsoft Windows Network: Domain1 (domain Windows2k Server), Domain2 (workgroup), Domain3 (domain Windows2k Server), Domain4 (workgroup)
NetWare Services: Serwery NetWare, System NDS
<br />
DWORD dwScope = RESOURCE_CONTEXT;<br />
DWORD dwUsage = RESOURCEUSAGE_CONTAINER;<br />
DWORD dwType = RESOURCETYPE_ANY;<br />
NETRESOURCE *NetResource = NULL, *ResDomain=NULL;<br />
HANDLE hEnum;<br />
dwScope = RESOURCE_GLOBALNET;<br />
WNetOpenEnum( dwScope, dwType, dwUsage, NetResource, &hEnum );<br />
if ( hEnum )<br />
{<br />
DWORD Count = 0xFFFFFFFF;<br />
DWORD BufferSize = 2048;<br />
LPVOID Buffer = new char[2048];<br />
LPVOID BuffDomain = new char[2048];<br />
WNetEnumResource( hEnum, &Count, Buffer, &BufferSize );<br />
NetResource = (NETRESOURCE*)Buffer;<br />
for ( unsigned int i = 0; i < BufferSize/sizeof(NETRESOURCE); i++, NetResource++ )<br />
{<br />
if (NetResource->dwDisplayType==RESOURCEDISPLAYTYPE_NETWORK ) <br />
{<br />
WNetOpenEnum(dwScope,dwType,dwUsage,NetResource,&hEnum);<br />
WNetEnumResource(hEnum,&Count,BuffDomain,&BufferSize);<br />
ResDomain=(NETRESOURCE*)BuffDomain;<br />
for (unsigned int k=0; k<BufferSize/sizeof(NETRESOURCE); k++, ResDomain++)<br />
{<br />
if (ResDomain->dwDisplayType==RESOURCEDISPLAYTYPE_DOMAIN)<br />
{<br />
}<br />
}<br />
}<br />
}<br />
this code finds me not all workgroups/domain
It finds two domains of NetWare Services
But domains/groups from Microsoft Windows Network - finds only Domain1 and Domain2
I tried debug - app found some network with dwDisplayType=3452816845. And some of them have missing groups (Domain3 and Domain4). So - I made code (remark /* || NetResource->dwDisplayType>RESOURCEDISPLAYTYPE_NDSCONTAINER*/) - now apps finds all workgroups but - groups which were missing (Domain3 and Domain4) are multiple - I mean that apps finds it more that one time
What do I do wrong?
------------------------------------------
gouranga
JID badzio(at)chrome(dot)pl
------------------------------------------
|
|
|
|
|
You aren't testing the return code of WNetEnumResource. If that returns ERROR_MORE_DATA, you need to call it again, and go through the next set of resources. You then keep calling WNetEnumResources until it doesn't return ERROR_MORE_DATA.
|
|
|
|
|
ok, enumerating of workgroups/domain is ok
but next problem - I want get list of computers from specified workgroup/domain
so... I enumerate workgroups... if I found workgroup with correct name, then I remember NETRESOURCE value.
Next I use WNetOpenEnum with NETRSOURCE value which I remembered. And then, WNetEnumResource and testing dwDisplayType etc...
but i get only two computers (I expected about 19 computers from this workgroup). WNetEnumResource return value 0 (so - NO_ERROR). parameter lpcCount also returns 2. So - what's wrong?
------------------------------------------
gouranga
JID badzio(at)chrome(dot)pl
------------------------------------------
|
|
|
|
|
badzio wrote:
So - what's wrong?
Impossible to say - you'll need to post the relevant source code.
|
|
|
|
|
<br />
int error;<br />
DWORD dwScope = RESOURCE_CONTEXT;<br />
DWORD dwUsage = RESOURCEUSAGE_CONTAINER;<br />
DWORD dwType = RESOURCETYPE_ANY;<br />
DWORD dwStatus;<br />
NETRESOURCE *NetResource = NULL, *NetRes = NULL,*ResDomain=NULL, *ResServer=NULL, *ResTree=NULL;<br />
NETRESOURCE *WorkgroupResource = NULL, *ResComputers = NULL;<br />
HANDLE hEnum, hWorkgroup = NULL;<br />
dwScope = RESOURCE_GLOBALNET;<br />
error = -3;<br />
WNetOpenEnum( dwScope, dwType, dwUsage, NetResource, &hEnum );<br />
CString ls_workgroups = "";<br />
DWORD Count = 0xFFFFFFFF;<br />
DWORD BufferSize = 2048;<br />
LPVOID Buffer = new char[2048];<br />
LPVOID BufferRes = new char[2048], BuffDomain = new char[2048], BuffNet = new char[2048], BuffComputers = new char[2048];<br />
CString workgroup;<br />
m_edit.GetWindowText(workgroup);<br />
bool lb_exists = false;<br />
if ( hEnum )<br />
{<br />
WNetEnumResource( hEnum, &Count, Buffer, &BufferSize );<br />
NetResource = (NETRESOURCE*)Buffer;<br />
for ( unsigned int i = 0; i < BufferSize/sizeof(NETRESOURCE); i++, NetResource++ )<br />
{<br />
if (NetResource->dwDisplayType==RESOURCEDISPLAYTYPE_NETWORK || NetResource->dwDisplayType>RESOURCEDISPLAYTYPE_NDSCONTAINER)<br />
{<br />
bool lb_test = false;;<br />
if (NetResource->dwType>RESOURCETYPE_RESERVED)<br />
lb_test = true;<br />
else<br />
if (!strcmp(NetResource->lpProvider,"Microsoft Windows Network"))<br />
lb_test = true;<br />
if (!lb_test)<br />
continue;<br />
WNetOpenEnum(dwScope,dwType,dwUsage,NetResource,&hEnum);<br />
if (!hEnum)<br />
continue;<br />
dwStatus = WNetEnumResource(hEnum,&Count,BuffDomain,&BufferSize);<br />
if (dwStatus==ERROR_NO_MORE_ITEMS)<br />
break;<br />
ResDomain=(NETRESOURCE*)BuffDomain;<br />
for (unsigned int k=0; k<BufferSize/sizeof(NETRESOURCE); k++, ResDomain++)<br />
{<br />
if ((ResDomain->dwDisplayType==RESOURCEDISPLAYTYPE_DOMAIN || ResDomain->dwDisplayType==RESOURCEDISPLAYTYPE_GROUP) &&<br />
(strcmp(ResDomain->lpProvider,"Microsoft Windows Network") || strcmp(ResDomain->lpProvider,"")))<br />
{<br />
if (!strcmp(ResDomain->lpRemoteName,workgroup))<br />
{<br />
hWorkgroup=hEnum;<br />
lb_exists = true;<br />
WorkgroupResource = ResDomain;<br />
break;<br />
}<br />
ls_workgroups += ResDomain->lpRemoteName;<br />
ls_workgroups += ";";<br />
}<br />
}<br />
if (lb_exists)<br />
break;<br />
}<br />
}<br />
}<br />
else<br />
return;<br />
WNetCloseEnum(hEnum);<br />
if (hWorkgroup==NULL)<br />
{<br />
error = -4;<br />
return;<br />
}<br />
dwUsage=RESOURCEUSAGE_ALL;<br />
dwStatus = WNetOpenEnum(dwScope,dwType,dwUsage,WorkgroupResource,&hWorkgroup);<br />
dwStatus = WNetEnumResource(hWorkgroup,&Count,BuffComputers,&BufferSize);<br />
if (dwStatus!=NO_ERROR)<br />
{<br />
error = -4;<br />
return;<br />
}<br />
ResComputers = (NETRESOURCE*)BuffComputers;<br />
CString ls_computers = "";<br />
for (unsigned int l=0; l<BufferSize/sizeof(NETRESOURCE); l++, ResComputers++)<br />
{<br />
if (ResComputers->dwDisplayType==RESOURCEDISPLAYTYPE_SERVER)<br />
{<br />
ls_computers+=ResComputers->lpRemoteName;<br />
ls_computers+=";";<br />
}<br />
}<br />
------------------------------------------
gouranga
JID badzio(at)chrome(dot)pl
------------------------------------------
|
|
|
|
|
badzio wrote:
Application must run on Windows 2k/xp, I use VisualC++ 6.0
You application will run only on win2000 and above as Api use for this purposes are not supported for WIN ME/98/95.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
ok - it's good that it run on win2k and above. but - how can I do it?
------------------------------------------
gouranga
JID badzio(at)chrome(dot)pl
------------------------------------------
|
|
|
|
|
We have legacy VC6 C++ application.
We need to link with a new DLL written in VC7 C++ (.NET) .
In our legacy application we are using alot of streams
(#include <iostream.h>).
DLL that we need to link with uses a namespace std and <iostream>.
How we can link one with the other?
Thanks in advance.
Julia
|
|
|
|
|
Hi,
I need to get all the printers that are installed in the computer (both local and network). I am using EnumPrinters with level 2. But this is giving only local printer details! Could anyone please help me.
Thanks,
Chetan
|
|
|
|
|
How about a code snippet for us to look at?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I got it the problem was with the flag
DWORD Level = 2;
PRINTER_INFO_2 *printerInfo = 0;<br />
<br />
DWORD numElems = 100;<br />
DWORD sizeBuff = 0;<br />
<br />
DWORD Flags = PRINTER_ENUM_CONNECTIONS | PRINTER_ENUM_LOCAL;
LPTSTR Name = NULL;<br />
<br />
DWORD sizeNeeded;
DWORD numReturned;
<br />
printerInfo = new PRINTER_INFO_2[numElems];<br />
sizeBuff = numElems * sizeof(PRINTER_INFO_2);<br />
<br />
BOOL qry = EnumPrinters(<br />
Flags,
Name,
Level,
(unsigned char*)printerInfo,
sizeBuff,
&sizeNeeded,
&numReturned
);
|
|
|
|
|
If you want to use PRINTER_ENUM_NETWORK , you'll need to set Level equal to 1.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Right, that was the mistake.
|
|
|
|
|
Dear friends,
Please tell me what data structure is suitable in my situation.
I am getting list of directories from FTP server. I need to keep information about each directory in that data structure in such a manner that later i can iterate through that data structure and know that who is child and who is parent.
Please tell me what data structure should i use. Or do i need to make my own ?
Imtiaz
|
|
|
|
|
A tree?
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|
|
Depending on how you are going to access the items, an array or list will both suffice. The former allows access to any item, while the latter requires you to iterate items from the beginning.
The item stored in either could look something like:
struct _FolderInfo
{
CString strFolder;
CString strParent;
};
CArray<_FolderInfo, _FolderInfo&> arrFolderInfo;
CList<_FolderInfo, _FolderInfo&> listFolderInfo; Having shown all that, a question that comes to mind is why store the name of the parent folder? If the absolute name of the folder is being stored, then the parent is known by simply removing the rightmost folder. Yes?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Actually my situation is just like that of windows registry, each node has children and each children can have more children. Any idea what data structure maintained by registry ??
Imtiaz
|
|
|
|
|
Imtiaz Murtaza wrote:
Any idea what data structure maintained by registry ??
See here.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I use both Visual Studio 6 and 7. I want to detect and use dual monitors. For this I use GetSystemMetrics(SM_CXVIRTUALSCREEN), which works fine under vs7. Under vs6 SM_CXVIRTUALSCREEN is unknown and it returns zero (after putting in the integer value of the constant).
Apparently one way to solve the problem is with the SDK. I would like to know if there is a lighter weight option? Also if I give the software to a friend, does he too need the SDK?
My gut feeling is there must be an easier solution.
Any suggestions?
Thanks,
Ilan
|
|
|
|
|