I am looking for a way to convert a UNC path to a local path. The UNC path is for the local machine that is running the installer. I am prompting the user for a directory using \\$HOSTNAME as the root, where $HOSTNAME is the name of the machine. I am prompting this way because I want to ensure that the user chooses a shared folder. I can use the UNC path for all of my NSIS script, however I also need the local path translation for configuring something installed.
Are there any functions to translate UNC to local paths? Possible registry keys or system files with UNC/local path mapping? Any insights would be greatly appreciated.
The target systems are Windows Server 2003.
Currently using NSIS v2.17.
Converting UNC to local path
6 posts
Hi!
Thats not the best way, but it is very easy:
Use "net share" and analyze the output.
-Bruno.
Thats not the best way, but it is very easy:
Use "net share" and analyze the output.
-Bruno.
You can try one of the methods mentioned on http://forums.winamp.com/showthread.php?threadid=206888
I would use:
If you write such a function, could you share it?
++Vitoco
I would use:
then capture the access path from the stack, and use some string manipulation to turn \\$HOSTNAME\MyShare from $INSTDIR into $AccessPath.nsExec::ExecToStack 'NET SHARE MyShare'
If you write such a function, could you share it?
++Vitoco
Thanks for the suggestions. I'm working on a function now. Will post when done.
Originally posted by vitocoHere's a solution that works for me so far. You need to have $HOSTNAME and $sharePath set before calling the function. HOSTNAME is the local machine name and sharePath is a UNC path for your local machine.
If you write such a function, could you share it?
Hope that helps. Oh yeah, the result is stored in shareLP.
!include WordFunc.nsh
!include FileFunc.nsh
!insertmacro GetRoot
!insertmacro WordFind
Var HOSTNAME
Var sharePath
Var shareFolder
Var shareLP
Section
...
ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" ComputerName
StrCpy $HOSTNAME $0
StrCpy $sharePath "\\$HOSTNAME\Your\Share\Folder\Path"
call UNCtoLP
...
SectionEnd
Function UNCtoLP
${GetRoot} $sharePath $0 ;Gets the share root (eg. \\$HOSTNAME\Your)
StrCpy $1 "\\$HOSTNAME\"
StrLen $2 $1
StrCpy $shareFolder $0 "" $2 ;Concat \\$HOSTNAME\ from our root path
nsExec::ExecToStack 'net share "$shareFolder"' ;Get net share output
Pop $0 ;Return code
Pop $1 ;Exec output
StrCmp $0 0 +3
MessageBox MB_OK|MB_ICONEXCLAMATION "Could not map the share folder to local path."
Abort
;parse exec output
${WordFind} $1 "Path " "-01" $R0
${WordFind} $R0 "$\r$\n" "+01" $shareLP
FunctionEnd
you can use GetTempFileName() as follows:
the full path name of the temporary file returned in [buf] contains the local path name for the share; just strip off the filename.ext from the end. (this works on WIN32; i dont know about vista(r)).
char buf[MAX_PATH];
GetTempFileName("\\\\hostname\\share","prefix",0,buf);
DeleteFile(buf);