Skip to main content

Build Requirements

Visual Studio

Visual Studio 2015 Community Edition or later

.NET Framework

.NET Framework 3.5 (default target)
SharpWMI has been built against .NET Framework 3.5 for maximum compatibility with older Windows systems. You can retarget to .NET 4.0 or later if needed.

Compilation Steps

1

Clone the Repository

git clone https://github.com/GhostPack/SharpWMI.git
cd SharpWMI
2

Open in Visual Studio

Open the SharpWMI.sln solution file in Visual Studio:
start SharpWMI.sln
Or use the File menu in Visual Studio:
  • File → Open → Project/Solution
  • Navigate to SharpWMI.sln
  • Click Open
3

Select Build Configuration

Choose the Release configuration for production builds:
  1. In the toolbar, locate the configuration dropdown (typically shows “Debug”)
  2. Change it to Release
  3. Ensure the platform is set to Any CPU or x64 as appropriate
4

Build the Solution

Build the project:
  • Menu: Build → Build Solution
  • Keyboard: Ctrl + Shift + B
The compiled binary will be located at:
SharpWMI\bin\Release\SharpWMI.exe
5

Verify the Build

Test the compiled binary:
SharpWMI.exe
You should see the usage information displayed.

Build Configurations

  • Release Build
  • Debug Build
Recommended for operational use:
  • Optimized code
  • No debug symbols
  • Smaller file size
  • Better performance
# Build location
SharpWMI\bin\Release\SharpWMI.exe

Retargeting .NET Framework Version

If you need to target a different .NET Framework version:
1

Open Project Properties

  • Right-click on the SharpWMI project in Solution Explorer
  • Select Properties
2

Change Target Framework

  • Navigate to the Application tab
  • In the Target framework dropdown, select your desired version:
    • .NET Framework 3.5 (default)
    • .NET Framework 4.0
    • .NET Framework 4.5
    • .NET Framework 4.6 or later
3

Rebuild

Rebuild the solution after changing the target framework:
Build → Rebuild Solution
Targeting newer .NET Framework versions may reduce compatibility with older Windows systems. .NET Framework 3.5 provides the widest compatibility.

Command-Line Build

You can also build SharpWMI using MSBuild from the command line:
  • Using MSBuild
  • Using Developer Command Prompt
# Locate MSBuild (Visual Studio 2019+ example)
cd "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin"

# Build Release configuration
.\MSBuild.exe C:\Path\To\SharpWMI\SharpWMI.sln /p:Configuration=Release

# Build Debug configuration
.\MSBuild.exe C:\Path\To\SharpWMI\SharpWMI.sln /p:Configuration=Debug

Code Signing (Optional)

For operational security, you may want to sign the compiled binary:
# Create self-signed certificate
$cert = New-SelfSignedCertificate -DnsName "CompanyName" -Type CodeSigning -CertStoreLocation Cert:\CurrentUser\My

# Export certificate
Export-Certificate -Cert $cert -FilePath ".\CodeSignCert.cer"
# Sign using signtool (Windows SDK)
signtool sign /a /t http://timestamp.digicert.com /fd SHA256 SharpWMI.exe

# Or using PowerShell
Set-AuthenticodeSignature -FilePath "SharpWMI.exe" -Certificate $cert
Self-signed certificates won’t bypass security controls but may help with application whitelisting in some environments.

Obfuscation (Optional)

Consider obfuscating the binary for operational use:

ConfuserEx

Free .NET obfuscator
  • Rename symbols
  • Control flow obfuscation
  • String encryption

InvisibilityCloak

C# obfuscation specifically for offensive tools
  • Randomizes method names
  • Encrypts strings
  • Compatible with offensive tooling
Heavy obfuscation may cause runtime issues or increase detection by behavioral analysis. Test thoroughly after obfuscation.

Troubleshooting Build Issues

Error: “The reference assemblies for framework .NETFramework,Version=v3.5 were not found”Solution:
# Enable .NET Framework 3.5 on Windows
DISM /Online /Enable-Feature /FeatureName:NetFx3 /All

# Or download from Microsoft
# Visual Studio Installer → Modify → Individual Components → .NET Framework 3.5
Error: “NuGet package restore failed”Solution:
# Restore NuGet packages manually
nuget restore SharpWMI.sln

# Or in Visual Studio
# Tools → NuGet Package Manager → Restore NuGet Packages
Error: Various compilation errors after changing target frameworkSolution:
  1. Clean the solution: Build → Clean Solution
  2. Delete bin and obj folders
  3. Rebuild: Build → Rebuild Solution
Error: “MSBuild is not recognized as an internal or external command”Solution:
# Add MSBuild to PATH or use full path
# Visual Studio 2019 example:
set PATH=%PATH%;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin

# Or use Developer Command Prompt for VS

Build Automation

Example PowerShell script to automate the build process:
# build.ps1
$SolutionPath = "C:\Path\To\SharpWMI\SharpWMI.sln"
$Configuration = "Release"
$OutputPath = "C:\Output"

# Locate MSBuild
$MSBuild = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe"

if (-not (Test-Path $MSBuild)) {
    Write-Error "MSBuild not found at $MSBuild"
    exit 1
}

# Clean previous builds
& $MSBuild $SolutionPath /t:Clean /p:Configuration=$Configuration

# Build solution
& $MSBuild $SolutionPath /t:Build /p:Configuration=$Configuration

if ($LASTEXITCODE -eq 0) {
    Write-Host "Build succeeded" -ForegroundColor Green

    # Copy to output directory
    $SourceBinary = "SharpWMI\bin\$Configuration\SharpWMI.exe"
    Copy-Item $SourceBinary -Destination $OutputPath
    Write-Host "Binary copied to $OutputPath" -ForegroundColor Green
} else {
    Write-Error "Build failed with exit code $LASTEXITCODE"
    exit $LASTEXITCODE
}

Pre-Built Binaries

The SharpWMI authors do not release pre-compiled binaries. You must build from source.
This is intentional to:
  • Prevent malware distribution
  • Ensure you review the code
  • Allow customization for your environment
  • Avoid antivirus signatures on official releases

Next Steps