Jump to content

Need Script to copy data based on MAC address


Recommended Posts

My goal is to query the MAC of the PC's network card and then look it up in a simple text database file in the format of:

MAC,PCName,ProductKey,Path on each line.

Once it finds the MAC in the file 'mac.txt' it should Display the PC Name, Product Key and Path on the screen just for confirmation, then it should change the PC Name, and copy contents from the path specified to C:\ABR and finally run an .exe file in the C:\ABR folder.

Here's a sample of proposed mac.txt:

"00-E0-B8-80-59-06",PCLAB-01,CXXXT-988V6-GXXXX-8HP7R-H4KK3,%WINDIR%/Activation/PCLAB01
"00-E0-B8-80-58-B6",PCLAB-02,W8HKH-4XXXX-HVRFD-GXXXX-2XXVG,%WINDIR%/Activation/PCLAB02
"00-E0-B8-80-58-41",PCLAB-03,DXXXF-78W4P-V8CBY-TXXX9-QX6QW,%WINDIR%/Activation/PCLAB03
"00-E0-B8-80-58-AF",PCLAB-04,RDM42-GK4BV-X72YB-RQXP3-RXDJJ,%WINDIR%/Activation/PCLAB04
"00-E0-B8-80-57-15",PCLAB-05,TXQ6B-3XXXX-Y6RXP-YTGGW-QXXX3,%WINDIR%/Activation/PCLAB05
"00-E0-B8-80-58-0B",PCLAB-06,XXXXP-XXX8W-MXXXX-H99R7-XXX9D,%WINDIR%/Activation/PCLAB06

Here's my partial script that needs refining and the part to rename the PC and copy files...

ECHO Determining Machine Name and Product Key...
ECHO.
ping -n 3 localhost> NUL
For /f "usebackq delims=," %%i IN (`getmac /fo csv /nh`) do (
For /f "usebackq delims=, tokens=1-3" %%a IN (`type mac.txt`) DO If %%i EQU %%a (
Set strComputername=%%b
Set strProduct=%%c
Set strPath=%%d
) )
Echo Computer Name should be: %strComputername%
ping -n 2 localhost> NUL
Echo Product Key should be: %strProduct%
ECHO.
Echo Path to Activation files should be: %strPath%

Any help would be appreciated!

Link to comment
Share on other sites


Nevermind, I figured it out, I just had to think it through. But just in case this is usefull to anyone, here's the code:

@echo off && Mode 80,25 && Color F2
TITLE OEM Activation
ECHO.
ECHO Determining Machine Name and Product Key...
ECHO.
ping -n 3 localhost> NUL
For /f "usebackq delims=," %%i IN (`getmac /fo csv /nh`) do (
For /f "usebackq delims=, tokens=1-3" %%a IN (`type mac.txt`) DO If %%i EQU %%a (
Set strComputername=%%b
Set strProduct=%%c
) )
ping -n 3 localhost> NUL
Echo Computer Name should be: %strComputername%
ping -n 3 localhost> NUL
Echo Product Key should be: %strProduct%
ping -n 3 localhost> NUL
Echo Path to Activation files should be: C:\Windows\Activation\%strComputername%
Echo.
ping -n 3 localhost> NUL
Echo Activating Windows...
Echo.
copy c:\windows\Activation\%strComputername%\*.* c:\Windows\Activation\ /y
start /wait C:\Windows\Activation\activation_restore.exe --silent
ECHO Windows should now be OEM Activated!
Echo.
ping -n 4 localhost> NUL
EXIT

Of course you need a lookup table file called mac.txt in the format:

"00-E0-B8-80-59-06",PCLAB-01,CXXXT-988V6-GXXXX-8HP7R-H4KK3

" MAC ID ", PC Name , Product Key

And you should have a folder in Windows called 'activation' containing subfolders with each computer's name. These subfolders should contain the OEM activations files (backup-cert.xrm-ms, backup-key.txt) from the respective computer. The root folder (Activation) should have the 'activation_restore.exe' file. By the way, the activation routine here is specifically for Vista OEM edition.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...