CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 1999
    Location
    Germay, Baden-Württemberg
    Posts
    18

    How to detect read/write-access on NT-shares?

    Hi,

    I'd like to verify network-access-rights before starting my program. How can I determine if the current user has

    1. read-access
    2. write-access

    to a specific share?

    Erich

    _____________________________________________________________________
    anti-spam: remove dashes in mail-adress to send mail
    Erich Hermann
    ETAS GmbH & Co. KG e-mail: [email protected]
    Borsigstr. 10 Phone: (+49)711-89661-144
    D-70469 Stuttgart Fax: (+49)711-89661-107

  2. #2
    Join Date
    Jun 1999
    Location
    Redmond US
    Posts
    148

    Re: How to detect read/write-access on NT-shares?

    Hi

    You can use Net Functions to achieve this...

    The required API is

    NET_API_STATUS NetShareGetInfo(
    LPWSTR servername,
    LPWSTR netname,
    DWORD level,
    LPBYTE *bufptr
    );

    If you want code for it - get back to me...

    Regards

    Arun D




    Regards

    Arun Dayanandan
    Software Engineer
    Aditi Technologies Pvt Ltd
    Redmond US

  3. #3
    Join Date
    Apr 1999
    Location
    Germay, Baden-Württemberg
    Posts
    18

    Re: How to detect read/write-access on NT-shares?

    Hi Arun,

    this seems to be the function of choice. I took a quick look at the help, but did not understand how the bufptr is to interpreted (I guess SHARE_INFO_0 is needed).

    Since you seem to be familiar with this, would you be as kind as to fill my function?


    BOOL CMyApp::CheckShareAccess( CString path, int mode /*=CFile::modeWrite*/ )
    {
    LPBYTE *bufptr;
    NET_API_STATUS status;
    BOOL bRet = FALSE;

    status = NetShareGetInfo( path, "", SHARE_INFO_0, bufptr );
    if (status == NERR_Success) {
    if (mode == CFile::modeRead) {
    // set bRet=TRUE on read-access
    }

    if (mode == CFile::modeWrite) {
    // set bRet=TRUE on write-access

    }
    }

    return bRet;
    }




    Erich

    _____________________________________________________________________
    anti-spam: remove dashes in mail-adress to send mail
    Erich Hermann
    ETAS GmbH & Co. KG e-mail: [email protected]
    Borsigstr. 10 Phone: (+49)711-89661-144
    D-70469 Stuttgart Fax: (+49)711-89661-107

  4. #4
    Join Date
    Jun 1999
    Location
    Redmond US
    Posts
    148

    Re: How to detect read/write-access on NT-shares?

    Hi Erich

    Sorry I could not mail to you earlier....

    I hope the parameters are clear to you. In the second parameter specify the share name which you want to access. The shareInfo structure's member variable's will contain all the information of the share name.(Note you are passing shareInfo as a reference...)

    Char shareName[]= "Name of the Share";
    SHARE_INFO_2 shareInfo;
    DWORD status;

    status = NetShareGetInfo(
    NULL,
    ShareName,
    2, // return a SHARE_INFO_2 structure
    (LPBYTE *) &shareInfo
    );

    Here is SHARE_INFO_2 member variables

    typedef struct _SHARE_INFO_2
    {
    LPWSTR shi2_netname;
    DWORD shi2_type;
    LPWSTR shi2_remark;
    DWORD shi2_permissions;
    DWORD shi2_max_uses;
    DWORD shi2_current_uses;
    LPWSTR shi2_path;
    LPWSTR shi2_passwd;
    }

    you can use shi2_permissions to get the permission on the share...whether Read or Write etc....

    Hope this would solve your problem....

    If you have still problem do get me back...


    regards...

    Arun D


    Regards

    Arun Dayanandan
    Software Engineer
    Aditi Technologies Pvt Ltd
    Redmond US

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured