Retrieving Connected Mapped Network Drives: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 5: Line 5:
== Invoke the function ==
== Invoke the function ==
<highlight-nsis>
<highlight-nsis>
  ;call the function
Section "Install"
  call FindNetDrives
${FindNetDrives} $R0
  ;get the result
DetailPrint "$R0"
  Pop $R0
SectionEnd
  ;at this point $R0 contais error if no mapped drive found
 
  DetailPrint '$R0'
Section "Uninstall"
${un.FindNetDrives} $R0
DetailPrint "$R0"
SectionEnd
</highlight-nsis>
</highlight-nsis>


Line 16: Line 19:
<highlight-nsis>
<highlight-nsis>
Function FindNetDrives
Function FindNetDrives
!define FindNetDrives    '!insertmacro _FindNetDrives ""'
!define un.FindNetDrives  '!insertmacro _FindNetDrives "un."'
!macro _FindNetDrives UN _Result
  Call ${UN}FindNetDrives
  Pop ${_Result}
!macroend
   Push $2
   Push $2
   Push $1
   Push $1
Line 39: Line 51:
   Exch 2
   Exch 2
   Exch
   Exch
   goto end  
   goto end


done:  ;found mapped network drives
done:  ;found mapped network drives
Line 51: Line 63:
   Pop $1
   Pop $1
   Pop $2
   Pop $2
FunctionEnd
FunctionEnd
</highlight-nsis>
</highlight-nsis>

Revision as of 20:14, 8 February 2007

Author: Red Wine (talk, contrib)


Description

Just a simple function that retrieves from registry the mapped network drives on a system, and returns only those that are actually connected.

Invoke the function

Section "Install"
 ${FindNetDrives} $R0
 DetailPrint "$R0"
SectionEnd
 
Section "Uninstall"
 ${un.FindNetDrives} $R0
 DetailPrint "$R0"
SectionEnd

The Function

Function FindNetDrives
 
 !define FindNetDrives     '!insertmacro _FindNetDrives ""'
 !define un.FindNetDrives  '!insertmacro _FindNetDrives "un."'
 
 !macro _FindNetDrives UN _Result
  Call ${UN}FindNetDrives
  Pop ${_Result}
 !macroend
 
  Push $2
  Push $1
  Push $0
 
  StrCpy $2 ''
  StrCpy $0 0
 
loop:
  EnumRegKey $1 HKCU Network $0
  StrCmp $1 "" exit
  IfFileExists '$1:\*' 0 +2
  StrCpy '$2' '$2 $1'
  IntOp $0 $0 + 1
  goto loop
 
exit:
  StrCmp $2 '' nonetdrv done
 
nonetdrv: ;not found mapped network drive
  Push 'error'
  Exch 3
  Exch 2
  Exch
  goto end
 
done:   ;found mapped network drives
  Push '$2'
  Exch 3
  Exch 2
  Exch
 
end:
  Pop $0
  Pop $1
  Pop $2
 
FunctionEnd

License

This function is provided 'as-is', without any express or implied warranty. In no event will the author be held liable for any damages arising from the use of this function.

Permission is granted to anyone to use this header file for any purpose, including commercial applications, and to alter it and redistribute it freely.