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>
Section "Install"
  ;call the function
${FindNetDrives} $R0
  call FindNetDrives
DetailPrint "$R0"
  ;get the result
SectionEnd
  Pop $R0
 
  ;at this point $R0 contais error if no mapped drive found
Section "Uninstall"
  DetailPrint '$R0'
${un.FindNetDrives} $R0
DetailPrint "$R0"
SectionEnd
</highlight-nsis>
</highlight-nsis>


Line 19: Line 16:
<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 51: Line 39:
   Exch 2
   Exch 2
   Exch
   Exch
   goto end
   goto end  


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

Revision as of 20:22, 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

  ;call the function
  call FindNetDrives
  ;get the result
  Pop $R0
  ;at this point $R0 contais error if no mapped drive found
  DetailPrint '$R0'

The Function

Function 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

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.