NetShareEnum (..) winapi not able to remove unnecessary sharefolders
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: NetShareEnum (..) winapi not able to remove unnecessary sharefolders

  1. #1
    Join Date
    Jan 2012
    Posts
    17

    NetShareEnum (..) winapi not able to remove unnecessary sharefolders

    For getting the share folder name i have been used the following code , here i am able to get the folder names . But the problem what i am facing is along with the share folder created by the user it gives some extra folder also , i don't know how to prevent the programe to hide that unnecessary folder names . Like in my case i am getting "cc_views"(used for clearcase) and "Users" folders , which i want to remove from my folder lists .

    I wrote the following codes , Please help in getting the correct output .

    #ifndef UNICODE
    #define UNICODE
    #endif
    #include <windows.h>
    #include <stdio.h>
    #include <lm.h>
    #pragma comment(lib, "Netapi32.lib")
    #pragma comment(lib, "Advapi32.lib")

    void wmain( int argc, TCHAR *lpszArgv[ ])
    {
    PSHARE_INFO_502 BufPtr,p;
    NET_API_STATUS res;
    LPTSTR lpszServer = NULL;
    DWORD er=0,tr=0,resume=0, i;

    switch(argc)
    {
    case 2:
    lpszServer = lpszArgv[1];
    break;
    default:
    printf("Usage: NetShareEnum <servername>\n");
    //return;
    }
    //
    // Print a report header.
    //
    printf("ShareFolderName\n");
    printf("---------------\n");
    //
    // Call the NetShareEnum function; specify level 502.
    //
    do // begin do
    {
    res = NetShareEnum ((LPSTR)lpszServer, 502, (LPBYTE *) &BufPtr, MAX_PREFERRED_LENGTH, &er, &tr, &resume);
    //
    // If the call succeeds,
    //
    if(res == ERROR_SUCCESS || res == ERROR_MORE_DATA)
    {
    p=BufPtr;
    //
    // Loop through the entries;
    // print retrieved data.
    //
    for(i=1;i<=er;i++)
    {
    LPCTSTR str = (LPCTSTR)p->shi502_remark;
    if(!(lstrcmpi(str,L"Remote admin")==0 ||lstrcmpi(str, L"Remote IPC")==0 || lstrcmpi(str,L"Default share")==0)) //Help in removing from extra folder based on the remarks
    printf("%-20S%\n",p->shi502_netname);
    p++;
    }
    //
    // Free the allocated buffer.
    //
    NetApiBufferFree(BufPtr);
    }
    else
    printf("Error: %ld\n",res);
    }
    // Continue to call NetShareEnum while
    // there are more entries.
    //
    while (res==ERROR_MORE_DATA); // end do
    return;
    }

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,050

    Re: NetShareEnum (..) winapi not able to remove unnecessary sharefolders

    The API is not aware of your desires. It just enumerates shares available on the target host. If you want something in the list be filtered out, please do it yourself.
    Best regards,
    Igor

  3. #3
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,746

    Re: NetShareEnum (..) winapi not able to remove unnecessary sharefolders

    Before posting, please properly format your code with indentations etc so that if can be read and understood more easily. Also please use code tags (Go Advanced, select code and click '#').

    Quote Originally Posted by Igor Vartanov View Post
    The API is not aware of your desires. It just enumerates shares available on the target host. If you want something in the list be filtered out, please do it yourself.
    This is the only way you are going to restrict what is displayed. NetShareEnum returns info about ALL shares on the target computer that are available. What you do with the returned info is up to you. The info returned about a share also includes the type of share and the path being shared. This may also be useful to filter out unwanted entries.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center