|
You'll need to test the dwDisplayType and dwUsage fields of the NETRESOURCE structure for each item you get back.
|
|
|
|
|
![Go to Parent](https://www.codeproject.com/App_Themes/CodeProject/Img/arrow-up24.png) 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.
|
|
|
|
|
![Go to Parent](https://www.codeproject.com/App_Themes/CodeProject/Img/arrow-up24.png)
<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. ![Frown | :(](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_frown.gif)
|
|
|
|
|
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
|
|
|
|
|
If you want to detect multiple monitors acting in/as a virtual screen, you might want to use SM_CMONITORS . Note that that value, as well as the SM_C?VIRTUALSCREEN values are dependent on the OS your application is running on; they will return an incorrect value (0 ) on Windows 95 and Windows NT.
The updated SDK only gives you the files required to compile and link your code that uses the updated/new identifiers, it does not guarantee that the resulting application will work on any OS.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Thanks Jim,
I am using SM_MONITORS and that doesn't work either.
The OS is XP so that is no problem but it returns zero.
Can you explain this??
Ilan
|
|
|
|
|
Nope, I cannot explain that. You do not have any of the Application Compatability settings turned on for your app, do you?
Look into EnumDisplayMonitors and see if that works for you.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Jim shalom,
Thanks for your trouble to answer my question. This morning I finally solved the mystery. I've got 2 different machines, one with 2 monitors and vs7 and the second with 1 monitor and vs6. (Change 2 variables at the same time and you've got problems.) The documentation about the SDK managed to confuse me as well.
Yesterday I went and looked with the debugger in assembly mode at the 2 monitor system. I saw it went into user32.dll with the integer value. Clearly user32.dll depends only on the operating system and has no connection to vs6 or vs7 (or any SDK for that matter).
Thus I manually defined SM_C?VIRTUALSCREEN and SM_MONITORS for vs6 only. Now I call SM_C?VIRTUALSCREEN if and only if SM_MONITORS returns > 1. I initially expected SM_C?VIRTUALSCREEN to return the same value as SM_C?SCREEN (the bounding rectangle of 1 screen), but this is a mistake and it returns zero for 1 monitor. Thus I have to complicate my code a bit and use:
if( GetSystemMetrics( SM_CMONITORS) > 1) {
m_screen.x = GetSystemMetrics( SM_CXVIRTUALSCREEN);
m_screen.y = GetSystemMetrics( SM_CYVIRTUALSCREEN);
}
else {
m_screen.x = GetSystemMetrics( SM_CXSCREEN);
m_screen.y = GetSystemMetrics( SM_CYSCREEN);
}
The bottom line is that it works and I don't need the SDK. It is still operating system dependent, but if I want 2 monitors, that is the price.
Thanks again for your help.
Shalom,
Ilan
|
|
|
|
|
Try the following codes:
CRect rectFrame, rectView, rectChild, rcScreen;
MONITORINFO mi;
mi.cbSize = sizeof (MONITORINFO);
if (GetMonitorInfo (MonitorFromPoint (CPoint(0,0), MONITOR_DEFAULTTONEAREST),
&mi))
{
rcScreen = mi.rcMonitor;
}
else
{
::SystemParametersInfo (SPI_GETWORKAREA, 0, &rcScreen, 0);
}
......
Jack
---------------------------------------------------------------------------------
XD++ MFC/C++ Flow/Diagram Library -- http://www.ucancode.net
|
|
|
|
|