A C# reimplementation of the Windows Software Licensing Management Tool (slmgr.vbs), built for environments where VBScript is no longer available. The project ships the same command set and behaviour as the original script, and additionally provides a library build so external programs can invoke it programmatically.
This project is a rewrite based on the Windows 11 26H2 (10.0.26300.9457) version of slmgr.vbs.
Microsoft has deprecated the VBScript engine on Windows. slmgr.vbs — the standard tool for installing product keys, activating Windows, configuring KMS, and inspecting license state — will no longer run once the engine is removed.
This project is a drop-in replacement written in C# targeting .NET Framework 4.5.2. It mirrors the option names, output strings and side effects of the original slmgr.vbs, and can be compiled into three different outputs from a single source tree.
- Full command coverage of
slmgr.vbs:- Product key and activation:
/ipk,/upk,/ato,/atp,/dti - License information:
/dli,/dlv,/xpr - Advanced:
/cpky,/ilc,/rilc,/rearm,/rearm-app,/rearm-sku - KMS client:
/skms,/ckms,/skms-domain,/ckms-domain,/skhc,/ckhc - KMS host:
/sprt,/sai,/sri,/sdns,/cdns,/spri,/cpri,/act-type - Token-based activation:
/lil,/ril,/ltc,/fta - Active Directory activation:
/ad-activation-online,/ad-activation-get-iid,/ad-activation-apply-cid,/ao-list,/del-ao
- Product key and activation:
- Three build outputs from one source tree:
slmgr.exe— Windows GUI host (output via MessageBox)slmgrc.exe— console host (output via Console)slmgrlib.dll— class library for external programs (output returned as a string)
- Visual Studio 2015 or later (MSBuild 14.0+)
- .NET Framework 4.5.2
- Administrator privileges at runtime for most commands
slmgr/
├── slmgr.csproj Single project, multiple build configurations
├── App.config
├── Program.cs Entry point (compiled only in exe builds)
├── Commands.cs Command dispatch and implementation
├── WmiHelper.cs WMI wrapper for SoftwareLicensingService / Product
├── AdHelper.cs Active Directory activation helpers
├── TkaHelper.cs Token-based activation helpers
├── OutputMode.cs Output routing (Console / MessageBox / redirect)
├── Resources.cs ResourceManager wrapper
├── SlmgrApi.cs Public entry point: slmgr.Slmgr.Run(...)
├── SlmgrResult.cs Return type for the API
├── ExitSignalException.cs Internal control-flow exception
├── WindowsAppId.cs Shared constants
├── Resources/ Language resources
└── Properties/
├── AssemblyInfo.cs
├── Resources.resx
└── Settings.settings
- Open the solution.
- Build → Configuration Manager.
- Under Active solution configuration, create
Debug-Console,Release-Console,Debug-Library,Release-Libraryby copying fromDebug/Release. - Ensure Build is checked for the
slmgrproject in every configuration. - Switch configurations in the toolbar to build each artifact.
msbuild slmgr.csproj /p:Configuration=Release
msbuild slmgr.csproj /p:Configuration=Release-Console
msbuild slmgr.csproj /p:Configuration=Release-LibraryAfter all three commands, bin\Release\ contains:
bin\Release\
├── slmgr.exe
├── slmgrc.exe
├── slmgrlib.dll
├── en-US\
...
Each artifact carries its own satellite assemblies (the .NET resource system keys satellites by assembly name). The satellite contents are identical; the duplication is a consequence of the single-project multi-configuration approach. To share a single satellite across all three artifacts, extract the resources into a separate class library project and reference it from all three.
slmgr.exe /dlv
slmgr.exe /ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
slmgr.exe /skms kms.example.com:1688
slmgr.exe /atoOutput is shown in a MessageBox. Intended for interactive use.
slmgrc.exe /dlv
slmgrc.exe /ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
slmgrc.exe /atoOutput goes to the console. Intended for scripting and automation.
Both executables accept up to three leading arguments for remote operation:
slmgrc.exe \\remote-pc admin password /dlv/ao-list and /del-ao do not support remote execution, matching the original script.
dotnet add package slmgr-csOr in Visual Studio Package Manager Console:
Install-Package slmgr-csYou can download from release page too.
Reference slmgrlib.dll from your project and call slmgr.Slmgr.Run(...):
using slmgr;
SlmgrResult r = Slmgr.Run("/dlv");
Console.WriteLine("ExitCode: " + r.ExitCode);
Console.WriteLine(r.Output);
SlmgrResult r2 = Slmgr.Run("/ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX");
if (!r2.Success)
{
Console.WriteLine("Failed: " + r2.Output);
}namespace slmgr
{
public static class Slmgr
{
public static SlmgrResult Run(string commandLine);
public static SlmgrResult Run(string[] args);
}
public class SlmgrResult
{
public string Output { get; set; } // captured output text
public int ExitCode { get; set; } // exit code
public bool Success { get; } // true when ExitCode == 0
}
}Run(string)splits the command line on whitespace, honouring double quotes.Run(string[])takes a pre-parsed argument array.- Both overloads are thread-safe; concurrent calls are serialized.
- The API does not call
Environment.Exit; the exit code is returned throughSlmgrResult.ExitCode.
Add-Type -Path 'slmgrlib.dll'
$r = [slmgr.Slmgr]::Run('/dlv')
Write-Host "ExitCode: $($r.ExitCode)"
Write-Host $r.OutputImports slmgr
Dim r As SlmgrResult = Slmgr.Run("/dlv")
Console.WriteLine("ExitCode: " & r.ExitCode)
Console.WriteLine(r.Output)The UI is localized through standard .NET resources.
ResourceManager selects the appropriate resource based on Thread.CurrentThread.CurrentUICulture. To force a specific language:
System.Threading.Thread.CurrentThread.CurrentUICulture =
new System.Globalization.CultureInfo("zh-CN");- Copy
Resources\Strings.resxtoResources\Strings.<culture>.resx(for exampleStrings.zh-TW.resx). - Translate the values.
- Add an
<EmbeddedResource Include="Resources\Strings.zh-TW.resx" />entry toslmgr.csproj. - Rebuild. A satellite assembly
zh-TW\slmgr.resources.dllwill be produced.
The following behaviours intentionally match slmgr.vbs:
- Option names are identical, including the historically unusual
/cprifor clearing KMS priority to Low. - Output text uses the same message templates, including placeholder tokens such as
%PKEY%,%ACTID%,%ERRCODE%. - Hexadecimal error codes are printed without leading zeros, mirroring VBScript's
Hex()function. /ao-listformats the binarymsSPP-CSVLKSkuIdattribute with the same byte ordering as the script'sGuidToStringhelper.- Remote connections use
Impersonate+PacketPrivacy, matching the script's WMI security settings.
Two small differences from the script:
- The subscription-status block in
/dliand/dlvis suppressed whenSubscriptionTypeisUnknown, instead of printing a placeholder. This avoids noisy output on Windows builds that predate the subscription-related WMI properties. /ao-listand/del-aofail fast on remote connections with a clear message, rather than a generic WMI error.
- Remote WMI: supported for most commands.
/ao-listand/del-aorequire local execution. - Remote registry: the KMS version registry write-back is local only. The original script used
StdRegProv; this implementation usesMicrosoft.Win32.RegistryKeyagainst the local machine. - Token-based activation (
/fta,/ltc,/lil,/ril) depends on theSPPWMI.SppWmiTokenActivationSignerCOM object being registered. This is present on Windows installations that support Token-based Activation; on other systems the commands will fail with a clear error. - Administrator privileges: nearly all commands require elevation. Running without it returns
0xC004F025(access denied), matching the script's behaviour.
This project is licensed under the MIT License.
The command set, output strings, and internal behaviour are based on the original slmgr.vbs shipped with Windows. This project is an independent reimplementation and is not affiliated with or endorsed by Microsoft.