Home > Software engineering >  Product key shower program batch file
Product key shower program batch file

Time:01-31

Me and my friend are trying to make a batch program that shows your product key written in a txt file. We have written three lines that execute the "wmic path SoftwareLicensingService get OA3xOriginalProductKey" which shows you the product key then creates a txt file to write the product key in and then a line to start the txt, but we can't figure out how to show the product key in the txt. We think we have to convert the response from the cmd into a variable to show the response in the txt but we don't know how to do it. These are the three lines of code that i've explained earlier:

@echo off
start /min cmd /k "wmic path SoftwareLicensingService get OA3xOriginalProductKey"
echo your product key is: %productkey%>Productkey.txt
start /max Productkey.txt

Could you please help us solve this issue? Thank you!

CodePudding user response:

As a result of my comment, I thought I'd offer a complete, and somewhat more reliable method, (or at least an alternative for when WMI does not provide the output you require):

@%SystemRoot%\System32\findstr.exe /V "^@" "%~f0" 1>"%Temp%\_%~n0.vbs"
@%SystemRoot%\System32\cscript.exe "%Temp%\_%~n0.vbs" //NoLogo 1>".\WinKey.txt"
@Del "%Temp%\_%~n0.vbs"
@Start %SystemRoot%\System32\notepad.exe ".\WinKey.txt"
@Exit /B
'GetWinKey
Set WshShell = CreateObject("WScript.Shell")
WScript.Echo DecodeKey(WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId"))

Function DecodeKey(Key)
   Const KeyOffset = 52
   i = 28
   Chars = "BCDFGHJKMPQRTVWXY2346789"
   Do
      Cur = 0
      x = 14
      Do
         Cur = Cur * 256
         Cur = Key(x   KeyOffset)   Cur
         Key(x   KeyOffset) = (Cur \ 24) And 255
         Cur = Cur Mod 24
         x = x -1
      Loop While x >= 0
      i = i -1
      KeyOutput = Mid(Chars, Cur   1, 1) & KeyOutput
      If (((29 - i) Mod 6) = 0) And (i <> -1) Then
         i = i -1
         KeyOutput = "-" & KeyOutput
      End If
   Loop While i >= 0
   DecodeKey = KeyOutput
End Function

CodePudding user response:

You can utilize powershell as part of your batch query:

@echo off
powershell (Get-WmiObject -query 'select * from SoftwareLicensingService').OA3xOriginalProductKey 1>Productkey.txt
echo your Product Key is: && type Productkey.txt
  •  Tags:  
  • Related