0

I am running three computers in my home network, all within the same workgroup. Now I want to find out on my computer which volumes are present/mounted on the other computers im my network, and I want to do it in my C++/C# code.

Method NetServerEnum works fine and delivers the computer names in my network but now I am stuck and cannot identify a function which lists the volumes of such named 'remote' computer. I have already tried function NetServerDiskEnum but receive ERROR_ACCESS_DENIED. Is there another function that does the trick? (Any File dialog can do it but I need to include that into my code - and without an operator intervention.

Does anybody have a hint for me?

Update (2021-04-08) Thanks to Alan, he gave me a lot to try out. I decided to proceed with using WNetEnumResource which does not require any elevated privileges. Here is my code:

#include <windows.h>

int main ( int nArgc, char** lppszArgv )
{
    DWORD ErrCode;
    HANDLE hEnum;
    DWORD dwCount;
    DWORD BfSize = 0x1000;

    ErrCode = WNetOpenEnum ( RESOURCE_CONTEXT, RESOURCETYPE_ANY, RESOURCEUSAGE_ALL, NULL, &hEnum );
    if ( ErrCode == NO_ERROR )
    {
        BYTE ucBuffer[0x1000];
        NETRESOURCE* lpNr = (NETRESOURCE*)ucBuffer;

        do
        {
            dwCount = 1;
            ErrCode = WNetEnumResource ( hEnum, &dwCount, ucBuffer, (LPDWORD)&BfSize );
        }
        while ( ErrCode == NO_ERROR && dwCount == 1 );

        ErrCode = WNetCloseEnum ( hEnum );
    }

    return 0;
}

That code gives me a perfect list of all computers in my home network. Now I try to figure out how to obtain the names of volumes and/or directories that current user has access to. It might take me a while, I come back with more results.

PaulTheHacker
  • 179
  • 1
  • 8
  • https://learn.microsoft.com/en-us/windows/win32/api/lmshare/nf-lmshare-netshareenum – Alan Birtles Apr 05 '21 at 18:17
  • @Alan: Thank you for your comment. I will give it a try and let you know about my success. – PaulTheHacker Apr 06 '21 at 09:32
  • Hi, going through the example will take me a while. I have been in C# for years now and have to learn again to use C++. – PaulTheHacker Apr 09 '21 at 09:54
  • @Alan: Hey, function NetShareEnum does the trick for me. The catch was that I had to use level=1 (instead of level=2 which requires admin privileges). And I did not have to use C++ (which might be very powerful but costs me too much time to reach an adequate level. Thank you. – PaulTheHacker Apr 09 '21 at 13:38

1 Answers1

0

I have already tried function NetServerDiskEnum but receive ERROR_ACCESS_DENIED.

This is because only members of the Administrators or Server Operators local group can successfully execute the NetServerDiskEnum function on a remote computer.

Refer: NetServerDiskEnum Remarks

Instead, No special group membership is required to successfully execute the NetServerEnum function.

Is there another function that does the trick?

Considering that you are running these computers on your own home network, you can simply set the domain user with administrator privileges.

Refer: How to set administrator rights to domain user?

If you don't want to set administrator privileges, WMI is another option. Of course, the implementation method will be more complicated than calling NetServerDiskEnum.

Using Get-Volume to get the specified Volume object, or all Volume objects if no filter is provided.

Similar case: How to get disk capacity and free space of remote computer

WMI can not only rely on PowerShell to implement their methods, but also C++. If you are interested, it is a good start to learn from this example.

Back to the topic, members of the Administrators group are allowed to remotely connect to the computer by default. But you can grant DCOM remote startup and activation permissions for certain users and groups.

Steps: Setting DCOM Security to Allow a User to Access a Computer Remotely

Strive Sun
  • 5,988
  • 1
  • 9
  • 26
  • Thank you for your fast and detailed response -- gives me a lot to try out. I come back here and let you know about the outcome. – PaulTheHacker Apr 06 '21 at 09:26
  • Too bad, I had not read the documentation for NetDiskServerEnum carefully enough. Indeed, I want the code to execute with the privileges of the current user's code. – PaulTheHacker Apr 08 '21 at 17:20
  • Hi, does the answer solve your issue? Please feel free to let me know if you have any issue and also accept it if it does help. – Zeus Apr 09 '21 at 05:35
  • Hi, I am not through yet. The last thing left was to look through "this example" but I could not make it work (yet?). Even if I supplied the username and password the method failed to connect to any server and terminated with an error code. Elaborating this example will take me a while. I have been in C# for years and have to learn now again to use C++. – PaulTheHacker Apr 09 '21 at 09:52
  • @Strive Sun: Again, thank you for your detailed answer; it put me on the right track. I have reverted to NetShareEnum which gives me the information I need (supposed the level does not require admin privileges). – PaulTheHacker Apr 09 '21 at 13:43