Iis-7

AppCmd 在 IIS7 的預設網站中創建虛擬目錄

  • August 5, 2016

我嘗試在 IIS 7 的“預設網站”下使用AppCmd.

但首先我想看看一個是否已經存在。如何使用AppCmd在“預設網站”下創建虛擬目錄以及如何執行 if 語句?

嘗試這個:

@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

引用自:https://serverfault.com/questions/46932