Computer Hope

Microsoft => Microsoft DOS => Topic started by: Abo-Zead on October 06, 2023, 08:38:34 PM

Title: Wmic to Get windows product key
Post by: Abo-Zead on October 06, 2023, 08:38:34 PM
Hi All,

I hope this message finds you in good spirits.

Recently, I've been looking into a way to remotely fetch Windows product keys for multiple workstations using batch file. Through my research, I came across the WMIC command, which seems good. and need to extract these keys from a list of computer names in a text file and save them to an output text file, all in one go, but unfortunately it didn't work
here is the code that i used :

Code: [Select]
@echo off
setlocal EnableDelayedExpansion
set "inputFile=input.txt"
set "outputFile=output_WPK.txt"

for /f "delims=" %%A in (%inputFile%) do (
    set "computerName=%%A"
    echo Product Key for !computerName!: >> %outputFile%
    for /f "tokens=2 delims==" %%I in ('wmic /node:!computerName! path softwarelicensingservice get OA3xOriginalProductKey /value') do (
        echo %%I >> %outputFile%
    )
    echo. >> %outputFile%
)

echo Product Keys extracted and saved to %outputFile%
pause

And here the output data below

Code: [Select]
Product Key for C3I-PC1:
ECHO is off.
Product Key for C3I-PC2:
ECHO is off.
Product Key for C3I-PC3:
ECHO is off.

And i want to exetract the Computer name and product key Only under each other like that
Code: [Select]
[ ComputerName : Windows Product Key]
[ ComputerName : Windows Product Key]

Your expertise in this area would be immensely helpful. If you have any tips, best practices, or perhaps even a sample script, I'd be extremely grateful.
Thank you so much for your efforts

Warm regards,
Title: Re: Wmic to Get windows product key
Post by: Abo-Zead on October 18, 2023, 07:54:14 AM
 :'(
Title: Re: Wmic to Get windows product key
Post by: Abo-Zead on November 29, 2023, 11:36:05 PM
Is there anyone here who can help me to make this code more effective
Title: Re: Wmic to Get windows product key
Post by: Geek-9pm on November 30, 2023, 01:18:51 PM
Your can buy something that might help you.
If your could just do it with code , Microsoft would stop it.
Search for a product key on Google. You might f ind one under$40.
Or talk to Microsoft support. In rare cases they will let you have it free.  :o
Look e for:
...how to get windows 10 for free
Title: Re: Wmic to Get windows product key
Post by: Squashman on February 02, 2024, 04:49:16 PM
1) Do not use variable names that are already system variables. computername is a system variable.
2) You do not need to assign %%A to a variable.  Just use %%A.

Other than that your code seems fine.  Works on my computer.
First thing I would do to troubleshoot is run this line of code with one computer to make sure you are getting output.
Code: [Select]
wmic /node:{Computer1} path softwarelicensingservice get OA3xOriginalProductKey /value