Advertisement
marioq

ff_01.cmd

Jun 27th, 2022 (edited)
835
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 14.67 KB | None
  1. @echo off & set _TIME_start=%time%
  2. echo\
  3. REM echo   %date% %time%
  4. REM echo   %~sf0 1=(%1) 2=(%2) 3=(%3) 4=(%4) 5=(%5)
  5. REM :::: dal file start_01.cmd
  6. REM :::: call %_USEFULTOOLS% run_as_admin %_CMD_EXE% "%username% %_USEFULTOOLS%"
  7. REM echo\
  8. REM echo  drive=%~d0
  9. REM echo  full=%~f0
  10. REM echo  path=%~p0 - 1=(%1) - 2=(%2) - 3=(%3) - 4=(%4) - 5=(%5)
  11. REM echo  file=%~nx0 - 1=(%1) - 2=(%2) - 3=(%3) - 4=(%4) - 5=(%5)
  12.  
  13. cd %~d0
  14. set "_DRIVE=%~d0"& REM set _DRIVE
  15. set "_PATH=%~p0"& REM set _PATH
  16. set "_FILE=%~nx0"& REM set _FILE
  17. set "_PATHs=%~sp0"& REM set _PATHs
  18. set "_FILEs=%~snx0"& REM set _FILEs
  19. echo   0=%0 1=(%1) 2=(%2) 3=(%3) 4=(%4) 5=(%5)
  20. set "_USER_REFERRER=%1"
  21. set "_USEFULTOOLS=%2"
  22. set /a _ERROR=0
  23. if not defined _USEFULTOOLS echo   controlla %~0 & goto :END00
  24. if %_USEFULTOOLS%==%_DRIVE%%_PATH%myScripts\usefultools.cmd (
  25.     if not exist %_DRIVE%%_PATH%myScripts\usefultools.cmd (
  26.         echo\
  27.         echo   %~f0
  28.         echo   non esiste
  29.         echo   "%_DRIVE%%_PATH%myScripts\usefultools.cmd"
  30.         echo\
  31.         set /a _ERROR+=1
  32.         REM for /f "delims=^=" %%A in ('@set _') do @set "%%A="
  33.         goto :END00
  34.     )
  35. )
  36. :::: controllo se l'utente che esegue è Administrators
  37. call %_USEFULTOOLS% user_is_admin >nul
  38. if %errorlevel% GTR 0 (
  39.     echo\
  40.     echo   utente "%USERNAME%" gruppo locale "%my_USER_IS%"
  41.     echo   devi appartenete al gruppo locale "Administrators"
  42.     echo   per eseguire questo script "%~f0"
  43.     exit /b 127
  44.     )
  45. )
  46.  
  47. title %username% %date% %time% esegue %~f0 %1 %2 %3 %4 %5
  48. echo   %~f0 start %_TIME_start%
  49. echo   attendi....
  50. %_DRIVE%
  51. cd\
  52. :::: cd %_DRIVE%%_PATHs%
  53.  
  54.  
  55.  
  56. goto :START
  57.  
  58. call %_USEFULTOOLS% where_is_ff >nul
  59. :: visualizza la var da modificare
  60. set my_FIREFOX_PROFILES
  61.  
  62. REM echo %~sdpnx0
  63. REM echo %~f0
  64. REM echo %~sf0
  65. REM echo %~s0
  66. REM echo %~0
  67. REM echo %0 "%1"
  68. echo ---------
  69.  
  70. :: sostituisco %username% con il parametro passato
  71. call set my_FF_PROFILES=%%my_FIREFOX_PROFILES:%username%=%%
  72. call set my_FF_PROFILES=%%my_FF_PROFILES:\\=\%1\%%
  73. ::
  74. if exist "%my_FF_PROFILES%" echo my_FF_PROFILES=%my_FF_PROFILES%
  75.  
  76. :START
  77.  
  78. setlocal enabledelayedexpansion
  79. echo\&echo setlocal--------------
  80.  
  81. echo ###############################################
  82. echo ## imposto i server                          ##
  83. echo ## di sincronizzazione orario *.pool.ntp.org ##
  84. :::: https://www.ntppool.org/it/use.html
  85. w32tm /config /syncfromflags:manual /manualpeerlist:"0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org 3.pool.ntp.org" & set ERROR_add_ntp=%errorlevel%
  86. if %ERROR_add_ntp% EQU 0 (
  87.     echo ## [OK] w32tm /config... .. .  .   .   .
  88. ) else (
  89.     echo  ATTENZIONE VERIFICA LO SCRIPT w32tm /config... .. .  .   .    .
  90. )
  91. echo ######################################
  92.  
  93.  
  94. echo ######################################
  95. echo ## Modifico le variabili di sistema ##
  96. echo ## Path . .  .  . in questo script #=%%
  97. set "_REG_Q_PATH=reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v Path | findstr -i path"
  98. :::: racchiuso tra virgoletta altrimenti interpreta | come pipe
  99. REM echo ++@@@]"%_REG_Q_PATH%"[@@@++
  100. :: escape | per lavorare con for
  101. set "_REG_Q_PATH=%_REG_Q_PATH:|=^|%"
  102. REM echo --@@@]"%_REG_Q_PATH%"[@@@--
  103.  
  104. set "_Qa=%%"
  105. set "_Qb=^%%"
  106. for /f "tokens=1,2,3" %%G in ('%_REG_Q_PATH%') do (
  107.     set "my_R_Q_Key_Name=%%G"
  108.     set "my_R_Q_Key_Tipe=%%H"
  109.     set "my_R_Q_PATH=%%I"
  110. )
  111. :::: evito l'espansione delle var, sostituisco % con #
  112. set "my_R_Q_PATH=!my_R_Q_PATH:%_Qa%=#!"
  113. :::: controllo se il valore Path termina con ;
  114. :::: findstr exit con 0=trovato
  115. echo %my_R_Q_PATH%| findstr /R /C:"[;]$">nul & set ERROR_findstr=!errorlevel!
  116. if not %ERROR_findstr% EQU 0 (
  117.     set SEMICOLON_end=;
  118.     set "my_R_Q_PATH=%my_R_Q_PATH%!SEMICOLON_end!"
  119. )
  120.  
  121. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  122. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  123. :::: aggiungo a Path se non contiene %my_ADD_Path% ::::::::
  124. set "my_ADD_Path=#SystemRoot#\myscripts"
  125. set "my_ADD_Path=%my_ADD_Path% #SystemRoot#\myscripts\UnxUtils"
  126. set "my_ADD_Path=%my_ADD_Path% #SystemRoot#\myscripts\x64tools"
  127. set "my_ADD_Path=%my_ADD_Path% #SystemRoot#\myscripts\sysInternal"
  128.  
  129. call :HANDLE_args %my_ADD_Path%
  130. echo  ---- %Return_COUNT_arg% Argomenti gestiti.
  131. REM echo %my_R_Q_PATH%
  132. goto :WRITE_new_Path
  133.  
  134. :HANDLE_args
  135. if not [%0]==[:HANDLE_args] (
  136.     echo  ..Che fai qui??
  137.     echo  .. .  .  .esci.
  138.     exit /b 110
  139. )
  140. set /a Return_COUNT_arg = 0
  141. :HANDLE_for_args
  142. if [%1]==[] goto :EOF
  143.     for /f "tokens=1-31" %%A in ('echo %my_TOUCH%') do (
  144.         echo %my_R_Q_PATH%| findstr -i %1;>nul && set "%1=!errorlevel!"
  145.         if defined %1 echo   -- %1 [OK] presente in #Path#
  146.         if not defined %1 (
  147.             echo  [OK] add %1 in #Path#
  148.             set "my_R_Q_PATH=%my_R_Q_PATH%%1;"
  149.         )
  150.     )
  151. set /a Return_COUNT_arg += 1
  152. shift /1
  153. goto :HANDLE_for_args
  154.  
  155. echo  questo non devi vederlo
  156. echo  l'uscita é:
  157. echo    :HANDLE_for_args
  158. echo    if [%1]==[] goto :EOF
  159. endlocal
  160. exit /b
  161. :::: aggiungo a Path se non contiene %my_ADD_Path% FINE ::::
  162. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  163. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  164.  
  165. :WRITE_new_Path
  166. :::: sostituisco # con %
  167. set "my_R_Q_PATH=%my_R_Q_PATH:#=!_Qb!%"
  168.  
  169. reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v %my_R_Q_Key_Name% /t %my_R_Q_Key_Tipe% /d %my_R_Q_PATH% /f & set ERROR_reg_add_path=!errorlevel!
  170. if %ERROR_reg_add_path% EQU 0 (
  171.     echo  reg add error=%errorlevel% Path [OK]
  172. ) else (
  173.     echo  reg add error=%errorlevel%
  174.     echo  ATTENZIONE VERIFICA LO SCRIPT reg add Path
  175.     echo    %_DRIVE%%_PATHs%%_FILEs%
  176. )
  177. echo ###########################################
  178. :::: FINE modifica PATH ::::::::::::::::::::
  179. ::::::::::::::::::::::::::::::::::::::::::::
  180. ::::::::::::::::::::::::::::::::::::::::::::
  181.  
  182.  
  183. echo ###########################################
  184. echo #### aggiungo myScripts alle variabili ####
  185. echo #### di sistema                        ####
  186. reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v myScripts /t %my_R_Q_Key_Tipe% /d %%SystemRoot%%\myScripts /f & set ERROR_reg_add_myS=!errorlevel!
  187. if %ERROR_reg_add_myS% EQU 0 (
  188.     echo  reg add error=%errorlevel% myScripts [OK]
  189. ) else (
  190.     echo  reg add error=%errorlevel%
  191.     echo  ATTENZIONE VERIFICA LO SCRIPT reg add myScripts
  192.     echo    %_DRIVE%%_PATHs%%_FILEs%
  193. )
  194. echo ###########################################
  195.  
  196. echo ###########################################
  197. echo #### aggiungo APRI CMD QUI              ###
  198. echo #### ... .. .   .    .     .
  199. set ERROR_OK_ADM=
  200. dir /b %_DRIVE%%_PATH%myScripts\OK_ADM_*.reg >nul && set ERROR_OK_ADM=%errorlevel%
  201. if defined ERROR_OK_ADM (
  202.     for /f %%A in ('dir /b %_DRIVE%%_PATH%myScripts\OK_ADM_*.reg ^| sort') do (
  203.         echo  reg import %_DRIVE%%_PATH%myScripts\%%A
  204.         @reg import %_DRIVE%%_PATH%myScripts\%%A
  205.     )
  206.     REM for /f %%A in ('dir /b %_DRIVE%%_PATH%myScripts\OK_ADM_*.reg ^| sort') do @echo %_DRIVE%%_PATH%myScripts\%%A
  207. ) else (
  208.     echo\
  209.     echo    COntrolla lo script %~f0
  210.     echo\
  211. )
  212. echo ############################################
  213.  
  214. :::::::::::::::::::::::::::::::::::::::::::::::::::::::
  215. :::::::::::::::::::::::::::::::::::::::::::::::::::::::
  216. :::: Aggiunge rimuove esclusioni a MS DEFENDER ::::::::
  217. :::: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Defender\Exclusions\Paths
  218. :::: https://docs.microsoft.com/en-us/powershell/module/defender/remove-mppreference?view=windowsserver2022-ps
  219. :HANDLE_DEFENDER
  220. if not [%0]==[:HANDLE_DEFENDER] (
  221.     goto :HANDLE_DEFENDER_END
  222.     echo  ..Che fai qui??
  223.     echo  .. .  .  .esci.
  224.     exit /b 110
  225. )
  226. if .%1==.add (
  227.     set "pwsh_exeA_R=powershell %1-MpPreference -ExclusionPath"
  228.     shift /1
  229.     echo ###########################################
  230.     echo ###### Aggiungo esclusioni a            ###
  231.     echo ###### MS DEFENDER                      ###
  232. )
  233. if .%1==.remove (
  234.     set "pwsh_exeA_R=powershell %1-MpPreference -ExclusionPath"
  235.     shift /1
  236.     echo ###########################################
  237.     echo ###### Rimuovo esclusioni a             ###
  238.     echo ###### MS DEFENDER                      ###
  239. )
  240. set /a Return_COUNT_DEFENDER_PATH = 0
  241.  
  242. :HANDLE_DEFENDER_for
  243. if .%1==. goto :EOF
  244.     set /a Return_COUNT_DEFENDER_PATH += 1
  245.     set "pwsh_exe=%pwsh_exeA_R% "%1" -Force">nul
  246.     echo   %Return_COUNT_DEFENDER_PATH% %pwsh_exe%
  247.     %pwsh_exe%
  248.     REM powershell senza una funzione ritorna sempre errolevel 0
  249.     REM echo error=%errorlevel%
  250. shift /1
  251. goto :HANDLE_DEFENDER_for
  252.  
  253. echo  questo non devi vederlo
  254. echo  l'uscita é:
  255. echo    :HANDLE_DEFENDER_for
  256. echo    if .%1==. goto :EOF
  257. endlocal
  258. exit /b
  259. :HANDLE_DEFENDER_END
  260. :::: Aggiunge rimuove esclusioni a MS DEFENDER FINE :::::::
  261. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  262. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  263.  
  264.  
  265. :::: MS DEFENDER MY_PATH ::::::::::::::::::::::::::::::::::
  266. set "my_DEFENDER_PATH=%SystemRoot%\myscripts"
  267. set "my_DEFENDER_PATH=%my_DEFENDER_PATH% %SystemRoot%\myscripts\x64tools"
  268. set "my_DEFENDER_PATH=%my_DEFENDER_PATH% %SystemRoot%\myscripts\UnxUtils"
  269. set "my_DEFENDER_PATH=%my_DEFENDER_PATH% %SystemRoot%\myscripts\sysinternal"
  270. set "my_DEFENDER_PATH=%my_DEFENDER_PATH% %_DRIVE%\\"
  271. set "my_DEFENDER_PATH=%my_DEFENDER_PATH% %_DRIVE%\%_PATHs:\=%"
  272. set "my_DEFENDER_PATH=%my_DEFENDER_PATH% %_DRIVE%%_PATHs%myscripts\x64tools"
  273. set "my_DEFENDER_PATH=%my_DEFENDER_PATH% %_DRIVE%%_PATHs%myscripts\UnxUtils"
  274. set "my_DEFENDER_PATH=%my_DEFENDER_PATH% %_DRIVE%%_PATHs%myscripts\sysinternal"
  275.  
  276. call :HANDLE_DEFENDER add %my_DEFENDER_PATH%
  277. echo  ---- %Return_COUNT_DEFENDER_PATH% Argomenti gestiti.
  278.  
  279.  
  280. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  281. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  282. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  283. ::::   ROBOCOPY
  284. :ROBO
  285. if not [%0]==[:ROBO] goto :ROBO_END
  286.  
  287. where robocopy.exe >nul 2>&1
  288. if %errorlevel% NEQ 0 (
  289.     echo\
  290.     echo ###################
  291.     echo ###################
  292.     echo   non c'é robocopy
  293.     echo ###################
  294.     echo ###################
  295.     echo\
  296.     goto :ROBO_END
  297. )
  298.  
  299. if [%1]==[FROM_DRIVE_TO_MYSCRIPTS] (
  300.     if not exist %windir%\myScripts mkdir %windir%\myScripts
  301.     set "ROBO_EXE=robocopy.exe %_DRIVE%%_PATH%myScripts %windir%\myScripts /mir /fp /COPYALL"
  302. )
  303.  
  304. if [%1]==[FROM_MYSCRIPTS_TO_DRIVE] (
  305.     if not exist %_DRIVE%%_PATH%myScripts mkdir %_DRIVE%%_PATH%myScripts
  306.     set "ROBO_EXE=robocopy.exe %windir%\myScripts %_DRIVE%%_PATH%myScripts /mir /fp /COPYALL"
  307. )
  308.  
  309. echo ###############################################
  310. echo ## robocopy  %1
  311. echo\
  312. :::: https://ss64.com/nt/robocopy-exit.html
  313. echo  call %ROBO_EXE%
  314. :::: call %ROBO_EXE% >nul
  315. call %ROBO_EXE%
  316.     if %ERRORLEVEL% EQU 16 echo   %ERRORLEVEL% ***FATAL ERROR*** & goto end
  317.     if %ERRORLEVEL% EQU 15 echo   %ERRORLEVEL% OKCOPY + FAIL + MISMATCHES + XTRA & goto end
  318.     if %ERRORLEVEL% EQU 14 echo   %ERRORLEVEL% FAIL + MISMATCHES + XTRA & goto end
  319.     if %ERRORLEVEL% EQU 13 echo   %ERRORLEVEL% OKCOPY + FAIL + MISMATCHES & goto end
  320.     if %ERRORLEVEL% EQU 12 echo   %ERRORLEVEL% FAIL + MISMATCHES& goto end
  321.     if %ERRORLEVEL% EQU 11 echo   %ERRORLEVEL% OKCOPY + FAIL + XTRA & goto end
  322.     if %ERRORLEVEL% EQU 10 echo   %ERRORLEVEL% FAIL + XTRA & goto end
  323.     if %ERRORLEVEL% EQU 9 echo   %ERRORLEVEL% OKCOPY + FAIL & goto end
  324.     if %ERRORLEVEL% EQU 8 echo   %ERRORLEVEL% FAIL & goto end
  325.     if %ERRORLEVEL% EQU 7 echo   %ERRORLEVEL% OKCOPY + MISMATCHES + XTRA & goto end
  326.     if %ERRORLEVEL% EQU 6 echo   %ERRORLEVEL% MISMATCHES + XTRA & goto end
  327.     if %ERRORLEVEL% EQU 5 echo   %ERRORLEVEL% OKCOPY + MISMATCHES & goto end
  328.     if %ERRORLEVEL% EQU 4 echo   %ERRORLEVEL% MISMATCHES & goto end
  329.     if %ERRORLEVEL% EQU 3 echo   %ERRORLEVEL% OKCOPY + XTRA & goto end
  330.     if %ERRORLEVEL% EQU 2 echo   %ERRORLEVEL% XTRA & goto end
  331.     if %ERRORLEVEL% EQU 1 echo   %ERRORLEVEL% OKCOPY & goto end
  332.     if %ERRORLEVEL% EQU 0 echo   %ERRORLEVEL% No Change & goto end
  333.     :end
  334.  
  335. if [%0]==[:ROBO] goto :EOF
  336.  
  337. :ROBO_END
  338. :::::::::           ROBOCOPY END                    ::::::::::::
  339. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  340. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  341. echo\
  342. echo ###############################################
  343. echo ## ROBOCOPY ###################################
  344. REM call :ROBO FROM_MYSCRIPTS_TO_DRIVE
  345. call :ROBO FROM_DRIVE_TO_MYSCRIPTS
  346. echo\
  347. echo ###############################################
  348.  
  349. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  350. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  351. ::::  SCHEDULE ogni ora                                      ::::
  352. echo ###############################################
  353. echo ###############################################
  354. echo ## AGGIUNGO OPERAZIONE PIANIFICATA OGNI ORA  ##
  355. echo\
  356. set "SCHEDULE_Q_ERROR="
  357. schtasks /query /tn "MY_SCHEDULE\OGNI_ORA" >nul 2>&1 && set SCHEDULE_Q_ERROR=%errorlevel%
  358. if defined SCHEDULE_Q_ERROR (
  359.     echo\
  360.     echo   la vecchia programmazione "MY_SCHEDULE\OGNI_ORA"
  361.     echo   viene sostituita
  362.     echo   schtasks /delete /tn "MY_SCHEDULE\OGNI_ORA" /f
  363.     schtasks /delete /tn "MY_SCHEDULE\OGNI_ORA" /f >nul 2>&1
  364.     echo\
  365. )
  366. echo   nuova programmazione "MY_SCHEDULE\OGNI_ORA"
  367. echo   schtasks /create /XML "%windir%\myScripts\ogni_ora.xml" /TN "MY_SCHEDULE\OGNI_ORA"
  368. schtasks /Create /XML "%windir%\myScripts\ogni_ora.xml" /TN "MY_SCHEDULE\OGNI_ORA" >nul 2>&1
  369. if %errorlevel% GTR 0 (
  370.     echo\
  371.     echo   ERRORE OPERAZIONE PIANIFICATA OGNI ORA
  372.     echo   controlla lo script %~f0
  373.     echo\
  374. ) else (
  375.     echo\
  376.     echo   OPERAZIONE PIANIFICATA OGNI ORA "OK"
  377. )
  378. echo\
  379. echo   supporto per themetools
  380. echo   copy /y "%windir%\myScripts\ok-theme.theme" "%windir%\Resources\Themes\ok-theme.theme"
  381. copy /y "%windir%\myScripts\ok-theme.theme" "%windir%\Resources\Themes\ok-theme.theme"
  382. echo ##############################################
  383. ::::  SCHEDULE ogni ora       FINE                           ::::
  384. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  385. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  386.  
  387.  
  388.  
  389. set my_DEFENDER_PATH=
  390. set "my_DEFENDER_PATH=%_DRIVE%\\"
  391. set "my_DEFENDER_PATH=%my_DEFENDER_PATH% %_DRIVE%\%_PATHs:\=%"
  392. set "my_DEFENDER_PATH=%my_DEFENDER_PATH% %_DRIVE%%_PATHs%myscripts\x64tools"
  393. set "my_DEFENDER_PATH=%my_DEFENDER_PATH% %_DRIVE%%_PATHs%myscripts\UnxUtils"
  394. set "my_DEFENDER_PATH=%my_DEFENDER_PATH% %_DRIVE%%_PATHs%myscripts\sysInternal"
  395.  
  396. REM call :HANDLE_DEFENDER remove %my_DEFENDER_PATH%
  397. REM echo  ---- %Return_COUNT_DEFENDER_PATH% Argomenti gestiti.
  398.  
  399. echo\
  400. endlocal&(
  401. echo endlocal---------------
  402. echo\
  403. )
  404.  
  405.  
  406.  
  407.  
  408.  
  409. :END00
  410. echo  %~0 start %_TIME_start%
  411. echo  %~f0   end %time%
  412. REM echo  %~0 - 1=(%1) - 2=(%2) - 3=(%3) - 4=(%4) - 5=(%5)
  413. echo  _USER_REFERRER=%_USER_REFERRER%
  414. echo  _USEFULTOOLS=%_USEFULTOOLS%
  415. echo  _DRIVE=%_DRIVE%  _PATHs=%_PATHs%  _FILEs=%_FILEs%
  416. exit /b %_ERROR%
  417.  
  418. for /f "delims=^=" %%A in ('@set my_') do set "%%A="
  419. for /f "delims=^=" %%A in ('@set _') do set "%%A="
  420.  
Advertisement
RAW Paste Data Copied
Advertisement