Pregunta

I am trying to modify a current script that is executed as logon script by domain GPO. I have a special case where if users log into a specific machine on the domain, I need to map different network drives. Otherwise all other computers load the basic drive mappings.

I have tries both of the following without any success:

echo %COMPUTERNAME% | %SYSTEMROOT%\System32\find.exe /i "VMMACHINE" > nul:
if %ERRORLEVEL% EQU 0 goto VMMACHINE-DRIVES

and I have tried

if %COMPUTERNAME% EQU "VMMACHINE" goto VMMACHINE-DRIVES

Can anyone help?

¿Fue útil?

Solución

I think you want:

if "%COMPUTERNAME%" == "VMMACHINE" goto VMMACHINE-DRIVES

Add " to interpret %COMPUTERNAME% as a string and == for string comparison.

Otros consejos

The syntax will work if you have both sides enclosed in double quotes and the case is correct for the two strings.

if "%COMPUTERNAME%" EQU "VMMACHINE" goto :VMMACHINE-DRIVES

This should work also. Your code looked fine apart from the : on nul: which may work but is not often used. This uses the errorlevel operator && and the complement is ||

echo %COMPUTERNAME% | find.exe /i "VMMACHINE" > nul && goto :VMMACHINE-DRIVES
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top