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?
I think you want:
if "%COMPUTERNAME%" == "VMMACHINE" goto VMMACHINE-DRIVES
Add "
to interpret %COMPUTERNAME%
as a string and ==
for string comparison.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.