Retrieving Connected Mapped Network Drives: Difference between revisions

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


== The Function ==
== The Function ==
<highlight-nsis>
<highlight-nsis>
Function FindNetDrives
!macro _FindNetDrivesCall UN _Result
  !verbose push
    !verbose 3
      Call ${UN}FindNetDrives
      Pop ${_Result}
  !verbose pop
!macroend
 
!macro FindNetDrives
  !verbose push
    !verbose 3
      !insertmacro _FindNetDrivesFunc ""
      !define FindNetDrives    '!insertmacro _FindNetDrivesCall ""'
  !verbose pop
!macroend
 
!macro un.FindNetDrives
  !verbose push
    !verbose 3
      !insertmacro _FindNetDrivesFunc "un."
      !define un.FindNetDrives  '!insertmacro _FindNetDrivesCall "un."'
  !verbose pop
!macroend
 
!macro _FindNetDrivesFunc UN
Function ${UN}FindNetDrives
 
   Push $2
   Push $2
   Push $1
   Push $1
Line 39: Line 71:
   Exch 2
   Exch 2
   Exch
   Exch
   goto end  
   goto end


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


Line 64: Line 98:
it freely.
it freely.


[[Category:Disk, Path & File Functions]]
[[Category:Disk, Path & File Functions]]

Latest revision as of 16:22, 25 July 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

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

The Function

!macro _FindNetDrivesCall UN _Result
  !verbose push
    !verbose 3
      Call ${UN}FindNetDrives
      Pop ${_Result}
  !verbose pop
!macroend
 
!macro FindNetDrives
  !verbose push
    !verbose 3
      !insertmacro _FindNetDrivesFunc ""
      !define FindNetDrives     '!insertmacro _FindNetDrivesCall ""'
  !verbose pop
!macroend
 
!macro un.FindNetDrives
  !verbose push
    !verbose 3
      !insertmacro _FindNetDrivesFunc "un."
      !define un.FindNetDrives  '!insertmacro _FindNetDrivesCall "un."'
  !verbose pop
!macroend
 
!macro _FindNetDrivesFunc UN
Function ${UN}FindNetDrives
 
  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
!macroend

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.