Skip to content
⌘ NSIS Forum Archive

saying $Instdir cannot be a certain folder?

9 posts

Dick4#

saying $Instdir cannot be a certain folder?

I haven't really researched this much, but is there any way to say "if $instdir = "C:\folder" then error/msgbox/don't install"?
Dick4#
all my stuff is at work, but this function allows me to do this?

Function .onVerifyInstDir
If $INSTDIR <> "\\path\directory" PathGood
Abort ;
PathGood
FunctionEnd
kichik#
Yes. NSIS calls this function each time it gets a new installation directory selection. If you use Abort inside it the installation directory is deemed invalid. Use StrCmp to do the if of course.
Dick4#
haha, yes, i was just wondering how to do the "if" then I found "strcomp" in the makensis.htm file..thanks!

*edit* ok, last question I promise 🙂 This should work, right?

Function .onVerifyInstDir
If strcmp $INSTDIR "\\path\directory" PathGood
Abort ;
PathGood
FunctionEnd
kichik#
No, there is no if in NSIS, and ; is for comments.

Function .onVerifyInstDir
  StrCmp $INSTDIR "C:\\Bad dir" 0 PathGood
    Abort
  PathGood:
FunctionEnd 
Dick4#
cool, I wrote one up real quick. I see I had it backwards (and I knew about the semicolon, but was missing the colon to designate the section).

I think it works...great, thanks!
kichik#
> but was missing the colon to designate the section

Label, not section 😉

> I think it works...great, thanks!

No problem, try reading the docs all the way next time please.