https://github.com/nyaosorg/go-windows-su
Switch or test Windows' administrator mode
https://github.com/nyaosorg/go-windows-su
go golang windows
Last synced: 9 months ago
JSON representation
Switch or test Windows' administrator mode
- Host: GitHub
- URL: https://github.com/nyaosorg/go-windows-su
- Owner: nyaosorg
- License: mit
- Created: 2020-01-18T02:57:14.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-05-29T13:00:23.000Z (about 4 years ago)
- Last Synced: 2025-08-15T12:48:35.227Z (11 months ago)
- Topics: go, golang, windows
- Language: Go
- Homepage: https://pkg.go.dev/github.com/nyaosorg/go-windows-su
- Size: 21.5 KB
- Stars: 12
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
go-windows-su
=============
Switch or test administrator's mode
[Switch](./cmd/chhosts/main.go)
------------------------------
```go
package main
import (
"os"
"path/filepath"
"github.com/nyaosorg/go-windows-su"
)
func main() {
windir := os.Getenv("SystemRoot")
hosts := filepath.Join(windir, `system32\drivers\etc\hosts`)
su.ShellExecute(su.RUNAS,
"notepad",
hosts,
`C:\`)
}
```
If you call the executable on the network by su.ShellExecute,
give the parameter the path filtered by filepath.EvalSymlinks.
[Test](./cmd/isElevated/main.go)
--------------------------------
```go
package main
import (
"fmt"
"os"
"github.com/nyaosorg/go-windows-su"
)
func main() {
flag, err := su.IsElevated()
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(2)
} else if flag {
fmt.Println("Administrator mode")
os.Exit(0)
} else {
fmt.Println("Not administrator mode")
os.Exit(1)
}
}
```
Sample Application
------------------
[source](./cmd/sucopy/main.go)
```
sucopy SRC DST
```
Execute `copy` built in CMD.EXE in Administrator-mode.
`sucopy` keeps network-drives.