AppCmd在IIS7中的默认网站中创建虚拟目录


11

我尝试使用在IIS 7的“默认网站”下创建一个虚拟目录AppCmd

但是首先,我想看看是否已经存在。如何使用AppCmd“默认网站”下的虚拟目录创建一个if语句?

Answers:


11

尝试这个:

@ECHO OFF
REM --------------------------------------------------------------------------------
REM Check for and create VDir under Default Web Site
REM
REM %1 is the VDIR to create
REM %2 is the Physical path to the VDIR 
REM --------------------------------------------------------------------------------

IF "%1"=="" GOTO Syntax
IF "%2"=="" GOTO Syntax

ECHO Running...
ECHO   AppCmd.exe list vdir "Default Web Site/%1/"
ECHO.
AppCmd.exe list vdir "Default Web Site/%1/"
IF %errorlevel%==1 GOTO Exists

ECHO.
ECHO Running...
ECHO   AppCmd.exe ADD vdir /app.name:"Default Web Site/" /path:/%1 /physicalPath:%2
ECHO.
AppCmd.exe ADD vdir /app.name:"Default Web Site/" /path:/%1 /physicalPath:%2

GOTO End

:Exists
ECHO.
ECHO VDir already exists
ECHO.
GOTO End

:SYNTAX
ECHO.
ECHO VDir Name and Physical Path Required
ECHO.
ECHO CreateVDir.CMD ^<VDirName^> C:\PhysPath
ECHO.

:END

凉!这就是我所需要的!谢谢!看起来ServerFault可能和SO一样好!
Riri

2
对于我不存在的虚拟目录,这似乎不会触发退出代码1。使用IIS 7.5。
jpmc26 2014年

1

尝试这个。基本上与Christopher_G_Lewis给出的答案相同,但它依赖于列表输出的解析而不是错误代码,我也没有得到。

还利用了cmd.exe shell构造A ||。B(如果A失败则B)

@ECHO OFF
REM --------------------------------------------------------------------------------
REM Check for and create VDir under Default Web Site
REM
REM %1 is the VDIR to create
REM %2 is the Physical path to the VDIR 
REM --------------------------------------------------------------------------------

IF "%1"=="" GOTO Syntax
IF "%2"=="" GOTO Syntax

AppCmd.exe list vdir "Default Web Site/%1/" | findstr /I "Default Web Site/%1/" || AppCmd.exe add vdir /app.name:"Default Web Site/" /path:/%1 /physicalPath:%2

goto :eof
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.