say i have the following code, using syscall
to hide command line window
process := exec.Command(name, args...)
process.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
err := process.Start()
if err != nil {
log.Print(err)
}
but when i compiled it and tried to run it in Windows, command line window showed up again
what can i do to prevent command line window from appearing?
PS i already know how to compile golang source into a Windows GUI executable using go build -ldflags -H=windowsgui
, but doing so only ensures the program itself doesn't bring up a command line window, Exec
will show those windows anyway
Go exec command tutorial shows how to execute shell commands and programs in Golang. The Run function starts the specified command and waits for it to complete, while the Start starts the specified command but does not wait for it to complete; we need to use Wait with Start . The os/exec package runs external commands.
The exec and hide commands are used to execute the script and hide any console windows from opening. Include elevatecmd to request administrator privileges for the batch file although it’s only needed if you know commands in your script require elevation. nircmd elevatecmd exec hide [path to.bat file]
Using exec in GoLang Exec is a subpackage in os package. It can be used to run external commands using Go. This post will provide some examples of how to get started using it.
When using a method to hide the console window make sure the batch script contains no commands that are likely to stop the script before it exits, such as pause or requiring user input like a Yes/No response.
There is a better solution, which can run exec.Command()
without spawn a visible window, ( ͡° ͜ʖ ͡°).
Here is my code:
Firstly import "syscall"
cmd_path := "C:\\Windows\\system32\\cmd.exe"
cmd_instance := exec.Command(cmd_path, "/c", "notepad")
cmd_instance.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
cmd_output, err := cmd_instance.Output()
Origin: https://www.reddit.com/r/golang/comments/2c1g3x/build_golang_app_reverse_shell_to_run_in_windows/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With