Archive: Re: Windows Command Prompt Access from installer script


Re: Windows Command Prompt Access from installer script
Is it possible to access the windows command prompt from an NSIS installer script file? In my installer script, I'd like to perform the following actions:

1. ping a server X
1a. if the ping is successful, place the server name X in a registry value
1b. if the ping is unsuccessful, place the server name Y in a registry value

I know how to write registry values (WriteRegStr). Unfortunately, I don't see how I could access and interpret a Windows command prompt "dialogue". While accessing the command prompt would be more intuitive to me, just being able to ping and interpret the results would be sufficient for my project.


Ping may be filtered in customer' network. IMHO better way is a short HTTP request. For example requesting HTTP headers only (or some short file from server). NSISdl included to distribution, but http://nsis.sourceforge.net/Inetc_plug-in has more features.


Takhir,

Are you suggesting an FTP request instead of a ping to the desired server? The "server X" is just a file server, so I don't know if it could do web requests, etc.

Assuming that you mean an FTP request, my only concern would be that the installer script would not know the appropriate user name/password to access the server. If the script doesn't know that information, will your suggestion still work?

Thanks again for your help.


Originally posted by jpo
Takhir,

Are you suggesting an FTP request instead of a ping to the desired server? The "server X" is just a file server, so I don't know if it could do web requests, etc.

Assuming that you mean an FTP request, my only concern would be that the installer script would not know the appropriate user name/password to access the server. If the script doesn't know that information, will your suggestion still work?

Thanks again for your help.
Well you could of course just make a guest account on the FTP server, one without any priviledges so that even if someone hacked the login from your installer it shouldn't cause any problems. Theoretically.

To answer your ping question, take a look at the nsExec plugin (ExecToLog function).

MSG,

Thanks for the info. Here's what I ended up doing:

Name "Test"
OutFile "Test.exe"

Section ""

; returns 1 (error) if ping returned "could not find host" or "request timed out"
nsExec::ExecToLog 'ping 192.0.0.1 -n 2 -w 200'
Pop $0 ;return value
IntCmp $0 0 PingDone

MessageBox MB_OK "Defaulting to external address"
goto Done

PingDone:
MessageBox MB_OK "Defaulting to internal address"


Done:
SectionEnd


Err... You're supposed to supply a path to write to, when you use the ExecToLog function. Because it, you know, outputs to a log file. If you just want to pop the return value from ping, use nsExec::Exec.


OK, thanks for the clarification.


jpo, I had in mind http access. But Inetc supports ftp as well. If login/password is not set in URL, you will get answer from server "530" (Anonymous access not allowed)... Or "550" (File not found). "Connection error" if no access to server. But ftp port may be closed as well.