@echo off
setlocal
:::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::"23/9/2025"~"martedì-23/settembre/2025 10:11:47"
:::::::::::::::::::::::::::::::::::::::::::::::::::
:::: queste variabili sono passate alle funzioni con "setlocal enabledelayedexpansion"
:::: dopo l'etichetta :STRLEN_ck_end
::::
::##_start_CK_online i primi 20 caratteri "::##_start_CK_online" sono un marcatore
:::: le righe di comando qui sotto vengono lette da curl per il controllo nella funzione :CK_ver
:::: "INFO_ver_date=dd/MM/yyyy"
set "INFO_ver_date=31/08/2025"
:::: "INFO_ver_time=HH:mm:s"
set "INFO_ver_time=09:09:59"
:::: le righe qui sopra vengono lette da curl per il controllo nella funzione :CK_ver
::##::_end_CK_online i primi 20 caratteri "::##::_end_CK_online" sono un marcatore
set "INFO_ver_date_yyyy=%INFO_ver_date:~-4%" & REM INFO_ver_date_yyyy==2025
set "INFO_ver_date_MMdd=%INFO_ver_date:~3,-5%%INFO_ver_date:~0,2%" & REM INFO_ver_date_MMdd==0831
set "INFO_ver_date_4_ck=%INFO_ver_date:~-4%%INFO_ver_date:~3,-5%%INFO_ver_date:~0,2%" & REM yyyyMMdd
set INFO_ver_time_4_ck=%INFO_ver_time::=%
if "%INFO_ver_time_4_ck:~0,1%" == "0" (
set "INFO_ver_time_4_ck=%INFO_ver_time_4_ck:~1,1000%"
)
if "%INFO_ver_time_4_ck:~0,1%" == " " (
set "INFO_ver_time_4_ck=%INFO_ver_time_4_ck: =%"
)
echo INFO_ver_date=%INFO_ver_date%
echo INFO_ver_date_4_ck=%INFO_ver_date_4_ck%
echo INFO_ver_time_4_ck=%INFO_ver_time_4_ck%
REM goto :EOF
REM set "INFO_ver_date_serial=%INFO_ver_date:/=%"
REM set "INFO_ver_date_serial=%INFO_ver_date_serial: =%"
REM set "INFO_ver_date_serial=%INFO_ver_date_serial::=%"
for /f "tokens=1,2 delims=:" %%A in ('chcp') do (
set "CHCP_OLD=%%B"
)
::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
chcp 65001 >nul
::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: caratteri speciali > < | & )( ! " ^ sono interpretati
:::: in modo speciale da "setlocal enabledelayedexpansion"
:::: per lavorare con STRLEN trasformo i caratteri speciali
:::: in caratteri innocui a "setlocal enabledelayedexpansion"
::::
:::: limite della riga di comando
:::: https://learn.microsoft.com/it-IT/troubleshoot/windows-client/shell-experience/command-line-string-limitation
if /i "%1" == "strlen" (
set "STRLEN=%1"
)
if not defined STRLEN (
goto :STRLEN_ck_end
)
set "STR_4_strlen="%*""
::::::::::::::::::::::::
:::: REM ASCI 161 ¡ -The extended ASCII codes,Inverted exclamation mark- https://www.ascii-code.com/ - https://ss64.com/ascii.html
set "STR_4_strlen=%STR_4_strlen:!=¿%" & REM alt+0191==¿
set "STR_4_strlen=%STR_4_strlen:>=¿%"
set "STR_4_strlen=%STR_4_strlen:<=¿%"
set "STR_4_strlen=%STR_4_strlen:|=¿%"
set "STR_4_strlen=%STR_4_strlen:&=¿%"
REM set "STR_4_strlen=%STR_4_strlen:"=¶%" & REM alt+0182==¶
set "STR_4_strlen=%STR_4_strlen:"=•%" & REM alt+0149==•
set "STR_4_strlen=%STR_4_strlen:^=¿%"
set "STR_4_strlen=%STR_4_strlen:(=¿%"
set "STR_4_strlen=%STR_4_strlen:)=¿%"
::::::::::::::::::::::::
REM set "STR_quote=¶" & REM alt+0182==¶
set "STR_quote=•" & REM alt+0149==•
set "STR_quote_L=„‡»" & REM alt+0132==„ alt+0135==‡ alt+187==»
set "STR_quote_R=«‡„" & REM alt+0171==« alt+0135==‡ alt+0132==„
REM set "STR_quote_L=؇»" & REM alt+0216==Ø alt+0135==‡ alt+187==»
REM set "STR_quote_R=«‡Ø" & REM alt+0171==« alt+0135==‡ alt+0216==Ø
REM set "STR_quote_L=.‡»" & REM alt+0135==‡ alt+187==»
REM set "STR_quote_R=«‡." & REM alt+0171==« alt+0135==‡
REM set "STR_dummy=¿" „
set "STR_4_strlen=%STR_quote_L%%STR_4_strlen%%STR_quote_R%"
REM echo\00000000 STR_4_strlen==%STR_4_strlen%
:::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::
::::REM set "Q="!"" & call :STR_set_dummy "%Q%"
::::REM set "Q=">"" & call :STR_set_dummy "%Q%"
::::REM set "Q="<"" & call :STR_set_dummy "%Q%"
::::REM set "Q="|"" & call :STR_set_dummy "%Q%"
::::REM set "Q="&"" & call :STR_set_dummy "%Q%"
::::REM set "Q=")"" & call :STR_set_dummy "%Q%"
::::REM set "Q="("" & call :STR_set_dummy "%Q%"
::::REM set "Q="^^"" & call :STR_set_dummy "%Q%"
::::REM set "STR_4_strlen=%STR_4_strlen:"=•%"
::::REM REM call :STR_set_dummy "^"
::::
::::REM :STR_set_dummy
::::REM if not "%0" == ":STR_set_dummy" goto :STR_set_dummy_end
:::: REM REM set "Q=%~1"
:::: REM echo\ "Q==%Q~%"
:::: REM set "STR_4_strlen=%STR_4_strlen:%%Q~%%=%%STR_dummy%%"
:::: REM call set Q=
::::REM goto :EOF
::::REM :STR_set_dummy_end
::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::
REM echo\\\\\\\\\\01 error==%errorlevel%
REM echo\\\\\\\\\\STR_4_strlen==%STR_4_strlen%
:::::::::::::::::::::::
:STRLEN_ck_end
if not defined STR_4_strlen goto :STRLEN_no
(
endlocal
setlocal enabledelayedexpansion
set "STRLEN=%STRLEN%"
set "STR_quote=%STR_quote%"
set "STR_quote_L=%STR_quote_L%"
set "STR_quote_R=%STR_quote_R%"
set "STR_4_strlen=%STR_4_strlen%"
set "my_STR_length="
set "CHCP_OLD=%CHCP_OLD%"
set "INFO_ver_date=%INFO_ver_date%"
set "INFO_ver_time=%INFO_ver_time%"
)
goto :STRLEN_NEXT_start
:STRLEN_no
(
endlocal
setlocal enabledelayedexpansion
set "CHCP_OLD=%CHCP_OLD%"
set "INFO_ver_date=%INFO_ver_date%"
set "INFO_ver_time=%INFO_ver_time%"
)
:STRLEN_NEXT_start
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: imposto un titolo alla finestrta in modo da poterla riconoscere
set "THIS_RANDOM=%random%"
title %~n0-%THIS_RANDOM% %username% "%cd%"
set N=
for /f "tokens=1,2,3" %%A in ('tasklist /NH /FI "WINDOWTITLE eq %~n0-%%THIS_RANDOM%% %%username%%*"') do (
set /a N+=1
if !N! EQU 1 (
set "B=%%B"
echo\!B! | findstr /r /c:"^[0-9][0-9]*.$" >nul 2>&1
if !errorlevel! EQU 0 (
set "THIS_file_pid=!B!"
REM echo\QQQ "THIS_file_pid==!THIS_file_pid! A==%%A - B==!B! pid==!THIS_file_pid! - C==%%C "
) else (
set "THIS_file_pid=%THIS_RANDOM:~2,-2%%date:/=% "
REM set "THIS_file_pid=%THIS_RANDOM:~0,2%dummy%date:/=%"
REM echo\WWW "THIS_file_pid==!THIS_file_pid! A==%%A - B==!B! pid==!THIS_file_pid! - C==%%C"
)
)
)
set N=
title %~n0-%THIS_file_pid%-%THIS_RANDOM% %username% "%cd%" & REM per identificare la consolle cmd
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set "THIS_file=%~nx0"
set "THIS_file=%THIS_file:"=%"
set "THIS_file_size=%~z0"
set "THIS_file_date=%~t0"
:::: se "THIS_file_size" è definita, il valore di "%~dp0" è il percorso reale del file.
:::: se "THIS_file_size" non è definita, il valore di "%~dp0" è il percorco della directory al prompt che invoca lo script.
:::: -|Strano comportamento, se "%THIS_file%" è in un percorso in "path" e viene invocato il nome tra vergolette "nomeFile.cmd"
:::: -|"%~dp0" prende il valore della directory corrente e non della dir che contiene il "nomeFile.cmd"
:::: -|"THIS_file_size=%~z0" e "THIS_file_date=%~t0" sono valorizzate se "%~dp0" è il percorso reale a "nomeFile.cmd"
:::: if not [%cd%\]==[%~dp0] set "THIS_file_path=%~dp0"
if defined THIS_file_size set "THIS_file_path=%~dp0"
set "THIS_file_full_path=%THIS_file_path%%THIS_file%"
REM echo\-----------"cd=%cd%" "~dp0=%~dp0"
REM echo\-----------"THIS_file=%THIS_file%"
REM echo\-----------"THIS_file_path=%THIS_file_path%"
REM echo\-----------"THIS_file_size=%THIS_file_size%"
REM echo\-----------"THIS_file_date=%THIS_file_date%"
REM echo\-----------"THIS_file_full_path=%THIS_file_path%%THIS_file%"
REM echo\----------- 0=%0 0~=%~0 p=%~p0
set "ALL_0arg="%*""
set "TIME_start=%time%"
set "ERROR="
::::::::::::
:::: set "ESC=" & REM notepad++ "alt+27"
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do ( set "ESC=%%b" )
set "C_RED=%ESC%^[91m" & REM Testo Rosso
set "C__=%ESC%^[4m" & REM Sottolineato
set "C_0=%ESC%^[0m" & REM Reset color
:::::::::::
set "RESET_all_var=for /f "delims=^=" %%Z in ^('@set my_'^) do @set "%%Z=" "
:::: Il carattere § viene sostituito da %LF% "echo %MSG:§=!LF!%"
set "MSG=-visualizza con ^"set my_^" §-resetta, elimina tutte le var ^"my_^" §* %RESET_all_var% §- exit %%errorlevel%% EQU-Uguale 0 -successo- §- exit %%errorlevel%% GEQ-Maggiore o uguale a 1 -errore-"
::::::::::
:::: imposto Line-Fedd
:::: dopo LF=^ 2 righe vuote da non eliminare
set LF=^
:::::::::::::::::: 2 righe vuote da non eliminare
if exist "%THIS_file_path%UnxUtils\tr.exe" (
set "TR_exe=%THIS_file_path%UnxUtils\tr.exe"
)
if exist "%THIS_file_path%cmdow.exe" (
set "CMDOW_exe=%THIS_file_path%cmdow.exe"
)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if "%1"=="" (
set "ERROR_start=Manca il parametro corretto"
call :HEADER
call :SOS_all
call :FOOTER
)
if /i "%1"=="CK_ver" (
call :HEADER
goto :%~1
)
:::::::::::::::::::
if /i "%1"=="my_ip4" (
call :HEADER
goto :%~1
)
if /i "%1"=="ip4" (
call :HEADER
goto :my_ip4
)
:::::::::::::::::::
if /i "%1"=="where_is_ff" (
call :HEADER
goto :%~1
)
if /i "%1"=="my_date" (
call :HEADER
goto :%~1
)
if /i "%1"=="geoip" (
call :HEADER
goto :%~1
)
if /i "%1"=="user_is_admin" (
call :HEADER
goto :%~1
)
if /i "%1"=="run_as_admin" (
call :HEADER
goto :%~1
)
if /i "%1"=="NIC" (
call :HEADER
goto :%~1
)
if /i "%1"=="strlen" (
call :HEADER
goto :%~1
)
if /i "%1"=="-h" set "SOS=-h"
if /i "%1"=="/h" set "SOS=/h"
if /i "%1"=="h" set "SOS=h"
if /i "%1"=="/?" set "SOS=/?"
if /i "%1"=="-?" set "SOS=-?"
if /i "%1"=="?" set "SOS=^?"
if /i "%1"=="help" set "SOS=help"
if defined SOS (
set "H_P2=%~2"
call :HEADER
if defined H_P2 (
for /f "tokens=*" %%A in ( 'findstr /r /x /c:"^[:][A-Z_0-9].*_sos$" "%THIS_file_full_path%"' ) do (
set "X=%%A"
set "X=!X::=!"
set "X=!X:_sos=!"
if /i "!X!"=="!H_P2!" (
set "ALL_0arg=%1 !H_P2!"
set "ERROR_help=sos per "!H_P2!""
if !X!§==RUN_AS_ADMIN§ set Xopt=NO_CMDOW_exe
call %%A !X! !Xopt!
echo\::------
echo\::%MSG:§=!LF!::%
call :FOOTER
exit /b %ERROR%
)
)
if /i "!H_P2!"=="all" (
set "ERROR_help=sos per "!H_P2!"..."
for /f "tokens=*" %%A in ( 'findstr /r /x /c:"^[:][A-Z_0-9].*_sos$" "%THIS_file_full_path%"' ) do (
set "ALL_0arg=%1 !H_P2!"
set "X=%%A"
set "X=!X::=!"
set "X=!X:_sos=!"
call %%A !X!
echo\::^|-----------------
echo\::------------------
)
echo\::%MSG:§=!LF!::%
call :FOOTER
exit /b %ERROR%
)
)
if not defined H_P2 (
REM set "ERROR_parametro_-h="%1" richiede valore"
set "ERROR_parametro_%SOS%="%1" richiede valore"
echo\::* %THIS_file% %1
echo\:: -richiede parametro... .. .
for /f "tokens=*" %%A in ( 'findstr /r /x /c:"^[:][A-Z_0-9].*_sos$" "%THIS_file_full_path%"' ) do (
set "X=%%A"
set "X=!X::=!"
set "X=!X:_sos=!"
echo\:: !X!
)
call :FOOTER
exit /b %ERROR%
)
if not "!H_P2!"=="" (
set "ERROR_parametro_%SOS%=^"!H_P2!^" non valido^"
echo\::* %THIS_file% %1 !H_P2!
echo\:: PARAMETRO "!H_P2!" non valido
set N=
for /f "tokens=*" %%A in ( 'findstr /r /x /c:"^[:][A-Z_0-9].*_sos$" "%THIS_file_full_path%" ^| sort' ) do (
set /a N+=1
set "X=%%A"
set "X=!X::=!"
set "X=!X:_sos=!"
if !N! EQU 1 (
echo\:: prova %1 !X!
) else (
echo\:: %1 !X!
)
)
set N=
call :FOOTER
exit /b %ERROR%
)
)
if not "%1"=="" (
set "ERROR_parametro=Parametro "%~1" non valido "
call :HEADER
call :SOS_all
call :FOOTER
exit /b %ERROR%
)
::::
::::
::::
goto :EOF
:START
REM :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM ::::::::::: modello per nuove funzioni ::::::::::::::::::::::::::::::::
REM :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM :::::::::::::: my_function ::::::::::::::::::::::::::::::::::::::::::::::
REM :::::::::::::: my_function ::::::::::::::::::::::::::::::::::::::::::::::
REM goto :function_end
REM :function
REM :FUNCTION_sos
REM if not "%~0"==":FUNCTION_sos" goto :function_sos_end
REM echo\::* %THIS_file% %C__%%~1%C_0% .
REM echo\:: la funzione di sos deve iniziare con "^[:][A-Z0-9]*[_].*"
REM echo\:: deve finire con ".*_sos$"
REM echo\:: scrivi qui sos per my_function
REM echo\::
REM echo\::
REM echo\::
REM echo\::
REM exit /b %ERROR%
REM :function_sos_end
REM echo scrivi qui lo script da eseguire
REM echo scrivi qui lo script da eseguire
REM echo scrivi qui lo script da eseguire
REM if "%qualche errore per uscire%"=="qualche errore per uscire" (
REM set "ERROR_brevissima_descrizione=spiegazione estesa ma concisa"
REM echo\::
REM echo\:: ERRORE bla bla bla
REM echo\::
REM call :FOOTER
REM exit /b %ERROR%
REM )
REM echo\::::::::::::::::::::::::::::::::::::::::
REM echo\::%MSG:§=!LF!::%
REM call :FOOTER
REM (
REM endlocal
REM set "my_VAR_00=%VALORE00_da restituire%"
REM set "my_VAR_01=%VALORE01_da restituire%"
REM exit /b %ERROR%
REM )
REM :function_end
REM :::::::::::::: function end ::::::::::::::::::::::::::::::::::::::::::
REM :::::::::::::: function end ::::::::::::::::::::::::::::::::::::::::::
REM :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM ::::::::::: fine modello per nuove funzioni :::::::::::::::::::::::::::
REM :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM :::::::::::::: CK_ver ::::::::::::::::::::::::::::::::::::::::::::::
REM :::::::::::::: CK_ver ::::::::::::::::::::::::::::::::::::::::::::::
goto :CK_ver_end
:CK_ver
:CK_ver_sos
if not "%~0"==":CK_ver_sos" goto :CK_ver_sos_end
echo\::* %THIS_file% %C__%%~1%C_0% .
echo\::
echo\:: controlla la versione attuale
echo\:: * %THIS_file_full_path% %INFO_ver_date%
echo\:: con la versione on line
echo\:: * "https://codeberg.org/marioq59/win_cmd/src/branch/main/usefulTools.cmd"
echo\::
echo\:: la funzione di sos deve iniziare con "^[:][A-Z0-9]*[_].*"
echo\:: deve finire con ".*_sos$"
echo\:: scrivi qui sos per my_function
echo\::
echo\::
exit /b %ERROR%
:CK_ver_sos_end
REM set "CAT_this=type C:\Users\PARETO-User\myScripts\usefultools.cmd"
set "URL4curl=https://codeberg.org/marioq59/win_cmd/raw/branch/main/usefulTools.cmd"
set "CAT_this=curl.exe -f -s -S -k -L -B -R --retry 1 -A "%THIS_file:~0,-4%-%THIS_file_pid%" %URL4curl%"
set "PING_this_2=gnu.org"
set "PING_this_1=codeberg.org"
set "PING_this_1=127.0.0.1"
if "%CAT_this:~0,4%"=="type" set "PING_this=127.0.0.1"
if "%CAT_this:~0,4%"=="curl" set "PING_this=%PING_this_1%"
REM ping -a -n 1 %PING_this% | findstr /i /r /c:".*[[][0-9:].*" >nul
REM for /f "tokens=1,2 delims=^=" %%A in ( 'set PING_this_' ) do (
REM ping -a -n 1 %%B >nul
REM if !errorlevel! GTR 0 (
REM set "ERROR_geoip_no_internet=connessione a internet non disponibile"
REM set "NO_PING_this=%%B"
REM )
REM if !errorlevel! EQU 0 (
REM set "ERROR_geoip_no_internet="
REM set "NO_PING_this="
REM )
REM if defined ERROR_geoip_no_internet (
REM ping -a -n 1 %%B >nul
REM if !errorlevel! GTR 0 (
REM set "ERROR_geoip_no_internet=connessione a internet non disponibile"
REM set "NO_PING_this=%%B"
REM )
REM )
REM )
REM if defined NO_PING_this (
REM echo\::
REM echo\:: connessione a internet non disponibile
REM echo\:: [ping -a -n 1 %NO_PING_this%] senza risposta
REM echo\::
REM call :FOOTER
REM exit /b %ERROR%
REM )
REM ping -a -n 1 -f %PING_this% >nul
ping -a -n 1 -l 8 -f -w 128 %PING_this% >nul
if %errorlevel% GTR 0 (
set "ERROR_ck_ver_no_internet=connessione a internet non disponibile"
echo\::
echo\:: connessione internet a "%PING_this%" non disponibile
echo\:: [ping -a -n 2 -l 8 -f -w 128 %PING_this%] senza risposta
echo\::
call :FOOTER
exit /b %ERROR%
)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM echo\:: %CAT_this%
set "THIS_file.online=%temp%\%THIS_file%.online"
REM set "THIS_file.online=C:\Users\sysop\AppData\Local\Temp\%THIS_file%.online"
( echo. >"%THIS_file.online%" 2>&1 ) 2>nul & REM a schermo non visualizza l'errore
if not exist "%THIS_file.online%" (
set "ERROR_ck_ver_del=errore nel gestire "%THIS_file.online%""
echo\::
echo\:: non posso scrivere "%THIS_file.online%"
echo\:: File richiesto per %THIS_file_full_path% %1
echo\::
call :FOOTER
exit /b %ERROR%
)
%CAT_this% >%THIS_file.online% 2>&1
REM %CAT_this% >nul 2>&1
set CURL_error=%errorlevel%
if "%CURL_error%" NEQ "0" (
echo\::
echo\:: %CAT_this%
echo\::
set "CAT_this=!CAT_this! 2^>^&1"
set N=0
set "N_txt="
for /f "tokens=* delims=" %%Z in ( '!CAT_this!' ) do (
REM echo\\\\Z==%%Z
set /a N+=1
set "N_txt=%%Z"
echo\:: exit error !CURL_error! "!N_txt!"
)
echo\::
if exist "%THIS_file.online%" del /q "%THIS_file.online%"
if not exist "%THIS_file.online%" set ERROR_ck_ver_del=errore nel gestire "%THIS_file.online%"
set "ERROR_CURL_ck=!CURL_error! !N_txt!"
call :FOOTER
exit /b %ERROR%
)
if "%CURL_error%" EQU "0" (
set N=0
set N_txt=
set CK_ok=
echo\::
echo\:: %CAT_this%
echo\::
for /f "tokens=* delims=" %%Q in ( '%CAT_this%' ) do (
set /a N+=1
set "N_txt=%%Q"
REM 20 caratteri "::##_start_CK_online"
if "!N_txt:~0,20!"=="::##_start_CK_online" ( REM "::##_start_CK_online" marcatore
set /a CK_ok+=1
)
if !CK_ok! EQU 1 (
set "VAR_dummy="
if not "!N_txt:~0,2!"=="::" (
REM echo\#----------!N! !N_txt!
set "VAR_dummy=!N_txt:set =!"
set "VAR_dummy=!VAR_dummy:"=!"
echo\"VAR_dummy=!VAR_dummy!"
for /f "usebackq tokens=1,2 delims=^=" %%G in ( '!VAR_dummy!' ) do (
echo\\#\#\#\#\ G=%%G H=%%H
set "_%THIS_file:~0,-4%_date_online=%%H"
)
set "VAR_dummy="
REM echo\#----------!N! !N_txt!
set VAR_dummy=!N_txt: =!
set VAR_dummy=!VAR_dummy:"=!
set VAR_dummy=!VAR_dummy:set=!
set VAR_dummy=!VAR_dummy:/=!
set VAR_dummy=!VAR_dummy::=!
REM echo\@----------!N! !N_txt!
for /f "tokens=1,2 delims=^=" %%A in ( 'echo\!VAR_dummy!' ) do (
set "_%THIS_file:~0,-4%_date_serial_online=%%B"
)
)
)
REM 20 caratteri "::##::_end_CK_online"
if "!N_txt:~0,20!"=="::##::_end_CK_online" ( REM "::##::_end_CK_online" marcatore
set "CK_ok=0"
)
)
)
echo\:: set _%THIS_file:~0,-4%_date_
set _%THIS_file:~0,-4%_date_
echo\:: set INFO_ver_date
set INFO_ver_date
for /f "tokens=1,2 delims=^=" %%R in ( 'set INFO_ver_date' ) do (
set "R=%%R"
set "S=%%S"
REM echo\ "R==!R!" "S==!S!"
if "!R!"=="INFO_ver_date" set "_%THIS_file:~0,-4%_date=!S!"
if "!R!"=="INFO_ver_date_serial" set "_%THIS_file:~0,-4%_date_serial=!S!"
)
REM set /a INFO_ver_date_serial-=10
REM set /a _%THIS_file:~0,-4%_date_serial+=10
set /a _%THIS_file:~0,-4%_date_serial-=10
echo\\\\\\--------!_%THIS_file:~0,-4%_date_serial!
echo\\\\\\--------!_%THIS_file:~0,-4%_date_serial_online!
echo\############# set _%THIS_file:~0,-4%
set _%THIS_file:~0,-4%
if !_%THIS_file:~0,-4%_date_serial! EQU !_%THIS_file:~0,-4%_date_serial_online! (
echo\::
echo\::___________versioni uguali
echo\::
)
if !_%THIS_file:~0,-4%_date_serial! LSS !_%THIS_file:~0,-4%_date_serial_online! (
echo\::
echo\::___________la versione corrente %INFO_ver_date% è meno recente di quella on line !_%THIS_file:~0,-4%_date_online!
echo\:: !_%THIS_file:~0,-4%_date_serial! ninore di !_%THIS_file:~0,-4%_date_serial_online!
echo\:: Questo valore è il resto della divisione del numero per 2^32 (4,294,967,296).
echo\::
)
if !_%THIS_file:~0,-4%_date_serial! GTR !_%THIS_file:~0,-4%_date_serial_online! (
echo\::
echo\::___________la versione corrente %INFO_ver_date% è più aggiornata di quella on line !_%THIS_file:~0,-4%_date_online!
echo\::
)
echo\#############
echo\::
echo\::
echo\::%MSG:§=!LF!::%
call :FOOTER
REM exit /b %ERROR%
for /f "tokens=1,2 delims=^=" %%a in ( 'set _%THIS_file:~0,-4%_' ) do (
if not defined Nn set /a Nn+=1
if !Nn! EQU 1 (
endlocal
)
set Nn=
set "my%%a=%%b"
)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM if "%qualche errore per uscire%"=="qualche errore per uscire" (
REM set "ERROR_brevissima_descrizione=spiegazione estesa ma concisa"
REM echo\::
REM echo\:: ERRORE bla bla bla
REM echo\::
REM call :FOOTER
REM exit /b %ERROR%
REM )
REM echo\::::::::::::::::::::::::::::::::::::::::
REM echo\::%MSG:§=!LF!::%
REM call :FOOTER
REM exit /b %ERROR%
REM (
REM endlocal
REM set "my_VAR_00=%VALORE00_da restituire%"
REM set "my_VAR_01=%VALORE01_da restituire%"
REM exit /b %ERROR%
REM )
:CK_ver_end
:::::::::::::: CK_ver end ::::::::::::::::::::::::::::::::::::::::::
:::::::::::::: CK_ver end ::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::: STRLEN ::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::: STRLEN ::::::::::::::::::::::::::::::::::::::::::::::
goto :STRlen_end
:strlen
:STRLEN_sos
if not "%~0"==":STRLEN_sos" goto :STRLEN_sos_end
echo\::* %THIS_file% %C__%%~1%C_0% .
echo\::
echo\:: Conta la lunghezza di una stringa di caratteri passata come argomento
echo\:: ed imposta la variabile my_STR_length con il valore della lunghezza.
echo\::* La lunghezza massima della stringa che è possibile usare al prompt
echo\:: dei comandi è di 8191 caratteri.
REM echo\::*https://learn.microsoft.com/it-IT/troubleshoot/windows-client/shell-experience/command-line-string-limitation
echo\::* Caratteri speciali %C_RED%^)^("^!^>^|^<^&^^ %C_0% devono essere racchiusi tra %C_RED%"%C_0%^)^(^!^>^|^<^&^^%C_RED%"%C_0%
echo\:: Prima del conteggio sono trasformati in caratteri innocui.
echo\:: %C_RED%^)^(^!^>^|^<^&^^ %C_0%sono sostituiti con %C_RED%¿%C_0%, %C_RED%^" %C_0%é sostituita con %C_RED%•%C_0% .
REM echo\:: I caratteri di reindirizzamento e di raggruppamento %C_RED%)(^>^|^<^& %C_0% devono essere racchiusi con ^"%C_RED%^>^|^<^&%C_0%^"
echo\:: Esempio:
echo\:: * %THIS_file% %~1 topolino pippo e pluto
echo\:: restituisce la variabile my_STR_length=22
echo\:: * %THIS_file% %~1 topolino pippo e pluto ">|<&"
echo\:: restituisce la variabile my_STR_length=29
echo\:: *^|%THIS_file% %~1 "topolino pippo e pluto "^>^|^<^&"
echo\:: ^| non viene eseguita.
echo\:: ^| Il secondo " chiude la stringa che non viene riaperta per >|<&"
echo\:: *^|%THIS_file% %~1 "topolino pippo e pluto "">|<&"
echo\:: ^| così va bene, restituisce la variabile my_STR_length=31
echo\:: * %THIS_file% %~1 "topolino > pippo < & | pluto! >|<&"
echo\:: restituisce la variabile my_STR_length=35
exit /b %ERROR%
:strlen_sos_end
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if defined STR_4_strlen (
if not "%STR_4_strlen:~50,60%"=="" (
set "STR_4_strlen_dummy=!STR_4_strlen:%STR_quote_L%%STR_quote%%STRLEN%=!"
set "ALL_0arg=%1 !STR_4_strlen_dummy:~0,35!... .. . .continua"
) else (
set "STR_4_strlen_dummy=!STR_4_strlen:%STR_quote_L%%STR_quote%%STRLEN%=!"
set "STR_4_strlen_dummy=!STR_4_strlen_dummy:%STR_quote%%STR_quote_R%=!"
set "ALL_0arg=%1 !STR_4_strlen_dummy!"
)
)
set "my_STR_length="
:::: rimuovo strlen all'inizio di %*
REM echo\:: 00 STR_4_strlen==^|%STR_4_strlen%^|
set "STR_4_strlen=!STR_4_strlen:%STR_quote_L%%STR_quote%%STRLEN%=%STR_quote_L%%STR_quote%!"
REM echo\:: 01 STR_4_strlen==^|%STR_4_strlen%^|
set /a N_blank=0
REM rimuovo gli spazi iniziali
:STR_4_strlen_loop
REM echo\:: loop %N_blank% STRLEN==^|%STRLEN%^|
if "%STR_4_strlen:~0,5%" == "%STR_quote_L%%STR_quote% " (
set "STR_4_strlen=!STR_4_strlen:%STR_quote_L%%STR_quote% =%STR_quote_L%%STR_quote%!"
set "STRLEN=!STRLEN! "
set /a N_blank+=1
goto :STR_4_strlen_loop
)
REM echo\:: 1 STR_4_strlen==^|!STR_4_strlen!^|
set "STR_4_strlen=!STR_4_strlen:%STR_quote_L%%STR_quote%=!"
set "STR_4_strlen=!STR_4_strlen:%STR_quote%%STR_quote_R%=!"
REM echo\:: 02 STR_4_strlen==^|%STR_4_strlen%^|
if "%STR_4_strlen%" == "" (
set "ERROR_strlen_no_string=STRLEN senza stringa da contare"
echo\::
echo\:: PARAMETRO %%1 "%1" OK
echo\:: !ERROR_strlen_no_string!
echo\:: Fornisci una stringa per contarne la lunghezza
echo\::
call :FOOTER
exit /b %ERROR%
)
if not "!STR_4_strlen:~50,60!"=="" (
echo\::
echo\:: caratteri speciali %C_RED%^)^("^!^>^|^<^&^^ %C_0%
echo\:: sono trattati in modo speciale; vedi
echo\:: ** %THIS_file% ? strlen
echo\::
echo\:: !STR_4_strlen:~0,35!... .. . .continua
) else (
echo\::
echo\:: caratteri speciali %C_RED%^)^("^!^>^|^<^&^^ %C_0%
echo\:: sono trattati im modo speciale; vedi
echo\:: ** %THIS_file% help strlen
echo\::
echo\:: !STR_4_strlen!
)
call :STRLEN_count
echo\:: restituisce la variabile
echo\:: my_STR_length=%_STR_length%
echo\::
:STRLEN_count
if not "%0"==":STRLEN_count" goto :STRLEN_count_end
set /a len=0
:STRLEN_count_loop
if not "!STR_4_strlen:~%len%!"=="" set /a len+=1 & goto :STRLEN_count_loop
set _STR_length=%len%
goto :EOF
:STRLEN_count_end
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo\::::::::::::::::::::::::::::::::::::::::
echo\::%MSG:§=!LF!::%
call :FOOTER
(
endlocal
set "my_STR_length=%_STR_length%"
exit /b %ERROR%
)
:strlen_end
:::::::::::::: STRLEN end ::::::::::::::::::::::::::::::::::::::::::
:::::::::::::: STRLEN end ::::::::::::::::::::::::::::::::::::::::::
:::::::::::::: NIC ::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::: NIC ::::::::::::::::::::::::::::::::::::::::::::::
goto :nic_end
:NIC
REM setlocal enabledelayedexpansion
:NIC_sos
if not "%~0"==":NIC_sos" goto :NIC_sos_end
echo\::* %THIS_file% %C__%%~1%C_0% .
echo\::
echo\:: per ogni scheda di rete con IP restituisce
echo\:: alcuni utili valori
exit /b %ERROR%
:NIC_sos_end
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: esempio di comando per info su Wi-Fi
:::: Netsh WLAN show interfaces
:::: visualizza la passwd della commessione Wi-Fi
:::: netsh wlan show profile name="NOME-PROFILO" key=clear
:::: esempio di risposta al comando:
:::: wmic nic where "netenabled=true" get /format:list
:::: da qui prendo il valore
:::: index, macaddress, netconnectionid, speed
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: AdapterType=Ethernet 802.3
:::: AdapterTypeId=0
:::: AutoSense=
:::: Availability=3
:::: Caption=[00000008] TP-Link Wireless USB Adapter
:::: ConfigManagerErrorCode=0
:::: ConfigManagerUserConfig=FALSE
:::: CreationClassName=Win32_NetworkAdapter
:::: Description=TP-Link Wireless USB Adapter
:::: DeviceID=8
:::: ErrorCleared=
:::: ErrorDescription=
:::: GUID={E8C2B227-0E77-4C38-B35F-46A3C86EBD52}
:::: Index=8
:::: InstallDate=
:::: Installed=TRUE
:::: InterfaceIndex=23
:::: LastErrorCode=
:::: MACAddress=D0:37:45:94:14:58
:::: Manufacturer=Realtek Semiconductor Corp.
:::: MaxNumberControlled=0
:::: MaxSpeed=
:::: Name=TP-Link Wireless USB Adapter
:::: NetConnectionID=Wi-Fi
:::: NetConnectionStatus=2
:::: NetEnabled=TRUE
:::: NetworkAddresses=
:::: PermanentAddress=
:::: PhysicalAdapter=TRUE
:::: PNPDeviceID=USB\VID_2357&PID_011F\00E04C000001
:::: PowerManagementCapabilities=
:::: PowerManagementSupported=FALSE
:::: ProductName=TP-Link Wireless USB Adapter
:::: ServiceName=RtlWlanu
:::: Speed=120000000
:::: Status=
:::: StatusInfo=
:::: SystemCreationClassName=Win32_ComputerSystem
:::: SystemName=HP1864
:::: TimeOfLastReset=20240516075523.500000+120
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
for /f "tokens=1,2 delims=^= " %%a in ('wmic nic where "netenabled=true" get /format:list 2^>nul') do (
set "Xa="
set "Xb="
set "Xa=%%a"
set "Xb=%%b"
if defined Xb (
if /i "%%a" == "index" (
set /a N_nic+=1
set "_NIC_!N_nic!_%%a=%%b"
)
if /i "%%a" == "macaddress" (
set "_NIC_!N_nic!_%%a=%%b"
)
if /i "%%a" == "netconnectionid" (
REM Ethernet - Wi-Fi ....
set "_NIC_!N_nic!_%%a=%%b"
)
if /i "%%a" == "speed" (
set "_NIC_!N_nic!_%%a=%%b"
)
)
)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if not defined N_nic (
set "ERROR_no_nic=NO NIC-Network Interface Controller- con IP"
echo\::
echo\:: no nic -Network Interface Controller-
echo\:: nessuna scheda abilitata con IP
echo\::
call :FOOTER
exit /b %ERROR%
)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: esempio di risposta al comando:
:::: wmic nicconfig where (index="!INDEX_N!" and macaddress="!MAC_N!") get %SEARC_NIC_PROPERTY% /format:list"
:::: Visualizza tutte le proprietà
:::: wmic nicconfig where IPEnabled=TRUE get /format:list
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: ArpAlwaysSourceRoute=
:::: ArpUseEtherSNAP=
:::: Caption=[00000012] Realtek USB GbE Family Controller
:::: DatabasePath=%SystemRoot%\System32\drivers\etc
:::: DeadGWDetectEnabled=
:::: DefaultIPGateway={"172.28.0.1"}
:::: DefaultTOS=
:::: DefaultTTL=
:::: Description=Realtek USB GbE Family Controller
:::: DHCPEnabled=TRUE
:::: DHCPLeaseExpires=20240516112847.000000+120
:::: DHCPLeaseObtained=20240516085207.000000+120
:::: DHCPServer=172.28.0.1
:::: DNSDomain=lanpareto
:::: DNSDomainSuffixSearchOrder={"lanpareto"}
:::: DNSEnabledForWINSResolution=FALSE
:::: DNSHostName=hp1864
:::: DNSServerSearchOrder={"172.28.0.1"}
:::: DomainDNSRegistrationEnabled=FALSE
:::: ForwardBufferMemory=
:::: FullDNSRegistrationEnabled=TRUE
:::: GatewayCostMetric={0}
:::: IGMPLevel=
:::: Index=12
:::: InterfaceIndex=14
:::: IPAddress={"172.28.5.214","fe80::7e5:2359:2836:5bcb"}
:::: IPConnectionMetric=25
:::: IPEnabled=TRUE
:::: IPFilterSecurityEnabled=FALSE
:::: IPPortSecurityEnabled=
:::: IPSecPermitIPProtocols={}
:::: IPSecPermitTCPPorts={}
:::: IPSecPermitUDPPorts={}
:::: IPSubnet={"255.255.0.0","64"}
:::: IPUseZeroBroadcast=
:::: IPXAddress=
:::: IPXEnabled=
:::: IPXFrameType=
:::: IPXMediaType=
:::: IPXNetworkNumber=
:::: IPXVirtualNetNumber=
:::: KeepAliveInterval=
:::: KeepAliveTime=
:::: MACAddress=00:E0:4C:68:B7:3D
:::: MTU=
:::: NumForwardPackets=
:::: PMTUBHDetectEnabled=
:::: PMTUDiscoveryEnabled=
:::: ServiceName=rtux64w10
:::: SettingID={9D499C5D-EA64-4740-BC3B-B82065415004}
:::: TcpipNetbiosOptions=0
:::: TcpMaxConnectRetransmissions=
:::: TcpMaxDataRetransmissions=
:::: TcpNumConnections=
:::: TcpUseRFC1122UrgentPointer=
:::: TcpWindowSize=
:::: WINSEnableLMHostsLookup=TRUE
:::: WINSHostLookupFile=
:::: WINSPrimaryServer=172.28.0.1
:::: WINSScopeID=
:::: WINSSecondaryServer=
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set "SEARC_NIC_PROPERTY=DefaultIPGateway^,Description"
set "SEARC_NIC_PROPERTY=%SEARC_NIC_PROPERTY%^,DHCPEnabled"
set "SEARC_NIC_PROPERTY=%SEARC_NIC_PROPERTY%^,DHCPServer"
set "SEARC_NIC_PROPERTY=%SEARC_NIC_PROPERTY%^,DNSDomain"
set "SEARC_NIC_PROPERTY=%SEARC_NIC_PROPERTY%^,DNSDomainSuffixSearchOrder"
set "SEARC_NIC_PROPERTY=%SEARC_NIC_PROPERTY%^,DNSHostName"
set "SEARC_NIC_PROPERTY=%SEARC_NIC_PROPERTY%^,DNSServerSearchOrder"
set "SEARC_NIC_PROPERTY=%SEARC_NIC_PROPERTY%^,IPAddress"
set "SEARC_NIC_PROPERTY=%SEARC_NIC_PROPERTY%^,IPConnectionMetric"
set "SEARC_NIC_PROPERTY=%SEARC_NIC_PROPERTY%^,IPSubnet"
set "SEARC_NIC_PROPERTY=%SEARC_NIC_PROPERTY%^,MACAddress"
REM Computer\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces\{SettingID}
set "SEARC_NIC_PROPERTY=%SEARC_NIC_PROPERTY%^,SettingID"
echo\:: Network-Interface-Controller
echo\:: %N_nic% NIC con ip assegnato
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Visualizza tutte le proprietà
:::: wmic nicconfig where IPEnabled=TRUE get /format:list
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
for /L %%a in (1,1,%N_nic%) do (
set "INDEX_N="
set "MAC_N="
set "INDEX_N=!_NIC_%%a_index!"
set "MAC_N=!_NIC_%%a_macaddress!"
for /f "tokens=1,2 delims=^=" %%A in ('"wmic nicconfig where (index="!INDEX_N!" and macaddress="!MAC_N!") get %SEARC_NIC_PROPERTY% /format:list"') do (
set "Y_A="
set "Y_B="
set "Y_A=%%A"
set "Y_B=%%B"
if defined Y_B (
set "Y_B=!Y_B:{=!"
set "Y_B=!Y_B:}=!"
set "Y_B=!Y_B:"=!"
set "Y_B=!Y_B:,=-!"
set "_NIC_%%a_!Y_A!=!Y_B!"
)
)
for /f "tokens=1,2 delims=^=" %%T in ('set _NIC_%%a') do (
set "T=%%T"
set "T=!T:_NIC_%%a_=!"
REM if /i not "!T!" == "index" (
call :NIC_all_property %%a "!T!=%%U"
REM set "_NIC_%%a_index="
REM )
)
)
:NIC_all_property
if not "%0" == ":NIC_all_property" goto :NIC_all_property_end
set "X2=%~2"
set "_NIC_%1_all_property="!X2!" !_NIC_%1_all_property!"
goto :EOF
:NIC_all_property_end
::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::
echo\::::::::::::::::::::::::::::::::::::::::
echo\:: my_NIC_N=%N_nic%
for /f "tokens=*" %%L in ('set _NIC_') do (
echo\%%L | findstr /r /c:"_NIC_[0-9]*_all_property" >nul
if !errorlevel! EQU 0 (
set "DUMMY_nic_prop=%%L"
set "DUMMY_nic_prop=!DUMMY_nic_prop:"='!
call :NIC_all_prop_split "!DUMMY_nic_prop!"
) else (
echo\:: my%%L
)
)
:NIC_all_prop_split
if not "%0" == ":NIC_all_prop_split" goto :NIC_all_prop_split_end
set "K="
set "K=%~1"
set "K=!K:' '=§!"
set "K=!K:'="!"
echo\::my%K:§=!LF!:: %
goto :EOF
:NIC_all_prop_split_end
::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::
echo\::::::::::::::::::::::::::::::::::::::::
echo\:: %N_nic% NIC con ip asegnato
echo\::::::::::::::::::::::::::::::::::::::::
echo\::%MSG:§=!LF!::%
call :FOOTER
set "N="
for /f "tokens=*" %%G in ('set _NIC_') do (
REM echo\@@@@@@@ G==%%G
set /a N+=1
REM echo N==!N!
REM if "!N!" EQU "1" endlocal & endlocal
if "!N!" EQU "1" endlocal & set "my_NIC_N=%N_nic%"
REM echo\@1@1@1@ G==%%G
set "my%%G"
)
set "N="
exit /b 0
:nic_end
:::::::::::::: NIC end ::::::::::::::::::::::::::::::::::::::::::
:::::::::::::: NIC end ::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::: run_as_admin ::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::: run_as_admin ::::::::::::::::::::::::::::::::::::::::::::::
goto :run_as_admin_end
:run_as_admin
:RUN_AS_ADMIN_sos
if not "%~0"==":RUN_AS_ADMIN_sos" goto :run_as_admin_sos_end
echo\::* %THIS_file% %C__%%~1%C_0% . & REM %2 .
echo\::
echo\:: %%2="path al file da eseguire come Administrators"
echo\:: %%3="eventuali parametri da passare"
echo\:: Spazi vuoti devono essere racchiusi tra " "
echo\:: Esempio:
echo\:: %THIS_file% %1 %%comspec%%
echo\:: esegue %C__%%comspec%%C_0% con permessi elevati
echo\:: %THIS_file% %1 "c:\my dir\my file.exe" "parametro_1 parametro_2"
echo\:: esegue %C__%"c:\my dir\my file.exe" parametro_1 parametro_2%C_0% con permessi elevati
if "%2"=="NO_CMDOW_exe" (
echo\::---------------------
echo\:: %C__%%~1%C_0% funziona con %C__%cmdow.exe%C_0% . ^(funziona anche con powershell^)
echo\:: CMDOW [Version 1.4.8] Win32 Commandline Window Utility for NT4/2000/XP/7.
echo\:: ^(C^) Copyright 2001-2014 Ritchie Lawrence, http://www.commandline.co.uk.
echo\:: https://github.com/ritchielawrence/cmdow/
echo\:: https://ritchielawrence.github.io/cmdow/
echo\:: Download: https://github.com/ritchielawrence/cmdow/blob/master/bin/Release/cmdow.exe
echo\::
echo\:: Molti anrivirus individuano cmdow.exe come virus perchè legge ed elabora
echo\:: informazioni che %C__%$%C_0%windows%C__%$%C_0% non accetta. Non è vero.
echo\::-OPEN-SOURCE "MIT license" garantisce ciò che cmdow.exe elabora.
echo\:: Istruisci il tuo antivirus a considerare cmdow.exe un programma sano.
echo\:: https://github.com/ritchielawrence/cmdow?tab=readme-ov-file#is-cmdow-malware
echo\::::::::::::::::::::::::::::::::::::::::
)
exit /b %ERROR%
:run_as_admin_sos_end
:: https://ss64.com/vb/syntax-elevate.html
if "%~2"§==""§ (
set "ERROR_run_as_admin_P2=Parametro 2 nul"
echo\::
echo\:: "%~1" Richiesto un percorso completo ad un file
echo\:: da eseguire in una consolle con privilegi elevati.
echo\:: Se contiene spazi racchiudere tra " "
echo\::
call :FOOTER
exit /b %ERROR%
)
if exist "%~f2" (
if "%~x2"§==""§ (
set "ERROR_run_as_admin_P2=Parametro 2.NO_estensione"
echo\::
echo\:: Richiesto un percorso completo ad un file compreso l'estensione
echo\:: "%~2".NO_estensione??
echo\:: se contiene spazi racchiudere tra " "
echo\::
call :FOOTER
exit /b %ERROR%
)
echo\%~f2| findstr /r /c:".*[ ].*" >nul 2>&1
if !errorlevel! EQU 0 (
set "_EXE_this=%~sdpnx2"
) else (
set "_EXE_this=%~f2"
)
)
if not defined _EXE_this (
set "ERROR_run_as_admin_P2=Parametro 2 "%~2" "
echo\::
echo\:: "%1" Richiesto un percorso completo ad un file
echo\:: da eseguire con permessi elevati "gruppo Administrators"
echo\:: Se contiene spazi racchiudere tra " "
echo\::
call :FOOTER
exit /b %ERROR%
)
set "_EXE3="
set "Xn="
shift /1
:loop_p3
shift /1
set "Xn=%~1"
if defined Xn (
if exist "%Xn%" (
echo\%Xn%| findstr /r /c:".*[ ].*" >nul 2>&1
REM se trovo spazi vuoti trasformo in nome breve
if !errorlevel! EQU 0 (
set "_EXE3=!_EXE3! %~sdpnx1 "
) else (
set "_EXE3=!_EXE3! %~1 "
)
) else (
set _EXE3=!_EXE3! %~1
)
REM echo\@@!_EXE3!
set "Xn="
goto :loop_p3
)
REM https://ss64.com/vb/shellexecute.html
REM OK .ShellExecute "application", "parameters", "dir", "verb", window
REM NO .ShellExecute 'some program.exe', '"some parameters with spaces"', , "runas", 1
set "RUN_AS_ADMIN_time=%time: =0%"
set "RUN_AS_ADMIN_time=%RUN_AS_ADMIN_time::=%"
set "RUN_AS_ADMIN_time=%RUN_AS_ADMIN_time:.=%"
set "RUN_AS_ADMIN_time=%RUN_AS_ADMIN_time:,=%"
REM https://ss64.com/nt/syntax-random.html
REM set /a RUN_AS_ADMIN_random=(%random%*1000/32768+1000)
set /a "RUN_AS_ADMIN_random=(%random%*100/32768+100)"
set "RUN_AS_ADMIN_win_title=%THIS_file_pid%-%RUN_AS_ADMIN_time%-%RUN_AS_ADMIN_random%"
set "_CMD=%comspec%"
set "_EXE_FULL=%_EXE_this% %_EXE3%"
set "_VBS=%temp%\dummy.vbs"
set "_OUT_cmd=%temp%\dummy.cmd"
if exist "%_VBS%" del /q /f "%_VBS%"
if exist "%_OUT_cmd%" del /q /f "%_OUT_cmd%"
::::::::::::::
:::::: file per dare risposta nella consolle elevata
::::::::::::::
echo\@echo off ^& setlocal > %_OUT_cmd%
echo\title %RUN_AS_ADMIN_win_title% "%username%" chiama "%%username%%" >> %_OUT_cmd%
echo\if "%%1"=="start" ^( >> %_OUT_cmd%
echo\ set "dummy_time_start=start %%date%% %%time: =0%%" >> %_OUT_cmd%
echo\ set "dummy_act=esegue" >> %_OUT_cmd%
echo\ set "dummy_call=chiama" >> %_OUT_cmd%
echo\^) >> %_OUT_cmd%
echo\if "%%1"=="end" ^( >> %_OUT_cmd%
echo\ set "dummy_time_end=end %%date%% %%time: =0%%" >> %_OUT_cmd%
echo\ set "dummy_act=ha eseguito" >> %_OUT_cmd%
echo\ set "dummy_call=ha chiamato" >> %_OUT_cmd%
echo\^) >> %_OUT_cmd%
echo\if "%%1"=="end" ^( >> %_OUT_cmd%
echo\ echo\::--- %%dummy_time_end%% -------- >> %_OUT_cmd%
echo\^) >> %_OUT_cmd%
echo\if "%%1"=="start" echo\::::::::::::::::: >> %_OUT_cmd%
echo\echo\:: "%username%" %%dummy_call%% "%%username%%" >> %_OUT_cmd%
echo\echo\:: utente "%%username%%" consolle con permessi elevati >> %_OUT_cmd%
echo\echo\:: "%%username%%" %%dummy_act%%: >> %_OUT_cmd%
echo\echo\:: %_EXE_this% >> %_OUT_cmd%
if defined _EXE3 echo\echo\:: %_EXE3% >> %_OUT_cmd%
echo\if "%%1"=="start" ^( >> %_OUT_cmd%
echo\ echo\::--- %%dummy_time_start%% -------- >> %_OUT_cmd%
echo\ echo\:: %_EXE_this% >> %_OUT_cmd%
if defined _EXE3 echo\ echo\:: %_EXE3% >> %_OUT_cmd%
echo\^) >> %_OUT_cmd%
echo\if "%%1"=="end" echo\::::::::::::::::: >> %_OUT_cmd%
echo\if defined dummy_time_end set "dummy_time_start=" >> %_OUT_cmd%
echo\endlocal ^& set "dummy_time_start=%%dummy_time_start%%" >> %_OUT_cmd%
::::::::::::::
:::::: fine file per dare risposta nella consolle elevata
::::::::::::::
echo Set UAC = CreateObject^("Shell.Application"^) > "%_VBS%"
echo UAC.ShellExecute "%_CMD%"," /K title %RUN_AS_ADMIN_win_title% & cd /d %cd% & call %_OUT_cmd% start & %_EXE_FULL% & call %_OUT_cmd% end & set dummy_time_start=", "%cd%", "runas", 1 >> "%_VBS%"
cscript //nologo %_VBS%
if defined CMDOW_exe (
REM echo\%CMDOW_exe% /p /f ^| findstr /r /c:".*%RUN_AS_ADMIN_win_title%" ^>nul 2^>^&1
%CMDOW_exe% /p /f | findstr /r /c:".*%RUN_AS_ADMIN_win_title%" >nul 2>&1
set ERROR_consolle=!errorlevel!
) else (
powershell "Get-Process | Where-Object {$_.mainWindowTitle} | Format-Table Id, Name, mainWindowtitle" ^
| findstr /r /c:".*%RUN_AS_ADMIN_win_title%.*" >nul 2>&1
set ERROR_consolle=!errorlevel!
)
REM echo\++++ ERROR_consolle==%ERROR_consolle%
if %ERROR_consolle% EQU 0 (
set ERROR_consolle=
echo\::
echo\:: "%username%" chiede una consolle con permessi elevati
echo\:: per eseguire %_EXE_this%
if defined _EXE3 echo\:: %_EXE3%
echo\:: CONSOLLE "%RUN_AS_ADMIN_win_title%" APERTA
echo\::
call :FOOTER
) else (
set "ERROR_run_as_admin_NO=UAC richiesta non valida"
echo\::
echo\:: CONSOLLE RIFIUTATA
echo\:: "%username%" !ERROR_run_as_admin_NO!
echo\:: comando UAC %_EXE_this%
if defined _EXE3 echo\:: parametri: %_EXE3% .
echo\::
echo\:: autenticazione??? ERRORE bla bla bla
echo\::
call :FOOTER
exit /b %ERROR%
)
:run_as_admin_end
:::::::::::::: function end ::::::::::::::::::::::::::::::::::::::::::
:::::::::::::: function end ::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::: user_is_admin ::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::: user_is_admin ::::::::::::::::::::::::::::::::::::::::::::::
:::: REM >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
:::: REM if '%errorlevel%' NEQ '0' (
:::: REM goto UACPrompt
:::: REM ) else ( goto gotAdmin )
:::: REM :UACPrompt
:::: REM echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
:::: REM echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
:::: REM "%temp%\getadmin.vbs"
:::: REM exit /B
:::: REM :gotAdmin
goto :user_is_admin_end
:user_is_admin
:USER_IS_ADMIN_sos
if not "%~0"==":USER_IS_ADMIN_sos" goto :user_is_admin_sos_end
echo\::* %THIS_file% %C__%%~1%C_0% .
echo\::
echo\:: Controlla su questo computer "%computername%"
echo\:: se l'utente locale "%username%" che esegue questo script
echo\:: fa parte del gruppo locale "Users" oppure "Administrators"
echo\::
echo\:: Restituisce la var "my_USER_IS" valorizzata
echo\:: con il gruppo di appartenenza
exit /b %ERROR%
:user_is_admin_sos_end
REM net session /list >nul 2>&1
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
set "is_admin=%errorlevel%"
set "my_USER_IS="
if %is_admin% EQU 0 (
for /f "delims=* tokens=1,2*" %%A in ('net user %username% ^| findstr /i /r /x /c:"^.*[*]Administrators.*"') do (
if !errorlevel! EQU 0 (
set "my_USER_IS=%%B"
)
)
)
if %is_admin% GEQ 1 (
for /f "delims=* tokens=1,2*" %%A in ('net user %username% ^| findstr /i /r /x /c:"^.*[*]Users.*"') do (
if !errorlevel! EQU 0 (
set "my_USER_IS=%%B"
)
)
)
if not defined my_USER_IS (
set ERROR_USER_IS=%username% non é nel gruppo "*Users", non é nel gruppo "*Administrators"
echo\::
echo\:: %username% non é nel gruppo "*Users", non é nel gruppo "*Administrators"
echo\::
call :FOOTER
exit /b %ERROR%
)
echo\:: utente locale "%username%" di questo host "%computername%"
echo\:: gruppo locale "%my_USER_IS: =%"
echo\:: valore restituito
echo\:: %%my_USER_IS%%==%my_USER_IS: =%
echo\::::::::::::::::::::::::::::::::::::::::
echo\::%MSG:§=!LF!::%
call :FOOTER
(
REM endlocal & endlocal
endlocal
set my_USER_IS=%my_USER_IS: =%
)
:user_is_admin_end
:::::::::::::: user_is_admin end ::::::::::::::::::::::::::::::::::::::::::
:::::::::::::: user_is_admin end ::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::: my_geoip start :::::::::::::::::::::::::::::::::::::::::::
:::::::::::::: my_geoip start :::::::::::::::::::::::::::::::::::::::::::
goto :geoip_end
:geoip
REM setlocal enabledelayedexpansion
:GEOIP_sos
if not "%~0"==":GEOIP_sos" goto :geoip_sos_end
echo\::* %THIS_file% %C__%%~1%C_0% .
echo\::
echo\:: Utilizza "curl.exe" per interrogare il servizio
echo\:: web "http://ip-api.com/json/?fields=66846719"
echo\:: -Se come parametro si aggiunge un indirizzo "IP"
echo\:: oppure un nome a "DNS" vengono restituiti i valori
echo\:: per il l'indirizzo.
echo\:: -Se non è specificato un'indirizzo i valori restituiti
echo\:: si riferiscono alla connessione internet in uso.
echo\:: -Esempio:
echo\::* %THIS_file% %1
echo\:: restituisce i valori per la connessione internet in uso.
echo\::* %THIS_file% %1 8.8.8.8
echo\:: restituisce i valori per l'indirizzo IP "8.8.8.8"
echo\:: il DNS pubblico di google
echo\::* %THIS_file% %1 208.67.222.222
echo\:: restituisce i valori per l'indirizzo IP "208.67.222.222"
echo\:: il DNS pubblico di Cisco
exit /b %ERROR%
:geoip_sos_end
if exist "%~dp0curl.exe" (
echo\:: "%~dp0curl.exe"
set "CURL_exe=%~dp0curl.exe"
)
if not defined CURL_exe (
if exist "%windir%\system32\curl.exe" (
REM echo\:: "%windir%\system32\curl.exe"
REM :::: "%windir%\system32" è un percorso in %path%
set "CURL_exe=curl.exe"
)
)
if not defined CURL_exe (
set "ERROR_geoip=MANCA "curl.exe""
echo\::
echo\:: manca curl.exe
echo\::
call :FOOTER
exit /b %ERROR%
)
REM trova %computername% ip4
REM set "FIND_ip4=[0-9]*[.][0-9]*[.][0-9]*[.][0-9]*"
REM ping -a -n 1 -4 %computername% | findstr /i /r /c:".*%computername%.*[%FIND_ip4%]" & echo error==%errorlevel%
REM trova localhost [::1*
REM ping -a -n 1 -6 %computername% | findstr /i /r /c:".*%computername%[ *[:1]*" & echo %errorlevel%
REM ping -a -n 1 -6 %computername% | findstr /i /r /c:".*%computername%[ *[fe80:]*" & echo %errorlevel%
REM trova connetività su internet
REM ping -a -n 1 gnu.org | findstr /i /r /c:".*[[][0-9:].*" & echo %errorlevel%
set "PING_this_2=gnu.org"
set "PING_this_1=ip-api.com"
set "PING_this=%PING_this_1%"
REM ping -a -n 1 %PING_this% | findstr /i /r /c:".*[[][0-9:].*" >nul
REM for /f "tokens=1,2 delims=^=" %%A in ( 'set PING_this_' ) do (
REM ping -a -n 1 %%B >nul
REM if !errorlevel! GTR 0 (
REM set "ERROR_geoip_no_internet=connessione a internet non disponibile"
REM set "NO_PING_this=%%B"
REM )
REM if !errorlevel! EQU 0 (
REM set "ERROR_geoip_no_internet="
REM set "NO_PING_this="
REM )
REM if defined ERROR_geoip_no_internet (
REM ping -a -n 1 %%B >nul
REM if !errorlevel! GTR 0 (
REM set "ERROR_geoip_no_internet=connessione a internet non disponibile"
REM set "NO_PING_this=%%B"
REM )
REM )
REM )
REM if defined NO_PING_this (
REM echo\::
REM echo\:: connessione a internet non disponibile
REM echo\:: [ping -a -n 1 %NO_PING_this%] senza risposta
REM echo\::
REM call :FOOTER
REM exit /b %ERROR%
REM )
ping -a -n 1 -f %PING_this% >nul
if %errorlevel% GTR 0 (
set "ERROR_geoip_no_internet=connessione a internet non disponibile"
echo\::
echo\:: connessione a internet non disponibile
echo\:: [ping -a -n 1 -l 8 -f -w 128 %PING_this%] senza risposta
echo\::
call :FOOTER
exit /b %ERROR%
)
:::: REM https://ip-api.com/docs/api:json
:::: set "FIELDS=status,message,"
:::: set "FIELDS=%FIELDS%continent,continentCode,country,countryCode,region,"
:::: set "FIELDS=%FIELDS%regionName,city,district,zip,lat,lon,timezone,offset,currency,"
:::: set "FIELDS=%FIELDS%isp,org,as,asname,reverse,mobile,proxy,hosting,query"
set "FIELDS=66846719"
set "ADDRESS=%~2"
set "GEO_IP_API=http://ip-api.com/json/%ADDRESS%?fields=%FIELDS%"
REM set "CURL_exe=%CURL_exe% -v -s -S -k -L --retry 1 -A "%THIS_file:~0,-4%""
set "CURL_exe=%CURL_exe% -s -S -k -L --retry 1 -A "%THIS_file:~0,-4% %THIS_file_pid%""
echo\:: %CURL_EXE% %GEO_IP_API%
::::::::::::
for /f "tokens=*" %%A in ( '"%CURL_exe% %GEO_IP_API%"' ) do (
REM if !errorlevel! GTR 0 (
REM set "ERROR_geoip_curl=errore curl"
REM echo\::
REM echo\:: errore curl
REM echo\::
REM call :FOOTER
REM exit /b %ERROR%
REM )
set "A_x=%%A"
set A_start=!A_x:~0,1!
set A_end=!A_x:~-1!
set CK_A=!A_start!!A_end!
if not "!CK_A!"=="{}" ( REM json restituito da curl sta su una sola riga
set/a CK_A_line+=1
if !CK_A_line! EQU 1 (
set "CK_A_line_1=!A_x!"
set "A_start_1=!A_x:~0,1!"
)
set "A_end=!A_x:~-1!"
)
if "!CK_A!"=="{}" (
echo\:: valori restituiti:... .. .
set "geo_ip=%%~A"
set "geo_ip=!geo_ip:{=!"
set "geo_ip=!geo_ip:}=!"
set "geo_ip=!geo_ip:":==!"
set "geo_ip=!geo_ip:"=!"
set "geo_ip=!geo_ip:, =##!"
)
)
if defined CK_A_line (
set ERROR_geoip_json=valore json restituito non valido
echo\:: !ERROR_geoip_json!, atteso {... .. . .}
echo\:: !ERROR_geoip_json!, ricevuto !A_start_1!... .. . .!A_end!
if not !CK_A_line_1! EQU !CK_A_line! (
echo\:: *!CK_A_line! righe... .. . . . .
echo\:: * 1 !CK_A_line_1!
echo\:: *!CK_A_line! !A_x!
) else (
echo\:: * 1 !CK_A_line_1!
)
call :FOOTER
exit /b %ERROR%
)
REM echo\ ---- GEO_IP ----
REM echo\%geo_ip:,=!lf!%
for /f "tokens=1,2 delims=^=" %%a in ( "%geo_ip:,=!LF!%" ) do (
set "A=%%a"
set "B=%%b"
if defined TR_exe (
for /f "tokens=*" %%Z in ( 'echo\!A!^|"%TR_exe%" [:lower:] [:upper:]') do (
set "A=%%Z"
)
)
if /i "!A!"=="status" (
if "!B!"=="fail" (
set "ERROR_geoip_status=ip-api.com errore !B!"
)
)
if defined ERROR_geoip_status (
if "!B!" NEQ "fail" set "ERROR_geoip_!A!=ip-api.com errore !B!"
)
if not defined ERROR_geoip_status (
REM if not defined B set "B="""
if not defined B set "B=_NUL_"
set "_!A!=!B:##=, !"
)
)
set "A="
set "B="
if defined ERROR_geoip_status (
call :FOOTER
exit /b %ERROR%
)
if not defined ADDRESS set "ADDRESS=local_%_query%"
echo\::::::::::::::::::::::::::::::::::::::::
for /f "tokens=*" %%z in ( 'set _' ) do echo\:: my_%ADDRESS%%%z
echo\::::::::::::::::::::::::::::::::::::::::
echo\::%MSG:§=!LF!::%
call :FOOTER
set "N="
for /f "tokens=1,2 delims=^=" %%G in ('set _') do (
set /a N+=1
if !N! EQU 1 (
endlocal
)
set "my_%ADDRESS%%%G=%%H"
)
set "N="
:geoip_end
:::::::::::::: my_geoip end ::::::::::::::::::::::::::::::::::::::::::
:::::::::::::: my_geoip end ::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::: my_date ::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::: my_date ::::::::::::::::::::::::::::::::::::::::::::::::::
goto :my_date_end
:my_date
:MY_DATE_sos
if not "%~0"==":MY_DATE_sos" goto :my_date_sos_end
echo\::* %THIS_file% %C__%%~1%C_0% .
echo\::
echo\:: restituisce una serie di variabili "my_....."
echo\:: che possono essere utili.
REM call "%THIS_file_full_path%" my_date >"%temp%\%~1.txt"
REM set "N="
REM for /f "tokens=*" %%Z in ('type "%temp%\%~1.txt"') do (
REM set "Zx=%%Z"
REM echo\!Zx! | findstr /x /r /c:"^[:][:][ ][m][y][_].*$" >nul 2>&1
REM if !errorlevel! EQU 0 (
REM set /a N+=1
REM if !N! EQU 1 (
REM echo\::* %THIS_file% %C__%%~1%C_0% .
REM echo\::
REM echo\:: restituisce queste variabili... .. .
REM echo\!Zx!
REM ) else (
REM echo\!Zx!
REM )
REM )
REM )
REM set "N="
REM del /q "%temp%\%~1.txt"
exit /b %ERROR%
:my_date_sos_end
REM for /f "tokens=1-5 delims= " %%a in ( 'wmic path win32_localtime get day^,dayofweek^,month^,year ^| findstr /R [0-9]' ) do (
REM set DAY=%%a
REM set DAY_OF_WEEK=%%b
REM set MONTH_N=%%c
REM set YEAR=%%d
REM )
:::: https://superuser.com/questions/331220/wmic-path-what-wmic-class-what
REM wmic path Win32_TimeZone get /format:list
REM wmic path Win32_UTCTime get /format:list
wmic path win32_localtime get /format:list >nul 2>&1
if %errorlevel% EQU 0 (
set "COUNT_all_wmic="
for /f "tokens=1,2 delims=^=" %%A in ('wmic path win32_localtime get /format:list') do (
set /a COUNT_all_wmic+=1
REM set "_%%A=%%B"
REM REM @echo\ A--[ %%A ] B--[ %%B ]
REM set /a COUNT_all+=1
set "Ax=%%A"
set "Bx=%%B"
REM echo\---- 'Ax=!Ax!' 'Bx=!Bx!'
REM :::: controllo se !Bx! è vuoto
REM :::: Milliseconds= non
if not !Bx!dummy==dummy (
REM :::: imposto solo !Bx! con valore
REM echo\:: valore valido !Ax!=!Bx!
set "!Ax!=!Bx!"
)
)
) else (
set "ERROR_win32_localtime=wmic path win32_localtime"
)
if defined Year (
set "_YEAR=%Year%"
) else (
set "ERROR_my_date_YEAR=Non trovo l'anno"
)
if defined Month (
if %Month%==1 set "_MONTH_NAME=gennaio"
if %Month%==2 set "_MONTH_NAME=febbraio"
if %Month%==3 set "_MONTH_NAME=marzo"
if %Month%==4 set "_MONTH_NAME=aprile"
if %Month%==5 set "_MONTH_NAME=maggio"
if %Month%==6 set "_MONTH_NAME=giugno"
if %Month%==7 set "_MONTH_NAME=luglio"
if %Month%==8 set "_MONTH_NAME=agosto"
if %Month%==9 set "_MONTH_NAME=settembre"
if %Month%==10 set "_MONTH_NAME=ottobre"
if %Month%==11 set "_MONTH_NAME=novembre"
if %Month%==12 set "_MONTH_NAME=dicembre"
if "%Month:~1,1%"=="" (
set "_MONTH_N=0%Month%"
) else (
set "_MONTH_N=%Month%"
)
) else (
set "ERROR_my_date_Month=Non trovo il mese"
)
if defined DayOfWeek (
if %DayOfWeek%==0 set "_DAY_NAME=domenica"
if %DayOfWeek%==1 set "_DAY_NAME=lunedì"
if %DayOfWeek%==2 set "_DAY_NAME=martedì"
if %DayOfWeek%==3 set "_DAY_NAME=mercoledì"
if %DayOfWeek%==4 set "_DAY_NAME=giovedì"
if %DayOfWeek%==5 set "_DAY_NAME=venerdì"
if %DayOfWeek%==6 set "_DAY_NAME=sabato"
if %DayOfWeek%==7 set "_DAY_NAME=domenica"
if "%DayOfWeek:~1,1%"=="" (
set "_DAY_OF_WEEK=0%DayOfWeek%"
) else (
set "_DAY_OF_WEEK=%DayOfWeek%"
)
) else (
set "ERROR_my_date_DayOfWeek=Non trovo il giorno della settimana"
)
if defined Quarter (
set "_QUARTER_IN_YEAR=%Quarter%"
) else (
set "ERROR_my_date_QUARTER_IN_YEAR=Non trovo il quadrimestre"
)
if defined WeekInMonth (
set "_WEEK_IN_MONTH=%WeekInMonth%"
) else (
set "ERROR_my_date_WEEK_IN_MONTH=Non trovo la settimana nel mese"
)
if defined Day (
if "%Day:~1,1%"=="" (
set "_DAY_IN_MONTH=0%Day%"
) else (
set "_DAY_IN_MONTH=%Day%"
)
) else (
set "ERROR_my_date_DAY_IN_MONTH=Non trovo il giorno del mese"
)
REM :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM wmic path Win32_TimeZone get /format:list
REM Bias=60
REM Caption=(UTC+01:00) Amsterdam, Berlino, Berna, Roma, Stoccolma, Vienna
REM DaylightBias=-60
REM DaylightDay=5
REM DaylightDayOfWeek=0
REM DaylightHour=2
REM DaylightMillisecond=0
REM DaylightMinute=0
REM DaylightMonth=3
REM DaylightName=ora legale Europa occidentale
REM DaylightSecond=0
REM DaylightYear=0
REM Description=(UTC+01:00) Amsterdam, Berlino, Berna, Roma, Stoccolma, Vienna
REM SettingID=
REM StandardBias=0
REM StandardDay=5
REM StandardDayOfWeek=0
REM StandardHour=3
REM StandardMillisecond=0
REM StandardMinute=0
REM StandardMonth=10
REM StandardName=ora solare Europa occidentale
REM StandardSecond=0
REM StandardYear=0
REM :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
wmic path Win32_TimeZone get /format:list >nul 2>&1
if %errorlevel% EQU 0 (
set "COUNT_all_wmic="
REM for /f "tokens=1,2 delims=^=" %%A in ('wmic path Win32_TimeZone get Description /format:list') do (
for /f "tokens=1,2 delims=^=" %%A in ('wmic path Win32_TimeZone get /format:list') do (
set /a COUNT_all_wmic+=1
REM set "_%%A=%%B"
REM REM @echo\ A--[ %%A ] B--[ %%B ]
REM set /a COUNT_all+=1
set "Ax=%%A"
set "Bx=%%B"
REM echo\---- 'Ax=!Ax!' 'Bx=!Bx!'
REM :::: controllo se !Bx! è vuoto
REM :::: Milliseconds= non
if not !Bx!dummy==dummy (
REM if defined TR_UPPER (
REM for /f "tokens=*" %%Z in ( 'echo\!Ax!^|%TR_UPPER%') do (
REM set "Ax=%%Z"
REM echo\@@@@@@@@@!Ax!
REM )
REM )
REM :::: imposto solo !Bx! con valore
REM echo\:: valore valido !Ax!=!Bx!
set "!Ax!=!Bx!"
)
)
) else (
set "ERROR_Win32_TimeZone=wmic path Win32_TimeZone"
)
if defined Description (
set "_TIME_Description=%Description%"
) else (
set "ERROR_TimeZone_Description=non trovo la descrizione di TimeZone"
)
if defined StandardName (
set "_TIME_StandardName=%StandardName%"
) else (
set "ERROR_TimeZone_StandardName=non trovo StandardName di TimeZone"
)
if defined DaylightName (
set "_TIME_DaylightName=%DaylightName%"
) else (
set "ERROR_TimeZone_DaylightName=non trovo DaylightName di TimeZone"
)
REM :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM wmic path Win32_UTCTime get /format:list
REM Day=4
REM DayOfWeek=4
REM Hour=12
REM Milliseconds=
REM Minute=26
REM Month=4
REM Quarter=2
REM Second=7
REM WeekInMonth=1
REM Year=2024
REM :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
wmic path Win32_UTCTime get /format:list >nul 2>&1
if %errorlevel% EQU 0 (
set "COUNT_all_wmic="
for /f "tokens=1,2 delims=^=" %%A in ('wmic path Win32_UTCTime get /format:list') do (
set /a COUNT_all_wmic+=1
REM set "_%%A=%%B"
REM REM @echo\ A--[ %%A ] B--[ %%B ]
REM set /a COUNT_all+=1
set "Ax=%%A"
set "Bx=%%B"
REM echo\---- 'Ax=!Ax!' 'Bx=!Bx!'
REM :::: controllo se !Bx! è vuoto
if not !Bx!dummy==dummy (
REM :::: imposto solo !Bx! con valore
REM echo\:: valore valido !Ax!=!Bx!
set "!Ax!=!Bx!"
)
)
) else (
set "ERROR_Win32_UTCTime=wmic path Win32_UTCTime"
)
if defined Day (
if "%Day:~1,1%"=="" (
set "_UTC_DAY_IN_MONTH=0%Day%"
) else (
set "_UTC_DAY_IN_MONTH=%Day%"
)
)
if defined DayOfWeek (
if "%DayOfWeek:~1,1%"=="" (
set "_UTC_DAY_OF_WEEK=0%DayOfWeek%"
) else (
set "_UTC_DAY_OF_WEEK=%DayOfWeek%"
)
)
if defined Month (
if "%Month:~1,1%"=="" (
set "_UTC_MONTH_N=0%Month%"
) else (
set "_UTC_MONTH_N=%Month%"
)
)
if defined Year (
set _UTC_YEAR=%Year%
)
if defined Hour (
if "%Hour:~1,1%"=="" (
set "_UTC_HOUR=0%Hour%"
) else (
set "_UTC_HOUR=%Hour%"
)
)
if defined Minute (
if "%Minute:~1,1%"=="" (
set "_UTC_MINUTE=0%Minute%"
) else (
set "_UTC_MINUTE=%Minute%"
)
)
if defined Second (
if "%Second:~1,1%"=="" (
set "_UTC_SECOND=0%Second%"
) else (
set "_UTC_SECOND=%Second%"
)
)
set "_UTC_TIME=%_UTC_HOUR%:%_UTC_MINUTE%:%_UTC_SECOND%"
set "_UTC_DATE=%_UTC_DAY_IN_MONTH%/%_UTC_MONTH_N%/%_UTC_YEAR%"
set "_DATE_serial=%_YEAR%%_MONTH_N%%_DAY_IN_MONTH%"
REM echo\@@@ _DATE_serial=%_DATE_serial%
REM "wmic path win32_localtime get /format:list" non inizializza Milliseconds, non considera i centesimi di sec
REM PRENDO I VALORI DA %time% e %date%
REM PER VALORIZZARE _TIME_serial _DATE_serial ... .. . . . .
REM formato localizzato della data da "reg import myregPARETO-User.reg"
REM reg query "HKCU\Control Panel\International"
REM reg query "HKCU\Control Panel\International" /v sDecimal
set "_CURRENT_date=%date%§%time: =0%" & REM spazi vuoti diventano "0"
REM echo %_CURRENT_date%
for /f "tokens=1-8 delims=/:,§" %%a in ("%_CURRENT_date%") do (
REM echo %%cYEAR %%bMONTH %%aDAY
REM echo %%dHOURS %%eMIN %%fSEC %%gCENTs
REM set "_Year=%%c"
REM set "_Month=%%b"
REM set "_Day=%%a"
set "_HOUR=%%d"
set "_MINUTE=%%e"
set "_SECOND=%%f"
set "_SECOND_CENT=%%g"
REM set "_DATE_serial=%%c%%b%%a"
REM set "_TIME_serial=%%d%%e%%f%%g"
)
set "_CURRENT_date="
set "_TIME_serial=%_HOUR%%_MINUTE%%_SECOND%%_SECOND_CENT%"
set "_DATE=%_DAY_NAME% %Day% %_MONTH_NAME% %_YEAR%"
set "_TIME=%_HOUR%:%_MINUTE%:%_SECOND%,%_SECOND_CENT%"
REM echo\@@@_DATE==%_DATE%
REM echo\@@@_TIME==%_TIME%
REM echo "%~dpnx0" %1
echo\:: %THIS_file% %C__%%~1%C_0% .
echo\::
echo\:: valori restituiti... .. .
echo\::::::::::::::::::::::::::::::::::::::::
for /f "tokens=1,2 delims=^=" %%A in ( 'set _' ) do (
set Az=
set Bz=
set "Az=%%A"
set "Bz=%%B"
echo\:: my!Az!=!Bz!
)
echo\::::::::::::::::::::::::::::::::::::::::
echo\::%MSG:§=!LF!::%
call :FOOTER
set "N="
for /f "tokens=1,2 delims=^=" %%G in ('set _') do (
set /a N+=1
REM if "!N!" EQU "1" endlocal & endlocal
if "!N!" EQU "1" endlocal
set "my%%G=%%H"
)
set "N="
:my_date_end
:::::::::::::: my_date end ::::::::::::::::::::::::::::::::::::::::::
:::::::::::::: my_date end ::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::: my_ip4 :::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::: my_ip4 :::::::::::::::::::::::::::::::::::::::::::::::::::
goto :my_IP4_end
:my_IP4
REM setlocal enabledelayedexpansion
:MY_IP4_sos
if not "%~0"==":MY_IP4_sos" goto :my_ip4_sos_end
echo\::* %THIS_file% %C__%%~1%C_0% %C__%to_file%C_0% .
echo\::
echo\:: Con il parametro "to_file" l'output
echo\:: é salvato nel file "%USERPROFILE%\myIP4.txt"
echo\:: -se disponibile l'indirizzo ip4 imposta la var "my_ip4"
echo\:: esce con %%errorlevel%%=0
echo\:: -se non è disponibile l'indirizzo ip4
echo\:: esce con %%errorlevel%%^>=1
exit /b %ERROR%
:my