Retrieving Connected Mapped Network Drives: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
 
No edit summary
Line 3: Line 3:
Just a simple function that retrieves from registry the mapped network drives on a system, and returns only those that are actually connected.<BR>
Just a simple function that retrieves from registry the mapped network drives on a system, and returns only those that are actually connected.<BR>


== Invoking the function ==
== Invoke the function ==
<highlight-nsis>
<highlight-nsis>
   ;call the function
   ;call the function

Revision as of 14:38, 2 January 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