runas

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2025 License: MIT Imports: 1 Imported by: 0

README

A golang library to run a process with elevated privileges.

This library provides some easy wrappers for the Win32 ShellExecuteEx function to be executed with the runas "verb" (it will prompt the user, with a UAC dialog, to allow admin privileges).

The provided API, are just two, self-explanatory, functions:

// RunElevated starts the given process with elevated priviledges.
// An UAC prompt is displayed to the user to confirm the action.
func RunElevated(executable, workingDir string, args []string, awaitProcCompletion bool) (int, error)

and

// IsAdminProcess returns true if the current process already
// runs as admin.
func IsAdminProcess() (bool, error)

The same functions called from non-Windows OS, will return an "unimplemented function" error.

LICENSE

Copyright (c) 2025, ARDUINO SA. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE

Documentation

Index

Constants

View Source
const (
	SEE_MASK_DEFAULT            = 0x00000000
	SEE_MASK_CLASSNAME          = 0x00000001
	SEE_MASK_CLASSKEY           = 0x00000003
	SEE_MASK_IDLIST             = 0x00000004
	SEE_MASK_INVOKEIDLIST       = 0x0000000C
	SEE_MASK_ICON               = 0x00000010
	SEE_MASK_HOTKEY             = 0x00000020
	SEE_MASK_NOCLOSEPROCESS     = 0x00000040
	SEE_MASK_CONNECTNETDRV      = 0x00000080
	SEE_MASK_NOASYNC            = 0x00000100
	SEE_MASK_FLAG_DDEWAIT       = 0x00000100
	SEE_MASK_DOENVSUBST         = 0x00000200
	SEE_MASK_FLAG_NO_UI         = 0x00000400
	SEE_MASK_UNICODE            = 0x00004000
	SEE_MASK_NO_CONSOLE         = 0x00008000
	SEE_MASK_ASYNCOK            = 0x00100000
	SEE_MASK_NOQUERYCLASSSTORE  = 0x01000000
	SEE_MASK_HMONITOR           = 0x00200000
	SEE_MASK_NOZONECHECKS       = 0x00800000
	SEE_MASK_WAITFORINPUTIDLE   = 0x02000000
	SEE_MASK_FLAG_LOG_USAGE     = 0x04000000
	SEE_MASK_FLAG_HINST_IS_SITE = 0x08000000
)
View Source
const (
	SE_ERR_FNF             = 2
	SE_ERR_PNF             = 3
	SE_ERR_ACCESSDENIED    = 5
	SE_ERR_OOM             = 8
	SE_ERR_DLLNOTFOUND     = 32
	SE_ERR_SHARE           = 26
	SE_ERR_ASSOCINCOMPLETE = 27
	SE_ERR_DDETIMEOUT      = 28
	SE_ERR_DDEFAIL         = 29
	SE_ERR_DDEBUSY         = 30
	SE_ERR_NOASSOC         = 31
)

Variables

This section is empty.

Functions

func IsAdminProcess

func IsAdminProcess() (bool, error)

IsAdminProcess returns true if the current process already runs as admin.

func RunElevated

func RunElevated(executable, workingDir string, args []string, awaitProcCompletion bool) (int, error)

RunElevated starts the given process with elevated priviledges. An UAC prompt is displayed to the user to confirm the action.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL