Archive: Install supported from Local Drive Only


Install supported from Local Drive Only
  Does anyone have any recommendations as to how I can run checks in a NSIS package to see if the install is run from a local drive. I have an installer that has some issues if it is run from across the network since there is a NIC wrapper that is installed..

Thanks...


Use GetDrives and validate $INSTDIR against it.

Stu


For anyone ever looking for how to do this, this is the following piece I used... The benefit of the below code is that I use NSIS as a wrapper for installers and on some the reset the network interface. If the installation is ran from a network source, it breaks the connection back to the source EXE causing a lockup. This forces the user to run the installation from a local source...

Thanks and sorry for the late response Afrow, finally got around to working on this...


verbose 2


Name "Non Net Drive Example"
>OutFile "NonNet.exe"
>ShowInstDetails show
RequestExecutionLevel user

>!include "FileFunc.nsh"
>!include "LogicLib.nsh"

>Var STR_HAYSTACK
>Var STR_NEEDLE
>Var STR_CONTAINS_VAR_1
>Var STR_CONTAINS_VAR_2
>Var STR_CONTAINS_VAR_3
>Var STR_CONTAINS_VAR_4
>Var STR_RETURN_VAR

>Function StrContains
Exch $STR_NEEDLE
Exch 1
Exch $STR_HAYSTACK
; Uncomment to debug
;MessageBox MB_OK 'STR_NEEDLE = $STR_NEEDLE STR_HAYSTACK = $STR_HAYSTACK '
StrCpy $STR_RETURN_VAR ""
StrCpy $STR_CONTAINS_VAR_1 -1
StrLen $STR_CONTAINS_VAR_2 $STR_NEEDLE
StrLen $STR_CONTAINS_VAR_4 $STR_HAYSTACK
loop:
IntOp $STR_CONTAINS_VAR_1 $STR_CONTAINS_VAR_1 + 1
StrCpy $STR_CONTAINS_VAR_3 $STR_HAYSTACK $STR_CONTAINS_VAR_2 $STR_CONTAINS_VAR_1
StrCmp $STR_CONTAINS_VAR_3 $STR_NEEDLE found
StrCmp $STR_CONTAINS_VAR_1 $STR_CONTAINS_VAR_4 done
Goto loop
found:
StrCpy $STR_RETURN_VAR $STR_NEEDLE
Goto done
done:
Pop $STR_NEEDLE ;Prevent "invalid opcode" errors and keep the
Exch $STR_RETURN_VAR
FunctionEnd

>!macro _StrContainsConstructor OUT NEEDLE HAYSTACK
Push "${HAYSTACK}"
Push "${NEEDLE}"
Call StrContains
Pop "${OUT}"
>!macroend

>!define StrContains '!insertmacro "_StrContainsConstructor"'

>Section
${GetDrives} "ALL" "Example3"
># MessageBox MB_OK "$EXEPATH"
# MessageBox MB_OK "Type of drive $R1 is $R0"
${If} $R0 != "HDD"
${AndIf} $R0 != "CDROM"
${AndIf} $R0 != "RAM"
${AndIf} $R0 != "FDD"
MessageBox MB_OK "This installation is being ran from an unsupported install source"
${EndIf}
>SectionEnd

>Function Example3
${StrContains} $R1 $9 $EXEPATH
># MessageBox MB_OK "$9: $8"
${If} $R1 == $9
StrCpy $R0$8 # Drive Type
StrCpy $0 StopGetDrives
${EndIf}
Push $0
FunctionEnd
>