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

Author Topic: Wmic to Get windows product key  (Read 25348 times)

0 Members and 1 Guest are viewing this topic.

Abo-Zead

    Topic Starter


    Beginner
  • Thanked: 1
  • Experience: Familiar
  • OS: Windows 10
Wmic to Get windows product key
« 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,

Abo-Zead

    Topic Starter


    Beginner
  • Thanked: 1
  • Experience: Familiar
  • OS: Windows 10
Re: Wmic to Get windows product key
« Reply #1 on: October 18, 2023, 07:54:14 AM »
 :'(

Abo-Zead

    Topic Starter


    Beginner
  • Thanked: 1
  • Experience: Familiar
  • OS: Windows 10
Re: Wmic to Get windows product key
« Reply #2 on: November 29, 2023, 11:36:05 PM »
Is there anyone here who can help me to make this code more effective

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Wmic to Get windows product key
« Reply #3 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

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: Wmic to Get windows product key
« Reply #4 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