Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Running a batch file in specific workstations  (Read 44696 times)

0 Members and 1 Guest are viewing this topic.

Abo-Zead

    Topic Starter


    Beginner
  • Thanked: 1
  • Experience: Familiar
  • OS: Windows 10
Running a batch file in specific workstations
« on: October 01, 2022, 03:32:56 AM »
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
Code: [Select]
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



    Hopeful
  • Thanked: 42
  • Experience: Expert
  • OS: Windows 10
Re: Running a batch file in specific workstations
« Reply #1 on: October 01, 2022, 09:47:05 AM »
Hi  ;)
Give a try for this batch :
Code: [Select]
@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

    Topic Starter


    Beginner
  • Thanked: 1
  • Experience: Familiar
  • OS: Windows 10
Re: Running a batch file in specific workstations
« Reply #2 on: October 01, 2022, 02:36:33 PM »
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

    Topic Starter


    Beginner
  • Thanked: 1
  • Experience: Familiar
  • OS: Windows 10
Re: Running a batch file in specific workstations
« Reply #3 on: October 05, 2022, 01:49:45 PM »
Thanks Hackoo for your help but unfortunately it didn't work with me
but I tried to write a simple code below
Code: [Select]
::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