1 line
12 KiB
JSON
1 line
12 KiB
JSON
{"uuid":"a480e4bf-a37e-4782-a936-2c49332863ce","slug":"les-clefs-de-produits-microsoft","title":"Récupérer la clé produit Microsoft Windows","author":"cedric@abonnel.fr","published":true,"published_at":"2020-04-17 18:06:06","created_at":"2020-04-17 18:06:06","updated_at":"2020-04-17 18:06:06","revisions":[],"cover":"","files_meta":[],"external_links":[],"seo_title":"","seo_description":"","og_image":"","category":"Informatique","content":"# Récupérer la clé produit Microsoft Windows\n\nUn petit script permet de récupérer les informations concernant votre licence.\n\nCopier ce code dans un fichier **viewpk.wsf**. L'extension du fichier est importante.\n\n```VBS\n<job>\n<runtime>\n<description author=\"jcb\">\n---\nCe script en ligne de commande détermine, à partir des clefs \n\"...\\...\\DigitalProductID\", la valeur de la \"ProductKey\" \n(clef de produit) sous la forme 5x5 :\n \txxxxx-xxxxx-xxxxx-xxxxx-xxxxx\nChaque caractère fait partie de l'ensemble BCDFGHJKMPQRTVWXY2346789\nPar défaut il examine le \"DigitalProductID\" de Windows, mais il est\ncapable de trouver et analyser ces clefs pour tous les produits Microsoft.\n(Office, FrontPage, Visio, ...)\nCe script affiche aussi la \"RAWkey\" correspondante (valeur binaire,\nexprimée en hexadécimal, en notations \"little endian\" et \"big endian\")\nInversement, il sait aussi convertir une RAWKey en ProductKey.\n\nEnfin il sert à calculer (partiellement) le ProductID à partir \nde la ProductKey ou de la RAWkey. \n\nJCB © 2005\n---\n</description>\n<named name = \"c\" \n\thelpstring = \"Nom NetBIOS d'ordinateur \n Si ce paramètre est absent, on retient l'ordinateur local\"\n\ttype = \"string\" \n\tmany=\"false\"\n\trequired = \"false\" />\n<named\n\tname = \"e\"\n\thelpstring = \"Commutateur indiquant le type de l'entrée :\n R : clef de la branche HKLM de la base de registres (software\\...)\n \t (valeur par défaut)\n T : Recherche de toutes les clefs 'DigitalProductID'\t\t \n P : ProductKey \n HL : chaine hexadécimale de ProductKey (RAW key)\n en notation Little Endian (octets de poids faibles en 1ers)\n HB : chaine hexadécimale de ProductKey (RAW key)\n en notation Big Endian (octets de poids forts en 1ers)\"\n\ttype = \"string\" \n\trequired = \"false\" />\n<unnamed name = \"v\" \n\thelpstring = \"Suivant la valeur du commutateur précédent\n 1. clef de la branche HKLM\n NB: ne pas indiquer ni le préfixe (HKLM) \n ni le nom de l'entrée (DigitalProductID)\n (à encadrer par des guillemets si le nom contient des espaces)\n Si ce paramètre est absent, on retient la clef :\n \\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\n 1. ProductKey sous la forme xxxxx-xxxxx-xxxxx-xxxxx-xxxxx\n 1. chaine hexadécimale (RAW Key)\"\n\ttype = \"string\" \n\tmany=\"false\"\n\trequired = \"false\" />\n<example>\nExemples : \n---\n viewpk \n affiche la ProductKey de Windows\n\n viewpk /e:T /c:GRANDBASSAM\n affiche les ProductKey de tous les produits Microsoft\n installés sur l'ordinateur \"GRANDBASSAM\"\n\n viewpk /c:SASSANDRA /e:R \"SOFTWARE\\Microsoft\\Office\\11.0\\Registration\\{9017040C-6000-11D3-8CFE-0150048383C9}\" \n affiche la ProductKey de FrontPage 2003 sur l'ordinateur \"SASSANDRA\"\n\n viewpk /e:HL 8063EFA7DE99C873A76B9F97FCD303\n affiche la ProductKey à partir de cette chaine Little Endian\n\n viewpk /e:P FCKGW-RHQQ2-YXRKT-8TG6W-2B7Q8 \n affiche la RAWKey à partir de cette ProductKey\n \nDans tous les cas, il est affiché :\n1. la RAWKey en notation Little Endian \n1. la RAWKey en notation Big Endian \n1. les 2 nombres centraux du productID\n (algorithme valable seulement pour Windows)\n---\n</example>\n</runtime>\n<script language=\"VBScript\">\n\nconst HKEY_LOCAL_MACHINE = &H80000002\nCharSet24 = array(\"B\",\"C\",\"D\",\"F\",\"G\",\"H\",\"J\",\"K\",\"M\",\"P\",\"Q\",\"R\",\"T\",\"V\",\"W\",\"X\",\"Y\",\"2\",\"3\",\"4\",\"6\",\"7\",\"8\",\"9\")\n' 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23\n' 0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15 16 17\nPrefix=\"HKLM\\\"\nKeyDef=\"software\\Microsoft\\Windows NT\\CurrentVersion\"\nEntry1=\"DigitalProductId\"\nEntry2=\"ProductID\"\nEntry3=\"ProductName\"\nSW_SHOWNORMAL=1\nDim shell, fso, net, args, Buffer, PK(25),Result(15), Key\nSet shell = WScript.CreateObject(\"WScript.Shell\")\nSet net = Wscript.CreateObject(\"WScript.Network\")\nSet args = Wscript.Arguments\nSet fso = WScript.CreateObject(\"Scripting.FileSystemObject\")\nnbargs=args.count\nTestHost false\n\nSet Named = WScript.Arguments.Named\nSet UnNamed = WScript.Arguments.UnNamed\nnu=UnNamed.count\nIf named.Exists(\"c\") Then Computer=lcase(named.Item(\"c\")) else Computer=lcase(net.ComputerName)\nSet oReg=GetObject(\"winmgmts:{impersonationLevel=impersonate}!\\\\\" & Computer & \"\\root\\default:StdRegProv\")\nOn Error Resume Next\njob=\"r\"\nIf named.Exists(\"e\") Then job=lcase(named.Item(\"e\"))\nSelect Case job\n'Analyse clef BDR\n\tCase \"r\" \n\t\tBDR=true\n\t\tIf nu=0 Then Key=KeyDef else Key=UnNamed(0)\t\t\n\t\tcoderet=oReg.GetBinaryValue(HKEY_LOCAL_MACHINE, Key, Entry1, Buffer)\n\t\tIf CodeRet<>0 Then\n\t\t\tWscript.echo \"Erreur BDR\"\n\t\t\tWscript.quit\t\n\t\t\tEnd If\n\t\tFor index = 0 to 14\n\t\t\tPK(index)=Buffer(index+&H34)\n\t\t\tNext\n\t\tPrintResult\n'Enumération de toutes les clefs\n\tCase \"t\"\n\t\tOn error goto 0\n\t\tBDR=true\n\t\trep=shell.Popup(\"Veuillez patienter SVP.\" & VBCRLF & \"La recherche des clefs peut prendre un certain temps\", _\n\t\t3, \"Clefs de produits Microsoft sur \" & Computer,65) \n\t\tIf rep=2 Then Wscript.quit\n\t\tExploreKey(\"Software\\Microsoft\")\n'Analyse de RAWKey ou ProductKey\n\tCase \"hl\",\"hb\",\"p\"\n\t\tBDR=false\n\t\tIf nu=0 Then \n\t\t\tWScript.Arguments.ShowUsage\n\t\t\tWScript.Quit\n\t\t\tend if\n\t\tKey=UnNamed(0)\n\t\tSelect Case job\n'Little Endian\n\t\t\tCase \"hl\" \n\t\t\t\ti1=0\n\t\t\t\ti2=14\n\t\t\t\ts=1\n'Big Endian\n\t\t\tCase \"hb\"\n\t\t\t\ti1=14\n\t\t\t\ti2=0\n\t\t\t\ts=-1\n\t\t\tCase \"p\"\n\t\t\tEnd Select\n\t\tIf job<>\"p\" Then\n'RAWKey\n\t\t\tj=0\n\t\t\tFor index = i1 To i2 Step s\n\t\t\t\tSbyte=\"&H\" & Mid(Key,index*2+1,2)\n\t\t\t\tPK(j)=CInt(Sbyte)\n\t\t\t\tj=j+1\n\t\t\t\tNext\n\t\t\tPrintResult\n\t\tElse\n'ProductKey\n\t\t\tj=0\n\t\t\tFor index = 1 To len(Key)\n'\tconversion des caractères en base24\n\t\t\t\tv=valueB24(Mid(Key,index,1)) \n\t\t\t\tIf v>=0 Then\n\t\t\t\t\tPK(j)=v\n\t\t\t\t\tj=j+1\n\t\t\t\t\tEnd If\t\n\t\t\t\tNext\n\t\t\tIf j<>25 Then\n\t\t\t\tWScript.Arguments.ShowUsage\n\t\t\t\tWScript.Quit\t\t\n\t\t\t\tEnd If\n'\tconversion en binaire\n\t\t\tFor i = 0 To 14 \n\t\t\t\tResult(i)=0\n\t\t\t\tNext\n\t\t\tNumDigits=24\n\t\t\tResLen=15\n\t\t\tFor i= 0 To 24\n\t\t\t\tAux=PK(i)\n\t\t\t\tm=0\n\t\t\t\tDo\n\t\t\t\t\tAux=Result(m)*NumDigits + Aux\n\t\t\t\t\tResult(m)= Aux AND 255\n\t\t\t\t\tm=m+1\n\t\t\t\t\tAux=int(Aux/256)\n\t\t\t\t\tLoop Until m >= ResLen\n\t\t\t\tNext\n\t\t\tFor i = 0 To 14\n\t\t\t\tPK(i)=Result(i)\n\t\t\t\tNext\n\t\t\tPrintResult\n\t\t\tEnd If\n\tCase else \n\t\t WScript.Arguments.ShowUsage\n\t WScript.Quit\n\tEnd Select\n\nWscript.quit\n'--------------------------------------------------------------------\n'Exploration récursive de la BDR \n'recherche des entrées \"DigitalProductId\"\nSub ExploreKey(CurKey)\ncoderet=oReg.GetBinaryValue(HKEY_LOCAL_MACHINE,CurKey,Entry1,Buffer)\nIf CodeRet=0 Then\n'Entrée trouvée. Extraction RAWKey\n\tFor index = 0 to 14\n\t\tPK(index)=Buffer(index+&H34)\n\t\tNext\n\tKey=CurKey\t\t\t\n\tPrintResult\n\tExit Sub\n\tend if\nDim arrSubKeys\n'Enumération des sous-clefs\ncoderet=oReg.EnumKey(HKEY_LOCAL_MACHINE,CurKey,arrSubKeys)\nIf codeRet=0 Then\n\tIf IsArray(arrSubKeys) Then\n\t\tFor Each subkey In arrSubKeys\n\t\t\tExploreKey(CurKey & \"\\\" & subkey)\n\t\t\tNext\n\t\tEnd If\n\tend if\nEnd Sub\n'--------------------------------------------------------------------\nSub PrintResult\nRAWKeyBE=\"\"\nRAWKeyLE=\"\"\n'Affichage des RAWkeys en Little Endian et en Big Endian\nFor index = 0 to 14\n\tRAWKeyBE=hexa(PK(index)) & RAWKeyBE \n\tRAWKeyLE=RAWKeyLE & hexa(PK(index))\n\tNext\nS=\"\"\n'Calcul du ProductID (algorithme valable seulement pour Windows) \nFor index = 0 To 3 \n\tCurByte=PK(Index)\n\tIf index = 3 Then CurByte=CurByte and &H7F\n\tS=Hexa(CurByte) & S \n\tnext\nPID=int[^note: \"&H\" &S) /2)\nSPID=CStr(PID)\nWhile len(SPID)<9\n\tSPID=\"0\" & SPID\n\tWend\nSPID1=left(SPID,3)\nSPID2=mid(SPID,4)\nsigma=0\nFor i = 1 To len(SPID2)\n\tsigma=sigma+Asc(mid(SPID2,i,1]-48\n\tNext\nm=7-sigma mod 7\nSPID=SPID1 & \"-\" & SPID2 & m\n'Conversion RAWKey en ProductKey\nS=\"\"\nFor i = 24 To 0 Step -1\n\tr = 0\n\tFor j = 14 To 0 Step -1\n\t\tr = r * 256 Xor PK(j)\n\t\tPK(j) = Int(r/24)\n\t\tr = r Mod 24\n\t\tNext\n\tS=CharSet24(r) & S \n\tIf i Mod 5 = 0 And i <> 0 Then S=\"-\" & S\n\tNext\nmsg=VBCRLF \nIf BDR Then\tmsg=msg & \"HKLM\\\" & Key & \"\\\" & Entry1\nmsg=msg & VBCRLF & \"ProductKey = \" & S\nmsg=msg & VBCRLF & \"RAWKey Big Endian = \" & RAWKeyBE\nmsg=msg & VBCRLF & \"RAWKey Little Endian = \" & RAWKeyLE\n' Calcul du ProductID (central)\n' NB : valable seulement pour Windows, l'algorithme semblant \n' être différent pour les autres produits\nmsg=msg & VBCRLF & \"ProductID calculé = \" & \"xxxxx-\" & SPID & \"-xxxxx\"\nIf BDR Then\n\tcoderet=oReg.GetStringValue(HKEY_LOCAL_MACHINE, Key, Entry2, SPID)\n\tIf Coderet=0 Then msg=msg & VBCRLF & \"ProductID BDR = \" & SPID\n\tcoderet=oReg.GetStringValue(HKEY_LOCAL_MACHINE, Key, Entry3, SPID)\n\tIf Coderet=0 Then msg=msg & VBCRLF & \"ProductName = \" & SPID\n\tEnd If\nWscript.echo msg\nEnd Sub\n'--------------------------------------------------------------------\n'Affichage hexadécimal d'un octet avec 0 non significatif éventuel\nFunction hexa(n)\nch=hex(n)\nIf len(ch)<2 then ch=\"0\" & ch\nhexa=ch\nEnd Function\n'--------------------------------------------------------------------\nFunction valueB24(c)\nvalueB24=-1\nc=ucase(c)\nFor i = 0 To 23\n\tIf c=CharSet24(i) Then\n\t\tvalueB24=i\t\t\n\t\texit for\n\t\tEnd If\n\tNext\nEnd Function\n'--------------------------------------------------------------------\n'Sous-programme de test du moteur\n'Vu les sorties générées, c'est CSCRIPT (et non pas WSCRIPT)\n'qui doit être utilisé de préférence\nSub TestHost(force)\ndim rep\nstrappli=lcase(Wscript.ScriptFullName)\nstrFullName =lcase(WScript.FullName)\ni=InStr(1,strFullName,\".exe\",1)\nj=InStrRev(strFullName,\"\\\",i,1)\nstrCommand=Mid(strFullName,j+1,i-j-1)\nif strCommand<>\"cscript\" then\n\tIf force then \n\t\tInit=\"Ce script doit être lancé avec CSCRIPT\"\n\tElse\n\t\tInit=\"Il est préférable de lancer ce script avec CSCRIPT\"\n\t\tEnd If\n\trep=MsgBox(Init & VBCRLF & _\n\t\"Cela peut être rendu permanent avec la commande\" & VBCRLF & _\n\t\"cscript *H:CScript *S /Nologo\" & VBCRLF & _\n\t\"Voulez-vous que ce soit fait automatiquement?\", _\n\tvbYesNo + vbQuestion,strappli)\n\tif rep=vbYes then \n\t\tnomcmd=\"setscript.bat\"\n\t\tSet ficcmd = fso.CreateTextFile(nomcmd)\n\t\tficcmd.writeline \"@echo off\"\n\t\tficcmd.writeline \"cscript *H:CScript *S /Nologo\"\n\t\tficcmd.writeline \"pause\"\n\t\tparams=\"\"\n\t\tFor i = 0 To nbargs-1 \n\t\t\tparams=params & \" \" & args(i)\n\t\t\tnext\n\t\tficcmd.writeline chr(34) & strappli & chr(34) & params\n\t\tficcmd.writeline \"pause\"\n\t\tficcmd.close\n\t\tshell.Run nomcmd, SW_SHOWNORMAL,true\n\t\tforce=true\n\t\tend if\n If force then WScript.Quit\n\tend if\nend sub\n'--------------------------------------------------------------------\n</script>\n</job>\n```\n\nDans une fenêtre DOS, positionnez vous dans le dossier où le fichier **viewpk.wsf**, puis exécutez la commande :\n```DOS\ncscript viewpk.wsf\n```\n\nLe résultat devrait de la forme suivante :\n\n```DOS\nProductKey = FXXXP-4DFJD-GXXX9-VJXX7-HXXX2\nRAWKey Big Endian = 00D62D7BA2A0036A00BF64300C49D9\nRAWKey Little Endian = 0049FC396000236A83A0027B2DD600\nProductID calculé = xxxxx-486-4100400-xxxxx\nProductID BDR = 00400-OEM-0092002-00006\nProductName = Windows 7 Ultimate\n```\n\n## + d'infos\n- <http://jc.bellamy.free.fr/fr/systeme.html#clefsproduitsMS>","featured":false,"tags":[]} |