Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I currently have this batch file that allow me create an Application and Application Pool in IIS. it works, but it only creates just one Application and Application Pool.

this is my current script:

@echo ON
setlocal enabledelayedexpansion

REM "Content Source path" 
set arg1=%1

REM "Content destination path" 
set arg2=%2

REM "apps to setup" 
set arg3=%3

REM Split virt names and loop through it.
FOR /F "tokens=1* delims=," %%a in (%arg3%) do (

    set vir=%%a
    set pool=!vir!!poolname!

    REM CREATE APPLICATION  
    %systemroot%\system32\inetsrv\APPCMD add app /site.name:"Default Web Site" /path:/!vir! /physicalpath:"%arg2%"

    REM CREATE APP POOL
    %systemroot%\system32\inetsrv\appcmd add apppool /name:!pool! /managedPipelineMode:Integrated /processModel.identityType:ApplicationPoolIdentity /enable32BitAppOnWin64:false

    REM ASSIGN APP POOL TO APPLICATION
    %systemroot%\system32\inetsrv\appcmd set app /app.name:"Default Web Site/!vir!" /applicationPool:!pool!

):END Endlocal

install.bat "c:\source" "c:\target" "APP1,APP2,APP3"

Please can someone tell me what I'm doing wrong.

Thanks.

share|improve this question
add comment

2 Answers

try call your batch:

install.bat "c:\source" "c:\target" APP1,APP2,APP3

without double quotes surrounding APP...
And set args in the batch:

set "arg3=%3,%4,%5"
share|improve this answer
    
that didn't work either, only APP1 was created. –  capiono Jul 17 '13 at 19:01
    
Please have a look at Microsoft's IIS Manual. :) –  Endoro Jul 17 '13 at 19:07
add comment

Issue 1: The :END ENDLOCAL should not follow the closing-parenthesis in the 'for %%a` loop. This generates a syntax error.

Issue 2: If the :END ENDLOCAL is moved to the next line, the endlocal is ineffective. Unlike Assembler, Batch does not execute "instructions" appearing after a label.

Issue 3: The :END label is superfluous. It is not used in the batch.

Issue 4: The endlocal is superfluous - reaching end-of-file closes any local environment operating in the same context.

Issue 5: assigning a variable using %n (n numeric) will INCLUDE the enclosing quotes in the value assigned. Use %~n to dispose of the enclosing quotes.

Issue 6: FOR/F is targeted against files. Whereas it will parse a quoted string as though it was an echo %string% instruction, that is but one line and hence your code will process only one (the number of "lines" encountered) time, assigning the first ,-separated token to %%a and the remainder to %%b (not used)

What you need in this case is far simpler -

FOR %%a in (%arg3%) do (

Issue 7: the variable poolname is not established in this code. Unless it is assigned before the code is executed, set pool=!vir!!poolname! will set pool to !vir! which is itself equivalent to %%a. Given the arguments you've shown, and the changes I've flagged, then within your code, !pool!==!vir!==%%a

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.