MrEyes
30th March 2006 15:54 UTC
Reading Console Output
After much hunting around I havent found the answer to this question, so its time to turn to you guys.
I need to execute a console command and read the output into an NSIS variable so I can then use it elsewhere.
As an example the following command:
adsutil.vbs ENUM /P W3SVC
outputs
[/W3SVC/Info]
[/W3SVC/Filters]
[/W3SVC/1]
[/W3SVC/2]
[/W3SVC/3]
[/W3SVC/4]
I need to get the last [/W3SVC/X] entry, increment the X number by one and put the result into an NSIS variable so that I can then use it elsewhere, e.g.
nsExec::ExecToLog /TIMEOUT=5000 'cscript.exe //B c:\inetpub\adminscripts\adsutil.vbs START_SERVER W3SVC/$R0'
kichik
30th March 2006 16:00 UTC
Use nsExec::ExecToStack.
MrEyes
30th March 2006 17:13 UTC
Thanks for that, wood for the trees situation I thinks.
For the benefit of anybody searching these forums in the future I was looking for a way to get NSIS to create and configure a new IIS site. The following is the relevant NSIS code
;get the last W3SVC id
nsExec::ExecToStack 'cscript.exe c:\inetpub\adminscripts\adsutil.vbs ENUM /P W3SVC'
Pop $0 ;return code
Pop $1 ;output
;parse out the last W3SVC id from $1 output
StrCpy $2 $1 "" -6
StrCpy $3 $2 1
;increment result by 1
IntOp $4 $3 + 1
;create new site (using incremented last number in /W3SVC/X from output above)
nsExec::ExecToStack 'cscript.exe c:\inetpub\adminscripts\adsutil.vbs create_vserv W3SVC/$4'
;copy settings from root site
nsExec::ExecToStack 'cscript.exe c:\inetpub\adminscripts\adsutil.vbs copy W3SVC/$3 W3SVC/$4'
;name the new site
nsExec::ExecToStack 'cscript.exe c:\inetpub\adminscripts\adsutil.vbs set W3SVC/$4/ServerComment "SiteNameGoesHere"'
;set new site to listen on 443 for SSL
nsExec::ExecToStack 'cscript.exe c:\inetpub\adminscripts\adsutil.vbs SET W3SVC/$4/SecureBindings ":443:"'
;set new home directory
nsExec::ExecToStack 'cscript.exe c:\inetpub\adminscripts\adsutil.vbs SET W3SVC/5/Root/Path "C:\RootDirectory"'
;Start new site
nsExec::ExecToStack 'cscript.exe c:\inetpub\adminscripts\adsutil.vbs START_SERVER W3SVC/$4'
The sample doesnt include a mechanism to get the site name/path/ports into it but this can easily be done with a custom page or two.