![]() |
#1 |
Junior Member
Join Date: Feb 2007
Location: Santa Monica, California (USA)
Posts: 6
|
Converting a mapped drive to a UNC path
Hello!
I've been running into clients with network setups who have been trying to install onto mapped network drives. This can cause issues, mainly because mapped drives are associated with User logons and can be different depending upon who is logged into a machine. Moreover, services do not obtain mapped drive information, even when given rights to "Log on as:" a particular user. UNC paths, however, do not exhibit this problem. Thus, I wrote a little function to take any windows full path and, if the path uses a mapped drive, convert it to a UNC path. Enjoy!! code: |
![]() |
![]() |
![]() |
#2 |
M.I.A.
[NSIS Dev, Mod] Join Date: Oct 2001
Location: Israel
Posts: 11,343
|
The UNIVERSAL_NAME_INFO structure contains only a pointer to a string. There is no need to allocate 1024 bytes for it, only 4. Call "*(i)" should be good enough. You can use 't' without the ampersand to make it clear the allocation is for a string pointer.
You should create a Wiki page for useful scripts so they won't get lost in the forums. NSIS FAQ | NSIS Home Page | Donate $ "I hear and I forget. I see and I remember. I do and I understand." -- Confucius |
![]() |
![]() |
![]() |
#3 |
Junior Member
Join Date: Feb 2007
Location: Santa Monica, California (USA)
Posts: 6
|
You would think so!
However, what Microsoft doesn't tell you (though they imply it in their example) is that lpBuffer not only contains the UNIVERSAL_NAME_INFO structure, it ALSO contains the string that the structure points to!! Thus, for a 14 byte path like "\\loki\loki_c" you need 18 bytes in your lpBuffer. Hence, my usage of NSIS_MAX_STRLEN. Note, my code is a little misleading... because of the 4 byte size of the structure the maximum length UNC path my function will return is NSIS_MAX_STRLEN-4 = 1020. A sidenote: if you don't give WNetGetUniversalNameA a big enough buffer, it returns the buffer size it does need in lpBufferSize. However, even this non-unicode version asks for a unicode size buffer!! Thus, for "\\loki\loki_c\pub" it would ask for 32 (14*2 + 4) bytes, even though it works with 18 (but set it to 17 and it asks for 32!! lol). Don't you just love Micro$oft?? ![]() |
![]() |
![]() |
![]() |
#4 |
M.I.A.
[NSIS Dev, Mod] Join Date: Oct 2001
Location: Israel
Posts: 11,343
|
So they expect everyone to always query for the required size and make no note of it in the documentation? That's one of the weirdest APIs I've ever seen. Why not LPSTR lpUniversalName[1] as always?
NSIS FAQ | NSIS Home Page | Donate $ "I hear and I forget. I see and I remember. I do and I understand." -- Confucius |
![]() |
![]() |
![]() |
#5 |
Junior Member
Join Date: Feb 2007
Location: Santa Monica, California (USA)
Posts: 6
|
Yes, it's wacky. They actually expect you to guess a size and use it, then only do something if it fails... which, btw, I'm not doing in my script.
|
![]() |
![]() |
![]() |
#6 |
Junior Member
Join Date: Feb 2007
Location: Santa Monica, California (USA)
Posts: 6
|
|
![]() |
![]() |
![]() |
#7 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,358
|
IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#8 |
Junior Member
Join Date: Aug 2013
Posts: 1
|
Hallo,
how can i download the GetUniversalName_nsh? |
![]() |
![]() |
![]() |
#9 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,358
|
The code is right there on the wiki page...
IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#10 |
Junior Member
Join Date: Aug 2013
Posts: 15
|
Sorry, But this( http://nsis.sourceforge.net/Get_Universal_Name ) does not work on my windows 7.
i have tried with WNetGetUniversalNameA WNetGetUniversalName WNetGetUniversalNameW (.. as suggested from hier: http://forums.winamp.com/showthread.php?t=373932 ) these 3 makes no changes.. i get no unc path from any of them.. the return value is always the same path as input path(mapped drive path.) * it is tested with NSIS Unicode Version(2.46.5 from http://www.scratchpaper.com/ ) |
![]() |
![]() |
![]() |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|