October 5th, 2015

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.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.