[UNSUPPORTED] Open 7 act*vator by Nononsence [revised by HotCarl] ;-)

Discussion in 'Windows 7' started by HotCarl, Oct 29, 2009.

  1. HotCarl

    HotCarl MDL Addicted

    Jul 21, 2009
    831
    16
    30
    #61 HotCarl, Nov 7, 2009
    Last edited by a moderator: Apr 20, 2017
    (OP)

    Right on, that is what I thought...thanks for the confirmation. :)
    I did something similar for that as well:
    Code:
    Using c1 As New Process
        c1.StartInfo.FileName = "cmd.exe"
        c1.StartInfo.Arguments = "/c takeown /f " & tokens & " && icacls " & tokens & " /grant *S-1-1-0:F"
        c1.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        Try
            c1.Start()
        Catch exc1 As Exception
            eventMessage = appName & " Error: " & exc1.Message
            eventMessage2 = appName & " was unable to take ownership of tokens.dat. Location of tokens.dat: " & tokens & " (See: Restore_Activation(2))"
            eventMessage3 = "Process used: " & c1.StartInfo.FileName.ToString & "; Arguements passed: " & c1.StartInfo.Arguments.ToString
            LogError(eventMessage, eventMessage2, eventMessage3)
        End Try
        c1.WaitForExit()
    End Using
    
    ...and then for pkeyconfig.xrm-ms as well...
    
    :)
     
  2. Hazar

    Hazar MDL Guru

    Jul 29, 2009
    2,507
    456
    90
    Looks good!

    I usually put the full paths in cmd lines, it prevents confusion but if that works then great.

    EDIT:
    Why not just chain on the pkeyconfig to it aswell with & and just have a section to take ownership.

    you will execute the native cmd line so no need to worry about syswow redirection. I also think on a 64bit system you need to change the pkeyconfig in syswow64 too
     
  3. HotCarl

    HotCarl MDL Addicted

    Jul 21, 2009
    831
    16
    30
    #63 HotCarl, Nov 7, 2009
    Last edited: Nov 7, 2009
    (OP)

    Yeah, the system's path determines where it will look for the cmd.exe, and since c:\windows and c:\window\system32 are always part of the Windows path, it will be ok... I probably should put the path in there though just in case someone alters their environmental variables...never know I guess...

    EDIT: tokens and pkey locations are determined by:
    Public WinDir As String = My.Application.GetEnvironmentVariable("WINDIR")
    Public tokens As String = WinDir & "\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform\tokens.dat"
    Public pkeyconfig As String = Environment.GetFolderPath(Environment.SpecialFolder.System) & "\spp\tokens\pkeyconfig\pkeyconfig.xrm-ms"

    ...so I am sure to get the right locations according to windows.

    Chaining the takeown and icacls commands for tokens and pkey together is probably a wise idea though, would save a few seconds perhaps over having 2 separate commands for each. :D
     
  4. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,460
    420
    60
    shoving all those commands together like that makes it harder to debug then ppl start asking why it doesnt work for them then you have to tell them its part of the takeownership process but you dont know what part for sure :p
     
  5. HotCarl

    HotCarl MDL Addicted

    Jul 21, 2009
    831
    16
    30
    #65 HotCarl, Nov 7, 2009
    Last edited by a moderator: Apr 20, 2017
    (OP)
    True, the way I have it now, I can tell where the error came from... Good point, I think I will leave it. :)

    Here is the entire function:

    Code:
        Public Function Restore_Activation() As Boolean
            '==================================================================================
            'restores the previously backed-up Windows 7 activation files...if there are any.
            '==================================================================================
    
            busy = True
            Me.Cursor = Cursors.WaitCursor
    
            Using p1 As New Process
                p1.StartInfo.FileName = "cmd.exe"
                p1.StartInfo.Arguments = "/c net stop sppsvc /y"
                p1.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
                Try
                    p1.Start()
                Catch exp1 As Exception
                    'MessageBox.Show(exp1.Message)
                    eventMessage = appName & " Error: " & exp1.Message
                    eventMessage2 = appName & " was unable to stop the Software Protection Platform service 'sppsvc'. (See: Restore_Activation(1))"
                    eventMessage3 = "Process used: " & p1.StartInfo.FileName.ToString & "; Arguements passed: " & p1.StartInfo.Arguments.ToString
                    LogError(eventMessage, eventMessage2, eventMessage3)
                End Try
                p1.WaitForExit()
            End Using
    
            'Code to take ownership of tokens.dat and pkeyconfig.xrm-ms...
            Using c1 As New Process
                c1.StartInfo.FileName = "cmd.exe"
                c1.StartInfo.Arguments = "/c takeown /f " & tokens & " && icacls " & tokens & " /grant *S-1-1-0:F"
                c1.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
                Try
                    c1.Start()
                Catch exc1 As Exception
                    'MessageBox.Show(exc1.Message)
                    eventMessage = appName & " Error: " & exc1.Message
                    eventMessage2 = appName & " was unable to take ownership of tokens.dat. Location of tokens.dat: " & tokens & " (See: Restore_Activation(2))"
                    eventMessage3 = "Process used: " & c1.StartInfo.FileName.ToString & "; Arguements passed: " & c1.StartInfo.Arguments.ToString
                    LogError(eventMessage, eventMessage2, eventMessage3)
                End Try
                c1.WaitForExit()
            End Using
            Using c2 As New Process
                c2.StartInfo.FileName = "cmd.exe"
                c2.StartInfo.Arguments = "/c takeown /f " & pkeyconfig & " && icacls " & pkeyconfig & " /grant *S-1-1-0:F"
                c2.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
                Try
                    c2.Start()
                Catch exc2 As Exception
                    'MessageBox.Show(exc2.Message)
                    eventMessage = appName & " Error: " & exc2.Message
                    eventMessage2 = appName & " was unable to take ownership of pkeyconfig.xrm-ms. Location of pkeyconfig.xrm-ms: " & pkeyconfig & " (See: Restore_Activation(3))"
                    eventMessage3 = "Process used: " & c2.StartInfo.FileName.ToString & "; Arguements passed: " & c2.StartInfo.Arguments.ToString
                    LogError(eventMessage, eventMessage2, eventMessage3)
                End Try
                c2.WaitForExit()
            End Using
    
            Try
                System.IO.File.SetAttributes(tokens, IO.FileAttributes.Normal)
                System.IO.File.SetAttributes(pkeyconfig, IO.FileAttributes.Normal)
                System.IO.File.Copy(tokensReplaceDestination & "tokens.dat", tokens, True)
                System.IO.File.Copy(tokensReplaceDestination & "pkeyconfig.xrm-ms", pkeyconfig, True)
    
                'Code to restore product key via SLMGR.VBS
                BackupWindowsActivation.restoreLabel.Text = "Restoring Backed-up Windows 7 Product Key..."
                Dim SLMGR As New Process, restoreKey As String
                SLMGR.StartInfo.CreateNoWindow = True
                SLMGR.StartInfo.UseShellExecute = False
                SLMGR.StartInfo.RedirectStandardError = True
                SLMGR.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
                SLMGR.StartInfo.FileName = "cscript"
    
                restoreKey = BackupWindowsActivation.restoreProductKeyTextBox.Text
                SLMGR.StartInfo.Arguments = (" //NOLOGO " & WinDir & "\System32\slmgr.vbs -ipk " & restoreKey)
                Me.Cursor = Cursors.WaitCursor
                SLMGR.Start()
    
                Do Until SLMGR.HasExited
                    Application.DoEvents()
                    System.Threading.Thread.Sleep(50)
                Loop
    
                Me.Cursor = Cursors.Default
    
            Catch ex As Exception
                'MsgBox(appName & " failed to restore tokens.dat and pkeyconfig.xrm-ms!", , "Error: Restore failed!")
                eventMessage = appName & " Error: " & ex.Message
                eventMessage2 = appName & " failed to restore tokens.dat and/or pkeyconfig.xrm-ms correctly. (See: Restore_Activation(4))"
                eventMessage3 = "Destination paths & files:" & vbNewLine & tokens & vbNewLine & pkeyconfig & vbNewLine & "Target folder:" & vbNewLine & tokensReplaceDestination
                LogError(eventMessage, eventMessage2, eventMessage3)
    
                Using p2 As New Process
                    p2.StartInfo.FileName = "cmd.exe"
                    p2.StartInfo.Arguments = "/c net start sppsvc /y"
                    p2.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
                    Try
                        p2.Start()
                    Catch exp2 As Exception
                        'MessageBox.Show(exp2.Message)
                        eventMessage = appName & " Error: " & exp2.Message
                        eventMessage2 = appName & " was unable to re-start the Software Protection Platform service 'sppsvc'. (See: Restore_Activation(5))"
                        eventMessage3 = "Process used: " & p2.StartInfo.FileName.ToString & "; Arguements passed: " & p2.StartInfo.Arguments.ToString
                        LogError(eventMessage, eventMessage2, eventMessage3)
                    End Try
                    p2.WaitForExit()
                End Using
    
                Me.Cursor = Cursors.Default
                busy = False
                Return False
            End Try
    
            Using p3 As New Process
                p3.StartInfo.FileName = "cmd.exe"
                p3.StartInfo.Arguments = "/c net start sppsvc /y"
                p3.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
                Try
                    p3.Start()
                Catch exp3 As Exception
                    'MessageBox.Show(exp3.Message)
                    eventMessage = appName & " Error: " & exp3.Message
                    eventMessage2 = appName & " was unable to re-start the Software Protection Platform service 'sppsvc'. (See: Restore_Activation(6))"
                    eventMessage3 = "Process used: " & p3.StartInfo.FileName.ToString & "; Arguements passed: " & p3.StartInfo.Arguments.ToString
                    LogError(eventMessage, eventMessage2, eventMessage3)
                End Try
                p3.WaitForExit()
            End Using
    
            Me.Cursor = Cursors.Default
            busy = False
            Return True
    
        End Function
    
    I have it return a boolean value so I can easily have it return whether the function completed successfully or not...and use it in an If statement like:
    Code:
    If restore_Activation() Then
        restoreLabel.Text = "Success: Restore Complete!"
    Else
        restoreLabel.Text = "Restore Failed!"
    End If
    
     
  6. Hazar

    Hazar MDL Guru

    Jul 29, 2009
    2,507
    456
    90
    I have an enourmous chain of cmds in removewat, debugging was hell lol
     
  7. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,460
    420
    60
    #67 PAYMYRENT, Nov 7, 2009
    Last edited: Nov 7, 2009
    hazar you also have the recoded source i gave you (separated commands)

    and im not good with the whole cmd chains i get lost easy :confused:
     
  8. Hazar

    Hazar MDL Guru

    Jul 29, 2009
    2,507
    456
    90
    Yeah I do, I dunno why but I just did it via the enourmous chain way, and it works.

    I can give the code to HotCarl if he wants to add "WAT Removal" as an option :p

    Also just a UI tip, change the activation method choice from a checkbox to a radio button
     
  9. HotCarl

    HotCarl MDL Addicted

    Jul 21, 2009
    831
    16
    30

    I thought about using 2 radio buttons, but then there is no way to have neither selected once the user has clicked one unless I put a "Clear Radio Buttons" button on the form to force all to be un-checked...

    I do like to use radio buttons whenever I can though as it can make coding a lot simpler... :)
     
  10. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,460
    420
    60
    #70 PAYMYRENT, Nov 7, 2009
    Last edited by a moderator: Apr 20, 2017
    Code:
                System.IO.File.SetAttributes(tokens, IO.FileAttributes.Normal)
                System.IO.File.SetAttributes(pkeyconfig, IO.FileAttributes.Normal)
    

    i dont get this lil part
     
  11. HotCarl

    HotCarl MDL Addicted

    Jul 21, 2009
    831
    16
    30
    #71 HotCarl, Nov 7, 2009
    Last edited by a moderator: Apr 20, 2017
    (OP)
    I set the attributes of those 2 files to normal in case somehow they were set to read-only, it is probably not needed now though since I takeown and icacls the files... It is old code remnants from the last thing I tried to do that can be deleted... :p
     
  12. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,460
    420
    60
    #72 PAYMYRENT, Nov 7, 2009
    Last edited: Nov 7, 2009
    i was just wondering about that lil peice because i never had to put anything like that in my token restore program it worked everytime just like the sc.exe stop sppsvc worked for me oh well lol

    two questions

    have you thought about ppl using this to backup activation for a MAK key?

    and have you imported system.io?
     
  13. HotCarl

    HotCarl MDL Addicted

    Jul 21, 2009
    831
    16
    30
    #73 HotCarl, Nov 7, 2009
    Last edited: Nov 7, 2009
    (OP)

    1) No, how different is backing up for a MAK key? I made it with Windows 7 Retail keys in mind.

    2) No, or I would have just used "File." instead of "System.IO.File."
    Should I?
     
  14. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,460
    420
    60
  15. HotCarl

    HotCarl MDL Addicted

    Jul 21, 2009
    831
    16
    30
  16. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,460
    420
    60
    its still on the machine but its not in the registry. ill try and figure out where it is. maybe you have to go through wmi
     
  17. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,460
    420
    60
    its the same as a user on a retail key running slmgr.vbs -cpky lol i highly doubt that OEM product id is a MAK key lol

    and yea ill look into it the way my program went was two versions one to back up everything, the other to take the tokens.dat and pkeyconfig.xrm-ms and have the user provide the key
     
  18. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,460
    420
    60
    all the test with my program showed me you didnt need to do anything with the syswow64 pkeyconfig. even when i disconected from my wireless it still activated offline with the system32 pkeyconfig only
     
  19. HotCarl

    HotCarl MDL Addicted

    Jul 21, 2009
    831
    16
    30
    #80 HotCarl, Nov 7, 2009
    Last edited: Nov 7, 2009
    (OP)