Running a batch file in specific workstations

Started by Abo-Zead, October 01, 2022, 03:32:56 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Abo-Zead

Hi All
Thanks in advance for Anyone help
I'm trying to  make my bat file run on specific workstations by comparing the workstation MAC address with inserted MACs inside my batch then Run my Bat if the workstation MAC address is one of them or EXIT if the workstation MAC address is not
but unfortunately, it didn't work for me also I tried to test this bat file for my localhost but also it didn't work, Can anyone help me and correct my code, please?
Here is my code below

for /f "tokens=3 delims=," %%i in ('getmac /s localhost /v /nh /fo csv') do Set "MyMAC=%%~i"
echo %MyMAC%
pause
if /I "%MyMAC%"==8C-DC-D4-42-F8-12( GOTO START_APP )else
if /I "%MyMAC%"==8C-DC-D4-42-53-73( GOTO START_APP )else
if /I "%MyMAC%"==8C-DC-D4-42-F8-A4( GOTO START_APP )else
if /I "%MyMAC%"==8C-DC-D4-42-F8-98( GOTO START_APP )else
( Echo "The program cannot be run on this workstation" & Timeout /t 3 /NoBreak >nul & GOTO EXIT )
:START_APP
Echo This workstation is Authorized to run this App
pause

:EXIT
exit

Hackoo

Hi  ;)
Give a try for this batch :
@echo off
Title Get MAC ADDRESS and Compare it
SET Auth_MAC=8C-DC-D4-42-F8-12,8C-DC-D4-42-53-73,8C-DC-D4-42-F8-A4,8C-DC-D4-42-F8-98
SetLocal EnableDelayedExpansion
@for /f "tokens=3 delims=," %%i in ('getmac /v /nh /fo csv ^| find /I "Wi-Fi"') do Set "MyMAC=%%~i" (
echo/ MAC ADDRESS : [%MyMAC%] & Timeout /T 3 /NoBreak>nul
@for %%M in (%Auth_MAC%) do (
set "Auth_M=%%M"
if /I [!MyMAC!]==[!Auth_M!] (echo/ !Auth_M! OK && GOTO START_APP)
)
)
Color 0C & echo/ & Echo/ "The program cannot be run on this workstation" & Timeout /t 5 /NoBreak>nul & EXIT
::------------------------------------------------------------------------------------------
:START_APP
color 0A & echo/
Echo/ This workstation is Authorized to run this App
Timeout /T 5 /NoBreak>nul
Exit /B 0
::------------------------------------------------------------------------------------------

Abo-Zead

Thanks, Hackoo for help as always you are the man who can help
I'll try to test this your code in my workplace tomorrow and then feedback to you with the result

Abo-Zead

Thanks Hackoo for your help but unfortunately it didn't work with me
but I tried to write a simple code below

::Check MAC Address
for /f "tokens=3 delims=," %%i in ('getmac /s localhost /v /nh /fo csv') do Set "MyMAC=%%~i"
if /i %MyMAC%==8C-DC-D4-42-F8-12 GOTO START_APP
if /i %MyMAC%==8C-DC-D4-42-53-73 GOTO START_APP
if /i %MyMAC%==8C-DC-D4-42-F8-A4 GOTO START_APP
if /i %MyMAC%==8C-DC-D4-42-F8-98 GOTO START_APP
Color 0C & echo "The program cannot be run on this workstation" & Timeout /t 5 >nul & GOTO EXIT
pause
:START_APP
color 0A
Echo/ This workstation is Authorized to run this App
Timeout /T 5 /NoBreak>nul


And this code works for me
Many thanks again for your help