Identify which partition is running the script

1

In the case of prompt of command we can use Windows environment variables to advance paths, such as:

echo %homedrive%

That will result in the attribute letter where sistema operacional was installed.

But to tell you the truth, I never thought of needing to know where Batch would be running as long as it hit the right path. What I want is to prevent the script from being run by the user by accessing another machine (mapped drive) or directly from a pen drive.

IF %HOMEDRIVE% == LOCAL_DA_SCRIPT (
   goto INICIAR
) ELSE (
   echo NAO PERMITIDO, ENCERRE O SCRIPT OU PECA AJUDA
   echo PARA O SUPORTE TECNICO
   pause>nul
)
    
asked by anonymous 03.03.2018 / 03:58

1 answer

2

I got the command cd since it is also a variable:

echo %cd%
rem Exemplo Windows XP: C:\Document and Settings\{currentuser}
rem Exemplo Windows 7: C:\Users\{currentuser}

To get only the partition:

echo %cd:~0,2%
rem Exemplo: C:

So to make the comparison:

IF %HOMEDRIVE% EQU %cd:~0,2% ( goto INICIAR ) ELSE ( goto ERRO )

:INICIAR
rem INICIO DO SCRIPT
pause

:ERRO
echo VOCE NAO PODE INICIAR O SCRIPT DE DENTRO
echo DO PENDRIVE OU MAPA VIRTUAL COPIE OS ARQUIVOS
echo PARA O SEU DESKTOP OU ALGUMA PASTADO SEU SISTEMA
pause>nul
exit
    
03.03.2018 / 20:28