Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 632081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:02:13+00:00 2026-05-13T20:02:13+00:00

I’m looking for a method to get corresponding local path for a given UNC

  • 0

I’m looking for a method to get corresponding local path for a given UNC path. Microsoft provides a small library CheckLCL for this purpose. This library is not supported on all Windows versions. Does anybody know any open source method for this?

There is also MAPI function ScLocalPathFromUNC, but am not sure if it works on all platforms.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:02:13+00:00Added an answer on May 13, 2026 at 8:02 pm

    After some googling and digging in MSDN i have the following solution:

    #include <Crtdbg.h>    // for debug stuff
    #include "Winnetwk.h"  // for WNetGetUniversalName()
    #include "Lm.h"        // for NetShareGetInfo()
    #include "pystring.h"  // from http://code.google.com/p/pystring
    
    #pragma comment( lib, "Mpr.lib" )       // for WNetGetUniversalName()
    #pragma comment( lib, "Netapi32.lib" )  // for NetShareGetInfo()
    
    //-----------------------------------------------------------------------------
    // converts x:\\folder -> \\\\server\\share\\folder
    bool ConvertLocalPathToUNC(const char* szFilePath, std::string& strUNC)
    {
      // get size of the remote name buffer
      DWORD dwBufferSize = 0;
      char szBuff[2];
      if (::WNetGetUniversalName(szFilePath, UNIVERSAL_NAME_INFO_LEVEL, szBuff, &dwBufferSize) == ERROR_MORE_DATA)
      {
        // get remote name of the share
        char* buf = new char[dwBufferSize];
        UNIVERSAL_NAME_INFO* puni = (UNIVERSAL_NAME_INFO*) buf;
    
        if (::WNetGetUniversalName(szFilePath, UNIVERSAL_NAME_INFO_LEVEL, buf, &dwBufferSize) == NO_ERROR)
        {
          strUNC = puni->lpUniversalName;
          delete [] buf;
          return true;
        }
        delete [] buf;
      }
    
      return false;
    }
    
    //-----------------------------------------------------------------------------
    // converts \\\\server\\share\\folder -> x:\\folder
    bool ConvertUNCToLocalPath(const char* szUNC, std::string& strLocalPath)
    {
      // get share name from UNC
      std::string strUNC(szUNC);
      std::vector< std::string > vecTokens;
      pystring::split(strUNC, vecTokens, _T("\\"));
    
      if (vecTokens.size() < 4)
        return false;
    
      // we need wchar for NetShareGetInfo()
      std::wstring strShare(vecTokens[3].length(), L' ');
      std::copy(vecTokens[3].begin(), vecTokens[3].end(), strShare.begin());
    
      PSHARE_INFO_502  BufPtr;
      NET_API_STATUS   res;
      if ((res = NetShareGetInfo(NULL, const_cast<LPWSTR>(strShare.c_str()), 502, (LPBYTE*) &BufPtr)) == ERROR_SUCCESS)
      {
        // print the retrieved data.
        _RPTF3(_CRT_WARN, _T("%ls\t%ls\t%u\n"), BufPtr->shi502_netname, BufPtr->shi502_path, BufPtr->shi502_current_uses);
    
        std::wstring strPath(BufPtr->shi502_path);
        strLocalPath.assign(strPath.begin(), strPath.end());
    
        // build local path
        for (size_t i = 4; i < vecTokens.size(); ++i)
        {
          if (!pystring::endswith(strLocalPath, _T("\\")))
            strLocalPath += _T("\\");
          strLocalPath += vecTokens[i];
        }
    
        // Validate the value of the shi502_security_descriptor member.
        if (IsValidSecurityDescriptor(BufPtr->shi502_security_descriptor))
          _RPTF0(_CRT_WARN, _T("It has a valid Security Descriptor.\n"));
        else
          _RPTF0(_CRT_WARN, _T("It does not have a valid Security Descriptor.\n"));
    
        // Free the allocated memory.
        NetApiBufferFree(BufPtr);
      }
      else
        return false;
    
      return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 349k
  • Answers 349k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think you should be fine if you simply include… May 14, 2026 at 6:44 am
  • Editorial Team
    Editorial Team added an answer What should $(this) be? If you have a reference to… May 14, 2026 at 6:44 am
  • Editorial Team
    Editorial Team added an answer There are as always different possibilities to work with CSV… May 14, 2026 at 6:44 am

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.