Yeah, its frustrating. I have been playing with it for a while...even took a look at Daz's REALbasic version and I am still baffled about what is going wrong. I am getting an obscure error code of "-2147024893" vs. "-2147024894" which means pkeyconfig.xrm-ms is missing...so I am at a total loss.
PidGenXX is actually PidGenX Your code works perfectly fine. Here's the rest of the code to get info. It is in C# PHP: if (RetID == 0) { byte[] pidb = new byte[100]; for (int i = 0; i < pidb.Length; i++) { pidb[i] = Marshal.ReadByte(genPID, i); } byte[] core = new byte[1272]; for (int i = 0; i < core.Length; i++) { core[i] = Marshal.ReadByte(DPID4, i); } Encoding enc = Encoding.ASCII; string pid = enc.GetString(pidb).Replace("\0", ""); //PID string epid = enc.GetString(core, 8, 96).Replace("\0", ""); //Extendend PID string aid = enc.GetString(core, 136, 72).Replace("\0", ""); //Activation ID string edi = enc.GetString(core, 280, 40).Replace("\0", ""); //Edition string sub = enc.GetString(core, 888, 20).Replace("\0", ""); //SubType string lit = enc.GetString(core, 1016, 25).Replace("\0", ""); //License Type string lic = enc.GetString(core, 1144, 20).Replace("\0", ""); //License Channel string cid = epid.Substring(8, 3); //Crypto ID }
Thanks guy's Im still a toddler when it comes to vb coding, heres what i did using your codes, i added 9 textboxs and 1 button to a form with this code: PHP: Imports System.Runtime.InteropServices Imports System.Text Public Class Form1 Declare Auto Function PidGenX Lib "pidgenx.dll" (ByVal key As String, ByVal pkeyconfigLocation As String, ByVal mpcID As String, ByVal unknown As Integer, ByVal generatedPID As IntPtr, ByVal oldDigitalPID As IntPtr, ByVal digitalPID4 As IntPtr) As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim serial As String = TextBox1.Text TextBox1.Clear() If serial = Nothing Then Exit Sub Dim genPID As IntPtr = Marshal.AllocHGlobal(100) Marshal.WriteByte(genPID, 0, &H32) Dim clearGenPID As Integer = 0 For clearGenPID = 1 To 99 Marshal.WriteByte(genPID, clearGenPID, &H0) Next clearGenPID Dim oldPID As IntPtr = Marshal.AllocHGlobal(164) Marshal.WriteByte(oldPID, 0, &HA4) Dim clearOldPID As Integer = 0 For clearOldPID = 1 To 163 Marshal.WriteByte(oldPID, clearOldPID, &H0) Next clearOldPID Dim DPID4 As IntPtr = Marshal.AllocHGlobal(1272) Marshal.WriteByte(DPID4, 0, &HF8) Marshal.WriteByte(DPID4, 1, &H4) Dim clearDPID4 As Integer = 0 For clearDPID4 = 2 To 1271 Marshal.WriteByte(DPID4, clearDPID4, &H0) Next clearDPID4 Dim pkeyconfig As String = Environment.GetFolderPath(Environment.SpecialFolder.System) + "\spp\tokens\pkeyconfig\pkeyconfig.xrm-ms" Dim RetID As Integer = PidGenX(serial, pkeyconfig, "XXXXX", 0, genPID, oldPID, DPID4) If RetID = 0 Then TextBox3.AppendText("Valid") ElseIf RetID = -2147024894 Then TextBox1.AppendText("Error: pkeyconfig.xrm-ms is missing") ElseIf RetID = -2147024809 Then TextBox1.AppendText("Error: Invalid arguments") ElseIf RetID = -1979645695 Then TextBox1.AppendText("Error: Invalid key") Else TextBox1.AppendText("Error: Invalid key") End If If RetID = 0 Then Dim pidb As Byte() = New Byte(99) {} For i As Integer = 0 To pidb.Length - 1 pidb(i) = Marshal.ReadByte(genPID, i) Next Dim core As Byte() = New Byte(1271) {} For i As Integer = 0 To core.Length - 1 core(i) = Marshal.ReadByte(DPID4, i) Next Dim enc As Encoding = Encoding.ASCII Dim pid As String = enc.GetString(pidb).Replace(vbNullChar, "") TextBox2.Text = pid 'PID Dim epid As String = enc.GetString(core, 8, 96).Replace(vbNullChar, "") 'Extendend PID Dim aid As String = enc.GetString(core, 136, 72).Replace(vbNullChar, "") TextBox4.Text = aid 'Activation ID Dim edi As String = enc.GetString(core, 280, 40).Replace(vbNullChar, "") TextBox5.Text = edi 'Edition Dim [sub] As String = enc.GetString(core, 888, 20).Replace(vbNullChar, "") TextBox6.Text = [sub] 'SubType Dim lit As String = enc.GetString(core, 1016, 25).Replace(vbNullChar, "") TextBox7.Text = lit 'License Type Dim lic As String = enc.GetString(core, 1144, 20).Replace(vbNullChar, "") 'License Channel 'Crypto ID Dim cid As String = epid.Substring(8, 3) TextBox8.Text = cid End If End Sub End Class I think it worked Alfa
lolz...everyone can get it to work but not me. Thanks for the help guys, I appreciate it... BTW, it does not patter whether I call it PidGenX or PidGenXX, that is just the function name associated with the call...
@ HotCarl Actually it does, how else do you think the DLL will know what function to use without using "Alias" either? Code: Declare Auto Function OooItsCustom Lib "pidgenx.dll" Alias "PidGenX" (WindowsKey As String, PkeyPath As String, MPCID As String, UnknownUsage As IntPtr, GeneratedProductID As IntPtr, OldDigitalProductID As IntPtr, DigitalProductID As IntPtr) As Integer Or Code: Declare Auto Function PidGenX Lib "pidgenx.dll" (WindowsKey As String, PkeyPath As String, MPCID As String, UnknownUsage As IntPtr, GeneratedProductID As IntPtr, OldDigitalProductID As IntPtr, DigitalProductID As IntPtr) As Integer Anything else will likely throw an error of some sort.
Ok, I guess it does. That is odd, because I was getting the same error no matter what I called the function... Now it seems to work with how alpha has set it up. Too weird... It works now though. Thanks lol...all I did was change the name to PidGenX like you said. It just didnt seem like that would fix it since I got the same error when I named it PidGenX or PidGenXX...but it worked this time. Thanks Daz and alphawaves and PAYMYRENT EDIT: atleast now I know what the error code "-2147024893" means now...
In the name of open source, here is what I have now: Code: Declare Auto Function PidGenX Lib "pidgenx.dll" (ByVal one As String, ByVal two As String, ByVal three As String, ByVal four As Integer, ByVal five As IntPtr, ByVal six As IntPtr, ByVal seven As IntPtr) As Integer Private Sub Check_Product_Key() Dim serial As String = keyTextBox.Text keyTextBox.Clear() If serial = Nothing Then Exit Sub Dim genPID As IntPtr = Marshal.AllocHGlobal(100) Marshal.WriteByte(genPID, 0, &H32) Dim clearGenPID As Integer = 0 For clearGenPID = 1 To 99 Marshal.WriteByte(genPID, clearGenPID, &H0) Next clearGenPID Dim oldPID As IntPtr = Marshal.AllocHGlobal(164) Marshal.WriteByte(oldPID, 0, &HA4) Dim clearOldPID As Integer = 0 For clearOldPID = 1 To 163 Marshal.WriteByte(oldPID, clearOldPID, &H0) Next clearOldPID Dim DPID4 As IntPtr = Marshal.AllocHGlobal(1272) Marshal.WriteByte(DPID4, 0, &HF8) Marshal.WriteByte(DPID4, 1, &H4) Dim clearDPID4 As Integer = 0 For clearDPID4 = 2 To 1271 Marshal.WriteByte(DPID4, clearDPID4, &H0) Next clearDPID4 Dim pkeyconfig As String = Environment.GetFolderPath(Environment.SpecialFolder.System) + "\spp\tokens\pkeyconfig\pkeyconfig.xrm-ms" Dim RetID As Integer = PidGenX(serial, pkeyconfig, "XXXXX", 0, genPID, oldPID, DPID4) If RetID = 0 Then outputTextBox.AppendText("Valid") ElseIf RetID = -2147024893 Then outputTextBox.AppendText("Error: invalid function call") outputTextBox.AppendText("Must call 'PidGenX'") ElseIf RetID = -2147024894 Then outputTextBox.AppendText("Error: pkeyconfig.xrm-ms is missing") ElseIf RetID = -2147024809 Then outputTextBox.AppendText("Error: Invalid arguments") ElseIf RetID = -1979645695 Then outputTextBox.AppendText("Error: Invalid key") Else outputTextBox.AppendText("Error: Invalid key") End If End Sub Works great!
@ HotCarl Not sure why you are filling up with nulls, shouldn't be required (as shown via the code I posted). Also you have converted the integers to hex?
I guess it isnt necessary, was just clearing that memory space beforehand... I can remove it...it just worked perfectly now and I have been messing with it a while, so I didnt want to jinx it Yes, it does not matter whether you pass hex (as long as the hex represents the intended integer) or integer to the Marshaler, it will still do it's thing with the WriteByte() method. Thanks Daz, you have been very helpful. +1 repped you and PAYMYRENT. I tried to +rep alpha but then it said I gave out too much rep so I will have to do it tomorrow...
Understandable, I can be the same when something that was hard to get working isn't (a complex fiddly API) and then I get it working. It's just odd though since you said you looked at my source that gives them as integers You're welcome though, it was something I have been meaning to do but never got around to it. If you get it displaying the outputs feel free to drop it in the open source thread I created for it, I already wrote it in 2 languages but this would be a good addiction
Yeah...I looked at your source. It just kept on giving me errors no matter what I did, so I tried using hex, then zeroing everything else out beforehand to be sure I was not passing any bad data... I am just so glad it works now, I dont wanna mess with it anymore...
Just got back from class... Yeah, as soon as I get the function done the way I want it, I will be sure to post it in your open source thread. Thanks so much Daz, you are the man.
Updated OP with new v1.0.6 release of O7A. Temporarily disabled the Activation Backup until the next version until I can fix it... Wanted to release this version though because it incorporates the product key checker I wanted to incorporate in the last version. Enjoy, and as always, thanks for the suggestions, insights, and help.
Thank you As soon as I figure out to stop/pause the Software Protection Service "sppsvc" in order to restore activation (copy tokens.dat and pkeyconfig.xrm-ms that the user has previously backed-up to their original locations), then I will re-implement the activation backup. No matter what I do in my VB code, sppsvc will not die Code: Imports System.ServiceProcess Dim sppsvc As New ServiceController sppsvc.MachineName = "." sppsvc.ServiceName = "sppsvc" Dim status As String = sppsvc.Status.ToString 'Debug... 'Stop the service If status = "Running" Then sppsvc.Stop() status = sppsvc.Status.ToString 'Debug... '...code here to restore activation... If sppsvc.Status.ToString <> "Running" Then sppsvc.Start() Neither the .Stop() nor the .Pause() methods work on sppsvc, so I have to figure something else out...
Will this not work? Stop: PHP: Interaction.Shell("net stop sppsvc", AppWinStyle.MinimizedFocus, False, -1) Start: PHP: Interaction.Shell("net start sppsvc", AppWinStyle.MinimizedFocus, False, -1) Alfa
this is how i did it in token restore maybe you can use it Code: Dim sppsvcoff As New Process With sppsvcoff .StartInfo.FileName = "sc" .StartInfo.Arguments = " stop sppsvc" .StartInfo.UseShellExecute = True .StartInfo.CreateNoWindow = True .StartInfo.WindowStyle = ProcessWindowStyle.Hidden .Start() End With Do Until sppsvcoff.HasExited = True Application.DoEvents() System.Threading.Thread.Sleep(10) Loop Dim sppsvcon As New Process With sppsvcon .StartInfo.FileName = "sc" .StartInfo.Arguments = " start sppsvc" .StartInfo.UseShellExecute = True .StartInfo.CreateNoWindow = True .StartInfo.WindowStyle = ProcessWindowStyle.Hidden .Start() End With Do Until sppsvcon.HasExited = True Application.DoEvents() System.Threading.Thread.Sleep(10) Loop oh i almost forgot if you add a backgroundworker to the product key checker the ui will not freeze at least it didnt freeze when i tested it