wails/website/docs/guides/windows.mdx
Lea Anthony e3dbe294f2 fix: Add Windows UAC execution level support to manifest template
Fixes #4349: Windows admin permissions not persisting between machines

This change adds configurable UAC (User Account Control) execution level
support to the Windows manifest template, allowing developers to specify
admin requirements that persist when executables are distributed.

## Changes Made

### Enhanced Windows Manifest Template
- Added conditional UAC `trustInfo` section to manifest template
- Uses template variable `{{.ExecutionLevel}}` for dynamic configuration
- Backward compatible: no UAC section when execution level not specified

### Project Configuration Support
- Added `WindowsInfo` struct to project configuration
- Added `executionLevel` field for specifying UAC requirements
- Integrated execution level into template data processing

### Template Data Enhancement
- Extended `assetData` struct to include execution level
- Updated template resolution to extract Windows-specific configuration
- Maintained backward compatibility with existing projects

### Documentation Updates
- Added comprehensive Windows UAC guide with examples
- Updated project configuration reference with Windows options
- Included usage examples and supported execution levels

## Usage

Developers can now specify execution level in wails.json:

```json
{
  "info": {
    "windows": {
      "executionLevel": "requireAdministrator"
    }
  }
}
```

Supported values:
- `requireAdministrator`: Requires admin privileges
- `asInvoker`: Runs with invoker's privileges
- `highestAvailable`: Runs with highest available privileges

## Testing

Verified that:
- UAC trustInfo section is properly embedded in Windows executables
- Admin privileges persist when executables are copied between machines
- Backward compatibility maintained for existing projects
- Template processing works correctly during build

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-12 22:03:07 +10:00

133 lines
4.8 KiB
Text

# Windows
This page has miscellaneous guides related to developing Wails applications for Windows.
## Handling the WebView2 Runtime Dependency
Wails applications built for Windows have a runtime requirement on the Microsoft [WebView2 Runtime](https://developer.microsoft.com/en-us/microsoft-edge/webview2/).
Windows 11 will have this installed by default, but some machines won't. Wails offers an easy approach to dealing with this dependency.
By using the `-webview2` flag when building, you can decide what your application will do when a suitable runtime is not detected (including if the installed runtime is too old).
The four options are:
1. Download
2. Embed
3. Browser
4. Error
### Download
This option will prompt the user that no suitable runtime has been found and then offer to download and run the official
bootstrapper from Microsoft's WebView2 site. If the user proceeds, the official bootstrapper will be downloaded and run.
### Embed
This option embeds the official bootstrapper within the application. If no suitable runtime has been found, the
application will offer to run the bootstrapper. This adds ~150k to the binary size.
### Browser
This option will prompt the user that no suitable runtime has been found and then offer to open a browser to the official
WebView2 page where the bootstrapper can be downloaded and installed. The application will then exit, leaving the installation
up to the user.
### Error
If no suitable runtime is found, an error is given to the user and no further action taken.
## Fixed version runtime
Another way of dealing with webview2 dependency is shipping it yourself.
You can download [fixed version runtime](https://developer.microsoft.com/microsoft-edge/webview2/#download-section) and bundle or download it with your application.
Also, you should specify path to fixed version of webview2 runtime in the `windows.Options` structure when launching wails.
```go
wails.Run(&options.App{
Windows: &windows.Options{
WebviewBrowserPath: "",
},
})
```
Note: When `WebviewBrowserPath` is specified, `error` strategy will be forced in case of minimal required version
mismatch or invalid path to a runtime.
The downloaded file will be compressed (extension `.cab`), so you must extract it before using it, according to the instructions on the [official site](https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/distribution#details-about-the-fixed-version-runtime-distribution-mode) should run in a terminal the following command to extract the file:
```
expand {path to the package} -F:* {path to the destination folder}
```
## Spawning other programs
When spawning other programs, such as scripts, you will see the window appear on the screen. To hide the window,
you can use the following code:
```go
cmd := exec.Command("your_script.exe")
cmd.SysProcAttr = &syscall.SysProcAttr{
HideWindow: true,
CreationFlags: 0x08000000,
}
cmd.Start()
```
Solution provided by [sithembiso](https://github.com/sithembiso) on the
[discussions board](https://github.com/wailsapp/wails/discussions/1734#discussioncomment-3386172).
## UAC Execution Level
Windows applications can request specific User Account Control (UAC) execution levels through the application manifest. Wails supports configuring UAC execution levels that will persist when your application is distributed to other machines.
### Configuring Execution Level
You can configure the UAC execution level in your `wails.json` project configuration:
```json
{
"info": {
"companyName": "My Company",
"productName": "My App",
"productVersion": "1.0.0",
"windows": {
"executionLevel": "requireAdministrator"
}
}
}
```
### Supported Execution Levels
| Level | Description |
|-------|-------------|
| `requireAdministrator` | The application requires administrator privileges and will prompt for elevation |
| `highestAvailable` | The application runs with the highest privileges available to the user |
| `asInvoker` | The application runs with the same privileges as the calling process (default behavior) |
### Example: Admin-Required Application
For applications that need administrator privileges (e.g., system utilities, installers):
```json
{
"name": "SystemTool",
"info": {
"companyName": "My Company",
"productName": "System Administration Tool",
"productVersion": "1.0.0",
"windows": {
"executionLevel": "requireAdministrator"
}
}
}
```
When built, this application will:
- Display a UAC prompt when launched on Windows
- Request administrator privileges before starting
- Persist this behavior when copied to other machines
### Backward Compatibility
If no `executionLevel` is specified, no UAC requirements are added to the manifest, maintaining the default Windows behavior where applications run with the same privileges as the launching process.