2024年10月22日 星期二

bat 讀檔存成另個檔案

在echo !line!時改成 echo(!line!

可以避免讀到空值時秀出echo is off的訊息

@echo off

setlocal enabledelayedexpansion
for /f "delims=:" %%a in ('findstr /n "AXX0000XXXA" "C:\Users\23456\Desktop\data.txt"') do (set /A find_line=%%a-1)
call :processFile < "C:\Users\23456\Desktop\data.txt" > target.txt
goto :EOF


:processFile

rem Duplicate the first %find_line%-1 lines
for /L %%i in (1,1,%find_line%) do (
   set /P "line="
   echo(!line!
)

rem Insert the additional line
type temp.txt

rem Copy the rest of lines
findstr ^^

exit /B

參考:windows - Why this code says echo is off? - Stack Overflow

2024年10月8日 星期二

使用command line 建立一個IIS web site

@SET /P A_ans=please type the Account for the Identity=

@SET /P P_ans=please type the password for the Identity=

powershell Expand-Archive "%~dp0Web.zip" -DestinationPath "%~dp0Web"

robocopy "%~dp0Web" "D:\temp" /E


REM add application pool

%WINDIR%\system32\inetsrv\appcmd.exe set config -section:system.applicationHost/applicationPools /+"[name='NewAppPool',autoStart='True',managedPipelineMode='Integrated']" /commit:apphost

%WINDIR%\system32\inetsrv\appcmd.exe set config /section:applicationPools /[name='NewAppPool'].processModel.identityType:SpecificUser /[name='NewAppPool'].processModel.userName:%A_ans% /[name='NewAppPool'].processModel.password:%P_ans% 


REM add app

%WINDIR%\system32\inetsrv\appcmd.exe add app /site.name:"Default Web Site" /path:/NewWeb /physicalPath:"D:\temp\Web" /applicationPool:NewAppPool