それは古いポストだにもかかわらず、私は(私があったように)人々はまだ同じシナリオを探しているかもしれないと思います。
下記のscripts.iniを拡張するためのバッチをご覧ください。
2つまたは3つのパラメータが必要です(例:スクリプトの最後)。
また、必要に応じてgpt.iniを編集してください。
gpt.ini here
GUIDを確認する最も簡単な方法は、gpedit.mscで編集して変更を監視することです。
スクリプトを使用して、実環境で使用する前にテストしてください。
@echo off
setlocal enabledelayedexpansion
REM get parameter for scripts.ini changes
if not "%~1"=="" (
set type=%1
) else (
goto enderror
)
if not "%~2"=="" (
set cmd=%2
) else (
goto enderror
)
if not "%~3"=="" (
set params=%3
) else (
set params=
)
if not exist scripts.ini echo. 2>scripts.ini
if exist scripts.ini (
set ctr=0
for /f %%a in (scripts.ini) do (
echo %%a | findstr /C:"[Logon]" 1>nul
if not errorlevel 1 (
set /a ctr+=1
)
)
if !ctr!==0 (
echo [Logon]>>scripts.ini
)
set ctr=0
for /f %%a in (scripts.ini) do (
echo %%a | findstr /C:"[Logoff]" 1>nul
if not errorlevel 1 (
set /a ctr+=1
)
)
if !ctr!==0 (
echo [Logoff]>>scripts.ini
)
)
REM remove scripts-new.ini if exists
if exist scripts-new.ini (
del /F /Q scripts-new.ini
)
REM ctr = number at front for each cmd-param pair - subctr = counter for lines --> pairs - diff = change from Logon to Logoff or vice versa
set ctr=0
set subctr=0
set diff=0
set used=0
for /f %%a in (scripts.ini) do (
set line=%%a
echo !line! | findstr /C:"[Logoff]" 1>nul
if not errorlevel 1 (
if !diff!==1 goto endlogon
)
echo !line! | findstr "CmdLine=!cmd!" 1>nul
if not errorlevel 1 (
set /a used+=1
)
if !diff!==1 (
echo !ctr!!line:~1!>>scripts-new.ini
set /a subctr+=1
if !subctr!==2 (
set /a ctr+=1
set subctr=0
)
)
echo !line! | findstr /C:"[Logon]" 1>nul
if not errorlevel 1 (
set diff=1
echo !line!>>scripts-new.ini
)
)
:endlogon
if /I !type!==logon if !used!==0 (
echo !ctr!CmdLine=!cmd!>>scripts-new.ini
echo !ctr!Parameters=!params!>>scripts-new.ini
)
set ctr=0
set diff=0
set used=0
for /f %%a in (scripts.ini) do (
set line=%%a
echo !line! | findstr /C:"[Logon]" 1>nul
if not errorlevel 1 (
if !diff!==1 goto endlogoff
)
echo !line! | findstr "CmdLine=!cmd!" 1>nul
if not errorlevel 1 (
set /a used+=1
)
if !diff!==1 (
echo !ctr!!line:~1!>>scripts-new.ini
set /a subctr+=1
if !subctr!==2 (
set /a ctr+=1
set subctr=0
)
)
echo !line! | findstr /C:"[Logoff]" 1>nul
if not errorlevel 1 (
set diff=1
echo !line!>>scripts-new.ini
)
)
:endlogoff
if /I !type!==logoff if !used!==0 (
echo !ctr!CmdLine=!cmd!>>scripts-new.ini
echo !ctr!Parameters=!params!>>scripts-new.ini
)
goto end
:enderror
echo Usage: scripts-extender.bat [LOGON ^| LOGOFF] [Script Name] "[optional Parameters for Script - WITH QUOTES!]"
echo Example: scripts-externder.bat logon netlogon.bat "param1 param2"
:end
move /Y scripts.ini scripts-old.ini
move /Y scripts-new.ini scripts.ini