How do I obtain the comment for a share?


Today's Little Program obtains the comment string for a share. This is what shows up in the net view output like this:

C:\>>net view \\scratch
Shared resources at \\scratch

Share name  Type  Used as  Comment

-------------------------------------------------------------------------------
temp        Disk           MAY BE DELETED AT ANY TIME WITHOUT WARNING
The command completed successfully.

Here goes. Remember: Little Programs do little to no error checking.

#define UNICODE
#define _UNICODE
#include <windows.h>
#include <lm.h>
#include <stdio.h>

int __cdecl wmain(int argc, wchar_t **argv)
{
 PSHARE_INFO_1 info1;
 NetShareGetInfo(argv[1], argv[2], 1, (LPBYTE*)&info1);
 printf("name = %ls\n", info1->shi1_netname);
 printf("remark = %ls\n", info1->shi1_remark);
 NetApiBufferFree(info1);
 return 0;
}

The expected command line arguments are the server name and the share name. We ask for information level 1, which gives us the name, the type, and the remark. I just print the name and the remark.

Bonus program:

#define UNICODE
#define _UNICODE
#include <windows.h>
#include <lm.h>
#include <stdio.h>

int __cdecl wmain(int argc, wchar_t **argv)
{
 PSERVER_INFO_101 info101;
 NetServerGetInfo(argv[1], 101, (LPBYTE*)&info101);
 printf("comment = %ls\n", info101->sv101_comment);
 NetApiBufferFree(info101);
 return 0;
}

This program prints the server comment.

Comments (4)
  1. Anon says:

    Unrelated to the post, but related to the blog, Raymond is a big-time reality TV star: channel9.msdn.com/.../Defrag-Tools-142-Raymond-Chen-Old-New-Thing

  2. Gabe says:

    I must say, that looking at the numberings of the various information structures, I have to wonder how they got numbered.

    It's almost as if different groups were assigned different numeric ranges and then numbers were chosen arbitrarily within those ranges.

    For example, SHARE_INFO has numbers, 0, 1, 2, 501, 502, 503, 1004, 1005, 1006, and 1501; while SERVER_INFO has 100, 101, 102, 402, 403, 502, 503, 1005, 1010, 1016, 1017, 1018, 1107, and many in the 1500 range.

  3. jonwil says:

    Always interesting to see these "how do you do xyz" posts (i.e. getting a piece of info that is displayed in the output of some part of Windows)

    The in-depth look at parts of the User subsystem in Raymond's book is amazing as well.

  4. Killer{R} says:

    oh, whose Net*.. Remembered that first time I felt myself hacker when NetShareEnum revealed that hidden share$ in our university campus network..

Comments are closed.

Skip to main content