# L'Math Auto Activation Script template # Use at your own risk! # == USAGE == # # For all users # .\script.ps1 -LicenseCode "code here" -Scope global # # For current user # .\script.ps1 -LicenseCode "code here" -Scope user # # For a specified user # .\script.ps1 -LicenseCode "code here" -Scope user -User "username" param ( [string]$LicenseCode, [ValidateSet("global", "user")] [string]$Scope, [string]$User ) # Check if LicenseCode is provided if (-not $LicenseCode) { Write-Host "ERROR: License code is required. Use: -LicenseCode ..." exit 1 } # Create JSON object $jsonObject = @{ key = $LicenseCode } | ConvertTo-Json # Encode JSON object as base64 $base64String = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($jsonObject)) # Determine file path based on scope if ($Scope -eq "global") { $filePath = "C:\Users\Public\.lmaths\.auto_activation" } elseif ($Scope -eq "user") { if ($User) { $userProfilePath = [System.IO.Path]::Combine("C:\Users", $User) if (-not (Test-Path $userProfilePath)) { Write-Host "ERROR: The specified user profile path '$userProfilePath' does not exist." exit 1 } $filePath = [System.IO.Path]::Combine($userProfilePath, "AppData\Roaming\LMath\.auto_activation") } else { $filePath = "$env:APPDATA\LMath\.auto_activation" } } else { Write-Host "ERROR: Invalid scope. Please use -Scope global or -Scope user or -Scope user -User username." exit 1 } # Ensure the directory exists $directory = Split-Path $filePath -Parent if (-not (Test-Path $directory)) { New-Item -ItemType Directory -Force -Path $directory } # Write the base64 string to the file Set-Content -Path $filePath -Value $base64String Write-Host "Activation file created successfully at $filePath."