Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 669c5b3011 | |||
| 79dea1606b | |||
| 0c1a143dbd | |||
| e0219ca728 | |||
| 63655c25c2 |
7
LICENSE
Normal file
7
LICENSE
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
Copyright 2025 Aurélie DELHAIE
|
||||||
|
|
||||||
|
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.
|
||||||
9
README.md
Normal file
9
README.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# Win2Linux
|
||||||
|
|
||||||
|
The software is still in alpha.
|
||||||
|
|
||||||
|
Small script in Go that allows you to reboot Windows to another operating system registered in the UEFI database.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Inspiriation from "Restart To" gnome extension (https://github.com/tiagoporsch/restartto)
|
||||||
BIN
img/main_screenshot.png
Normal file
BIN
img/main_screenshot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 154 KiB |
33
main.go
33
main.go
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"Win2Linux/pkg/windows"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@@ -49,7 +50,10 @@ func onReady() {
|
|||||||
mCustom := systray.AddMenuItem(key, "Switch to"+key)
|
mCustom := systray.AddMenuItem(key, "Switch to"+key)
|
||||||
go func() {
|
go func() {
|
||||||
<-mCustom.ClickedCh
|
<-mCustom.ClickedCh
|
||||||
fmt.Println(uuid)
|
if uuid == "{fwbootmgr}" {
|
||||||
|
rebootToFirmware()
|
||||||
|
return
|
||||||
|
}
|
||||||
reboot(uuid)
|
reboot(uuid)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -71,7 +75,7 @@ func list() []Entry {
|
|||||||
cmd := exec.Command("bcdedit", "/enum", "firmware")
|
cmd := exec.Command("bcdedit", "/enum", "firmware")
|
||||||
out, err := cmd.Output()
|
out, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
fatal(fmt.Sprintf("failed to run bcdedit: %s\n\nRun this program in administrator mode", err), 1)
|
||||||
}
|
}
|
||||||
return parse(string(out))
|
return parse(string(out))
|
||||||
}
|
}
|
||||||
@@ -122,13 +126,26 @@ func parse(out string) []Entry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func reboot(uuid string) {
|
func reboot(uuid string) {
|
||||||
if err := exec.Command("bcdedit", "/Set", "{fwbootmgr}", "BootSequence", uuid, "/addFirst").Run(); err != nil {
|
out, err := exec.Command("bcdedit", "/Set", "{fwbootmgr}", "BootSequence", uuid, "/addFirst").Output()
|
||||||
panic(err)
|
if err != nil {
|
||||||
|
windows.MessageBox(windows.NULL, fmt.Sprintf("failed to execute bcdedit: %s", out), "Win2Linux", windows.MB_OK)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := exec.Command("shutdown", "/r", "/t", "0").Run(); err != nil {
|
out, err = exec.Command("shutdown", "/r", "/t", "0").Output()
|
||||||
panic(err)
|
if err != nil {
|
||||||
|
windows.MessageBox(windows.NULL, fmt.Sprintf("failed to restart the computer: %s", out), "Win2Linux", windows.MB_OK)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
os.Exit(0)
|
|
||||||
|
func rebootToFirmware() {
|
||||||
|
out, err := exec.Command("shutdown", "/r", "/fw", "/t", "0").Output()
|
||||||
|
if err != nil {
|
||||||
|
windows.MessageBox(windows.NULL, fmt.Sprintf("failed to restart the computer: %s", out), "Win2Linux", windows.MB_OK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func fatal(message string, exitCode int) {
|
||||||
|
windows.MessageBox(windows.NULL, message, "Win2Linux", windows.MB_OK)
|
||||||
|
os.Exit(exitCode)
|
||||||
}
|
}
|
||||||
|
|||||||
30
pkg/windows/windows.go
Normal file
30
pkg/windows/windows.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package windows
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
NULL = 0
|
||||||
|
MB_OK = 0
|
||||||
|
)
|
||||||
|
|
||||||
|
// MessageBox of Win32 API.
|
||||||
|
func MessageBox(hwnd uintptr, caption, title string, flags uint) int {
|
||||||
|
_caption, err := syscall.UTF16PtrFromString(caption)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
_title, err := syscall.UTF16PtrFromString(title)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
ret, _, _ := syscall.NewLazyDLL("user32.dll").NewProc("MessageBoxW").Call(
|
||||||
|
uintptr(hwnd),
|
||||||
|
uintptr(unsafe.Pointer(_caption)),
|
||||||
|
uintptr(unsafe.Pointer(_title)),
|
||||||
|
uintptr(flags))
|
||||||
|
|
||||||
|
return int(ret)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user