TSForge Activation Script [ps1 version]

Discussion in 'Scripting' started by Dark Vador, Apr 19, 2025.

  1. mephistooo2

    mephistooo2 MDL Junior Member

    Feb 5, 2008
    83
    143
    0
    Dear @Dark Vador , I updated your script a bit, automated a lot of the work but there are still some missing parts. ☺️

    Is there a way to permanently activate Office products with the zerocid method using this script with a Retail or MAK product key?

    I just couldn't figure it out ☺️

    Features:
    1. LibTSforge.dll Integration: The script loads the LibTSforge.dll file, which is Base64 encoded, into memory. If the file is present, it will be loaded; otherwise, it will be decompressed from Base64 and loaded into memory.

    2. Random KMS IP Address Setting: For KMS or Volume licensed products, the script generates a random KMS IP address and sets it in the Windows registry. This helps prevent the "Genuine" license warning.

    3. Activation for Different License Types:
      • KMS (Key Management Service) licenses for activation.

      • VIRTUAL MACHINE ACTIVITY for AVMA (Automatic Virtual Machine Activation).

      • MAK, RETAIL, and OEM licenses for activation.
    4. Retail Office Products: The script detects retail (consumer) Office products, but it does not perform automatic activation for them.

    5. Product Selection and Activation: The script provides a user interface (Out-GridView) for selecting Windows and Office products for activation. Users can choose products and start the activation process.

    6. Product Information Retrieval: The script detects the license status of installed Windows and Office products on the system.

    7. Version Detection: The script uses the LibTSforge library to detect the current version of the product, and based on this, it performs the appropriate activation.

    8. Key Generation: The script generates random product keys and applies them to the corresponding products.
    Supported Versions:
    • Windows: Windows 10 and later versions (supports zerocid activation).

    • Office: Office 2013 and later versions, particularly for KMS licenses. Compatible with Office 2016 and later versions. (supports KMS activation).
    User Input:
    • -w: Selects only Windows products for activation.

    • -o: Selects only Office products for activation.
    When these parameters are used, the script activates only Windows or Office products. If both are selected, it activates both Windows and Office. If no parameters are provided, the user is prompted with a selection screen to choose the products to activate.

    Special Cases:
    • VIRTUAL_MACHINE_ACTIVATION license type: Works only on Windows Server Datacenter editions and requires Hyper-V or QEMU virtualization environments. While the script indicates success, real activation status may be verified through the slmgr.vbs -dlv command, which might show the actual activation state.

    [​IMG]
     

    Attached Files:

    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. Dark Vador

    Dark Vador X Æ A-12

    Feb 2, 2011
    4,397
    6,419
    150
    Office products also offer mak license
    Install them, use ZeroCid
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. mephistooo2

    mephistooo2 MDL Junior Member

    Feb 5, 2008
    83
    143
    0
    I couldn't figure out how to do this. :rolleyes:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. Dark Vador

    Dark Vador X Æ A-12

    Feb 2, 2011
    4,397
    6,419
    150
    #24 Dark Vador, May 14, 2025
    Last edited: May 14, 2025
    (OP)
    So now you want to install list of massive amount of mak license's, wmi command will be very very slowly :D
    In case of rtool, I remove all license, and reinstall vol & mak license
    And client* and pkeyconfig* license^s
    * But for a specific product
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. Dark Vador

    Dark Vador X Æ A-12

    Feb 2, 2011
    4,397
    6,419
    150
    Got an idea, do query of all office license * specific vol
    Search for mak same product
    Not found, search for mak license
    Install them, than re load license list
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. mephistooo2

    mephistooo2 MDL Junior Member

    Feb 5, 2008
    83
    143
    0
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. witherornot

    witherornot MDL Junior Member

    Nov 18, 2020
    75
    447
    0
    How doesn't CSVLK work? What error is shown?
     
  8. pm67310

    pm67310 MDL Guru

    Sep 6, 2011
    3,544
    2,775
    120
    Error are kms key no installed but gvlk key are host
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. witherornot

    witherornot MDL Junior Member

    Nov 18, 2020
    75
    447
    0
    ?????
     
  10. pm67310

    pm67310 MDL Guru

    Sep 6, 2011
    3,544
    2,775
    120
    #30 pm67310, May 17, 2025 at 06:54
    Last edited: May 17, 2025 at 07:21
    Kms host key "csvlk" working with tsforge or massgrave ( but error with dark vador scripts )

    1 use dark vador to activate server 2022 standard with kms4k

    If you choose with dark vador script kms ws22 channel "csvlk" / kms4k are used she need to edit to use zerocid for ws22 channel

    If you use this script + regular kms aka gvlk os are activated fines ( but kms server features aka csvlk no works )

    @Dark Vador

    You need to edit script !

    If channel csvlk aka kms host are selected

    WS12_R2,WS16,WS19,WS22,WS25,WS10 => ZeroCID
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. Dark Vador

    Dark Vador X Æ A-12

    Feb 2, 2011
    4,397
    6,419
    150
    I think the proper credit should be given to
    give me updated script :D
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. pm67310

    pm67310 MDL Guru

    Sep 6, 2011
    3,544
    2,775
    120
    #32 pm67310, May 17, 2025 at 07:39
    Last edited: May 17, 2025 at 08:52
    if ($desc -match 'KMSCLIENT') {
    [LibTSforge.Activators.KMS4k]::Activate($ver, $prod, $id)
    }
    elseif ($desc -match 'VIRTUAL_MACHINE_ACTIVATION') {
    [LibTSforge.Activators.AVMA4K]::Activate($ver, $prod, $id)
    }
    elseif ($desc -match 'MAK|RETAIL|OEM|KMS_R2|WS12|WS12_R2|WS16|WS19|WS22|WS25') {
    [LibTSforge.Activators.ZeroCID]::Activate($ver, $prod, $id)
    }
    else {
    Write-Warning "Unknown license type: $desc"
    }
    }

    change

    $_.Description -notmatch 'DEMO|MSDN|PIN|FREE|TIMEBASED|GRACE|W10|WS12|WS12R2|WS16|WS19|WS22|WS25'

    to $_.Description -notmatch 'DEMO|MSDN|PIN|FREE|TIMEBASED|GRACE|W10'
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  13. Dark Vador

    Dark Vador X Æ A-12

    Feb 2, 2011
    4,397
    6,419
    150
    $_.Description -notmatch 'DEMO|MSDN|PIN|FREE|TIMEBASED|GRACE|W10|WS12|WS12R2|WS16|WS19|WS22|WS25'
    so, it include or exclude :doh:
    what about the rest products ? w?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. pm67310

    pm67310 MDL Guru

    Sep 6, 2011
    3,544
    2,775
    120
    #34 pm67310, May 17, 2025 at 08:30
    Last edited: May 17, 2025 at 09:00
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  15. Dark Vador

    Dark Vador X Æ A-12

    Feb 2, 2011
    4,397
    6,419
    150
    Done :oops:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  16. pm67310

    pm67310 MDL Guru

    Sep 6, 2011
    3,544
    2,775
    120
    #36 pm67310, May 17, 2025 at 19:25
    Last edited: May 17, 2025 at 19:37
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  17. Dark Vador

    Dark Vador X Æ A-12

    Feb 2, 2011
    4,397
    6,419
    150
    #37 Dark Vador, May 17, 2025 at 19:52
    Last edited: May 17, 2025 at 19:59
    (OP)
    @pm67310
    so, you want install oHook & use ZeroCid\kms4k in same time ?
    or maybe give user a choice, with GUI, instead ?
    also, this is x64 ohook only o_O
    what about the part of - install key's ?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  18. pm67310

    pm67310 MDL Guru

    Sep 6, 2011
    3,544
    2,775
    120
    #38 pm67310, May 17, 2025 at 20:31
    Last edited: May 17, 2025 at 20:44
    @Dark Vador
    so, you want install oHook & use ZeroCid\kms4k in same time ? => Yes because features upgrade resist

    what about the part of - install key's ? => use generated key

    32bits os ? useless
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  19. Dark Vador

    Dark Vador X Æ A-12

    Feb 2, 2011
    4,397
    6,419
    150
    Interesting, and about the x86 version?
    In my logic, you can just copy paste it
    After first activation end
    And I need to also encode x86 dll too
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  20. pm67310

    pm67310 MDL Guru

    Sep 6, 2011
    3,544
    2,775
    120
    and about the x86 version? => tsforge only @Dark Vador

    Code:
    Function GetRandomKey([String] $ProductID) {
        try {
            $guid = [Guid]::Parse($ProductID)
            $pkc = [LibTSforge.SPP.PKeyConfig]::new()
            try {
              $pkc.LoadConfig($guid) | Out-Null
            } catch {
              $pkc.LoadAllConfigs([LibTSforge.SPP.SLApi]::GetAppId($guid)) | Out-Null
            }
            $config = [LibTSforge.SPP.ProductConfig]::new()
            $refConfig = [ref] $config
            $pkc.Products.TryGetValue($guid, $refConfig) | Out-Null
            return $config.GetRandomKey().ToString()
        } catch {
            Write-Warning "Failed to retrieve key for Product ID: $ProductID"
            return $null
        }
    }
    
    function Invoke-IfOfficeClickToRunExists {
        param (
            [ScriptBlock]$Action
        )
    
        # Get OS version
        $osVersion = [System.Environment]::OSVersion.Version
    
        # Check if the OS is Windows 8.0 (6.2) or higher
        $isSupportedOS = ($osVersion.Major -gt 6) -or ($osVersion.Major -eq 6 -and $osVersion.Minor -ge 2)
    
        if (-not $isSupportedOS) {
            Write-Host "ohook need windows 8.0 or up. Skipping action..."
            return
        }
    
        # Check if the Office Click-to-Run service exists
        $clickToRunService = Get-Service -Name "ClickToRunSvc" -ErrorAction SilentlyContinue
    
        if ($clickToRunService) {
            Write-Host "Office Click-to-Run detected. Executing action..."
            & $Action
        } else {
            Write-Host "Office Click-to-Run not detected. Skipping ohook action..."
        }
    }
    
    # Example usage:
    Invoke-IfOfficeClickToRunExists {
    $base64 = @'
    H4sIAAAAAAAEAO1aW2wcVxn+15ckbuxcIGnTNmk2wUmctFns1AGnoak3u3Z26TreeH1pkqbxZPd4PfV6ZjIz69oVSKUhgOtaiuAFVaoKohVCQqIPRUQkSFaDGngIBZknHkBqkUiUSg0CHlAEy3dmznhnZ/YSgdKoyMf+Zs75/ss5/z9nz5zZ2b4TF6ieiBqAQoHoItmlm2qXl4A1W3++ht5purbtYiBxbdvguGwENV3N6tJkMC0pimoGz7CgnleCshKM9qeCk2qGhVpa7msVPpI9RJlvrCT18C3m+L1Foe2r6+r2UB0aj9jcP9fhwEHf7uC0Va+zx83LCsf4gh2M8hoXjwaIgja/zlFY52mLapJonlc0VAN2cNM8Me1ErfS/l2/Bb1cVechk0yaJvkVsS8GJEiQaDekZyZREVEGht6JUrxv/Ic3Ws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vd5awHp1xuhYIGXq+D8aH7HfXQL8mwXD+mqBaAPaT/cMHO1JPL5PUNSm8XdoiZFwMu5Qn+ISsF49b7LfyJbw/HvB9jJ8UwNRDLVnINlcX5Rsru/EcZhSdBrHHhpALU79dBTtOI69qPPyi4aP/839NAq7xtIOqAF/dR7uK3XcIkUm6SSTQll4kylHDJ4VGiOVj8fSaadO4IB17iE+ohdpL/gIdCZxeSXoz7jegRGFwXCZBH8q5cmgIHpS4dWkF8Dq0AtSFEcT4P2r1nsz06opkEUsRvPwvByi1ejbGSv3YVDa8qGV6Kk0Dqg0YfWdxF/E4ttplct+2OrfcNm1U4j2A+0WiPYgmwErJ/ZYFSuqYrQG+tUobdm+iuwEKAE+a2nxKDTkho8ui/HwxflHGM8+eN4H3eBdzNQT1ISx9Iu+ZTFuJ27FN/4QZSCxP3uP0QrYJmGrgs1DapZc32JuCVGs8ul6s+rNadSa9cNWfP5Zx39vwX/IMGhFpMBPzjMHmhr+7PlVx70t/wHxf5zsACQAAA==
    '@
    
        # Decode the Base64 string back into a byte array
        $compressedDllBytes = [Convert]::FromBase64String($base64)
    
        # Step 2: Create a MemoryStream from the byte array
        $compressedStream = [System.IO.MemoryStream]::new($compressedDllBytes)
    
        # Step 3: Decompress the byte array using GZip
        $gzipStream = New-Object System.IO.Compression.GZipStream($compressedStream, [System.IO.Compression.CompressionMode]::Decompress)
        $decompressedStream = New-Object System.IO.MemoryStream
    
        # Copy the decompressed data to a new MemoryStream
        $gzipStream.CopyTo($decompressedStream)
        $gzipStream.Close()
    
        # Step 4: Get the decompressed byte array
        $decompressedDllBytes = $decompressedStream.ToArray()
       
        # Define the output file path with ProgramFiles environment variable
        $sppc = [System.IO.Path]::Combine($env:ProgramFiles, "Microsoft Office\root\vfs\System\sppc.dll")
    
        # Define paths for symbolic link and target
        $sppcs = [System.IO.Path]::Combine($env:ProgramFiles, "Microsoft Office\root\vfs\System\sppcs.dll")
        $System32 = [System.IO.Path]::Combine($env:windir, "System32\sppc.dll")
    
        # Step 1: Check if the symbolic link exists and remove it if necessary
        if (Test-Path -Path $sppcs) {
            Write-Host "Symbolic link already exists at $sppcs. Attempting to remove..."
    
            try {
                # Remove the existing symbolic link
                Remove-Item -Path $sppcs -Force
                Write-Host "Existing symbolic link removed successfully."
            } catch {
                Write-Host "Failed to remove existing symbolic link: $_"
            }
        } else {
            Write-Host "No symbolic link found at $sppcs."
        }
    
        try {
            # Attempt to write byte array to the file
            [System.IO.File]::WriteAllBytes($sppc, $decompressedDllBytes)
            Write-Host "Byte array written successfully to $sppc."
        }
        catch {
            Write-Host "Failed to write byte array to ${sppc}: $_"
    
            # Inner try-catch to handle the case where the file is in use
            try {
                Write-Host "File is in use or locked. Attempting to move it to a temp file..."
    
                # Generate a random name for the temporary file in the temp folder
                $tempDir = [System.IO.Path]::GetTempPath()
                $tempFileName = [System.IO.Path]::Combine($tempDir, [System.Guid]::NewGuid().ToString() + ".bak")
    
                # Move the file to the temp location with a random name
                Move-Item -Path $sppc -Destination $tempFileName -Force
                Write-Host "Moved file to temporary location: $tempFileName"
    
                # Retry the write operation after moving the file
                [System.IO.File]::WriteAllBytes($sppc, $decompressedDllBytes)
                Write-Host "Byte array written successfully to $sppc after moving the file."
    
            } catch {
                Write-Host "Failed to move the file or retry the write operation: $_"
            }
        }
    
        # Step 3: Check if the symbolic link exists and create it if necessary
        try {
            if (-not (Test-Path -Path $sppcs)) {
                # Create symbolic link only if it doesn't already exist
                New-Item -Path $sppcs -ItemType SymbolicLink -Target $System32 | Out-Null
                Write-Host "Symbolic link created successfully at $sppcs."
            } else {
                Write-Host "Symbolic link already exists at $sppcs."
            }
        } catch {
            Write-Host "Failed to create symbolic link at ${sppcs}: $_"
        }
    }
    
    Function Main {
        $selected = $null
        $ver   = [LibTSforge.Utils]::DetectVersion()
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...