powershell migration

This commit is contained in:
2025-10-07 21:21:47 +03:00
parent 4829e210e9
commit dc22461901
18 changed files with 158 additions and 97 deletions
+12
View File
@@ -0,0 +1,12 @@
@echo off
setlocal
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
echo Restarting as Admin...
powershell -Command "Start-Process -FilePath '%~dp0apps-manager.bat' -ArgumentList 'connect' -Verb RunAs"
exit /b
)
call "%~dp0apps-manager.bat" connect
endlocal
+11
View File
@@ -0,0 +1,11 @@
@echo off
setlocal
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
echo Restarting as Admin...
powershell -Command "Start-Process -FilePath '%~dp0apps-manager.bat' -ArgumentList 'disconnect' -Verb RunAs"
exit /b
)
call "%~dp0apps-manager.bat" disconnect
endlocal
+95
View File
@@ -0,0 +1,95 @@
@echo off
:: ==========================================
:: Проверка прав администратора
:: ==========================================
@REM >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
@REM if '%errorlevel%' NEQ '0' (
@REM echo Требуются права администратора. Перезапуск...
@REM powershell -Command "Start-Process -FilePath '%~f0' -ArgumentList '%*' -Verb RunAs "
@REM exit /b
@REM )
:: ==========================================
:: Инициализация
:: ==========================================
setlocal EnableDelayedExpansion
set "init=%~dp0\settings\init.bat"
call "%init%"
set "config=%apps-all%"
:: ==========================================
:: Аргумент действия
:: ==========================================
set "action=%1"
if "%action%"=="" set "action=reconnect"
:: ==========================================
:: Обработка CSV
:: ==========================================
for /f "skip=1 tokens=1-8 delims=," %%A in (%config%) do (
set "App=%%A"
set "From=%%B"
set "To=%%C"
set "Type=%%D"
set "Enabled=%%E"
set "ExtraVariables=%%~F"
set "ExtraConnect=%%~G"
set "ExtraDisconnect=%%~H"
if "!Enabled!"=="1" (
:: Разворачиваем стандартные переменные окружения
call set "From=!From!"
call set "To=!To!"
call set "ExtraConnect=!ExtraConnect!"
call set "ExtraDisconnect=!ExtraDisconnect!"
:: Выполняем Extra-Variables как команду
if not "!ExtraVariables!"=="" (
echo !ExtraVariables!
)
echo ==============================
echo Processing !App! with action %action% (Type=!Type!)
if /I "!Type!"=="isolate" (
:: Для isolate исполняем только extra команды
if /I "%action%"=="disconnect" if not "!ExtraDisconnect!"=="" call !ExtraDisconnect!
if /I "%action%"=="connect" if not "!ExtraConnect!"=="" call !ExtraConnect!
if /I "%action%"=="reconnect" (
if not "!ExtraDisconnect!"=="" call !ExtraDisconnect!
if not "!ExtraConnect!"=="" call !ExtraConnect!
)
) else (
:: default — обычное поведение
if /I "%action%"=="disconnect" call :disconnect
if /I "%action%"=="connect" call :connect
if /I "%action%"=="reconnect" (
call :disconnect
call :connect
)
)
)
)
:: ==========================================
:: Завершение
:: ==========================================
:end
endlocal
exit /b
:: ==========================================
:: Функции
:: ==========================================
:disconnect
echo Removing "!To!"...
rd /Q "!To!" 2>nul
if not "!ExtraDisconnect!"=="" call !ExtraDisconnect!
goto :eof
:connect
echo Creating symlink "!To!" -> "!From!"...
mklink /D "!To!" "!From!"
if not "!ExtraConnect!"=="" call !ExtraConnect!
goto :eof
+11
View File
@@ -0,0 +1,11 @@
@echo off
setlocal
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
echo Restarting as Admin...
powershell -Command "Start-Process -FilePath '%~dp0apps-manager.bat' -ArgumentList 'reconnect' -Verb RunAs"
exit /b
)
call "%~dp0apps-manager.bat" reconnect
endlocal
+31
View File
@@ -0,0 +1,31 @@
@echo off
setlocal EnableDelayedExpansion
:: BatchGotAdmin BEGIN https://sites.google.com/site/eneerge/home/BatchGotAdmin | https://ss64.com/nt/rem.html | https://ss64.com/nt/cacls.html
:: Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
:: If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%~dp0getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%~dp0getadmin.vbs"
"%~dp0getadmin.vbs"
exit /B
:gotAdmin
if exist "%~dp0getadmin.vbs" ( del "%~dp0getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0"
:: BatchGotAdmin END
cd /d "%~dp0\modules"
call init.bat
start call storage-connect.bat
start call mounts-connect.bat
+27
View File
@@ -0,0 +1,27 @@
@echo off
setlocal EnableDelayedExpansion
:: BatchGotAdmin BEGIN https://sites.google.com/site/eneerge/home/BatchGotAdmin | https://ss64.com/nt/rem.html | https://ss64.com/nt/cacls.html
:: Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
:: If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%~dp0getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%~dp0getadmin.vbs"
"%~dp0getadmin.vbs"
exit /B
:gotAdmin
if exist "%~dp0getadmin.vbs" ( del "%~dp0getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0"
:: BatchGotAdmin END
call "%~dp0apps-manager.bat" reconnect