Old 29th October 2009, 16:50   #1
jpo
Junior Member
 
Join Date: Oct 2009
Posts: 4
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.
jpo is offline   Reply With Quote
Old 29th October 2009, 18:13   #2
Takhir
Major Dude
 
Join Date: Feb 2004
Location: Moscow, Russia
Posts: 1,222
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 is offline   Reply With Quote
Old 29th October 2009, 19:12   #3
jpo
Junior Member
 
Join Date: Oct 2009
Posts: 4
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.
jpo is offline   Reply With Quote
Old 30th October 2009, 07:15   #4
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
Quote:
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 is offline   Reply With Quote
Old 30th October 2009, 13:11   #5
jpo
Junior Member
 
Join Date: Oct 2009
Posts: 4
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
jpo is offline   Reply With Quote
Old 30th October 2009, 13:40   #6
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
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.
MSG is offline   Reply With Quote
Old 30th October 2009, 13:43   #7
jpo
Junior Member
 
Join Date: Oct 2009
Posts: 4
OK, thanks for the clarification.
jpo is offline   Reply With Quote
Old 31st October 2009, 05:34   #8
Takhir
Major Dude
 
Join Date: Feb 2004
Location: Moscow, Russia
Posts: 1,222
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.
Takhir is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump