|
| 1 | +# A golang library to run a process with elevated privileges. |
| 2 | + |
| 3 | +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). |
| 4 | + |
| 5 | +The provided API, are just two, self-explanatory, functions: |
| 6 | + |
| 7 | +```go |
| 8 | +// RunElevated starts the given process with elevated priviledges. |
| 9 | +// An UAC prompt is displayed to the user to confirm the action. |
| 10 | +func RunElevated(executable, workingDir string, args []string, awaitProcCompletion bool) (int, error) |
| 11 | +``` |
| 12 | + |
| 13 | +and |
| 14 | + |
| 15 | +```go |
| 16 | +// IsAdminProcess returns true if the current process already |
| 17 | +// runs as admin. |
| 18 | +func IsAdminProcess() (bool, error) |
| 19 | +``` |
| 20 | + |
| 21 | +The same functions called from non-Windows OS, will return an "unimplemented function" error. |
| 22 | + |
| 23 | +### LICENSE |
| 24 | + |
| 25 | +Copyright (c) 2025, ARDUINO SA. |
| 26 | +All rights reserved. |
| 27 | + |
| 28 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 29 | +of this software and associated documentation files (the “Software”), to deal |
| 30 | +in the Software without restriction, including without limitation the rights |
| 31 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 32 | +copies of the Software, and to permit persons to whom the Software is furnished |
| 33 | +to do so, subject to the following conditions: |
| 34 | + |
| 35 | +The above copyright notice and this permission notice shall be included in all |
| 36 | +copies or substantial portions of the Software. |
| 37 | + |
| 38 | +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 39 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 40 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 41 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 42 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 43 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 44 | +SOFTWARE |
0 commit comments