How to use a code signing certificate for Windows 10 so that the UAC prompts don't show warnings.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.1 KiB

  1. //go:generate goversioninfo -manifest=setup.exe.manifest
  2. //Add new firewall rule in Go.
  3. package main
  4. import (
  5. "os"
  6. "os/exec"
  7. "io/ioutil"
  8. "syscall"
  9. "fmt"
  10. "log"
  11. "static" // Your fileb0x.
  12. )
  13. func main() {
  14. // Grab files from virtual filesystem
  15. files, err := static.WalkDirs("", false)
  16. if err != nil {
  17. log.Fatal(err)
  18. log.Println("ALL FILES", files)
  19. }
  20. // here we'll read the file from the virtual file system
  21. b, err := static.ReadFile("server.exe")
  22. if err != nil {
  23. log.Fatal(err)
  24. }
  25. // Copy file from virtual filesystem to real filesystem
  26. err = ioutil.WriteFile("server.exe", b, 0644)
  27. if err != nil {
  28. fmt.Println("Error creating", "server.exe")
  29. fmt.Println(err)
  30. return
  31. }
  32. // Get current working directory and set it to 'dir'.
  33. dir, err := os.Getwd()
  34. if err != nil {
  35. log.Fatal(err)
  36. }
  37. // Set server file path to 'file'
  38. var file = "-Program '" + dir + "\\server.exe'"
  39. //Create firewall rule if no firewall rule exists.
  40. cmdinstance := exec.Command("powershell.exe", "-WindowStyle", "Hidden", "-Command", "$r", "=", "Get-NetFirewallRule", "-DisplayName", "'Go Web Server'", "2>", "$null;", "if", "($r)", "{write-host 'found rule';}", "else", "{New-NetFirewallRule", "-DisplayName", "'Go Web Server'", "-Direction", "Inbound", file, "-Action", "Allow}")
  41. cmdinstance.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} // Make it silent.
  42. cmdinstance2 := exec.Command("cmd", "/C", "start", "http://localhost:8100")
  43. cmdinstance2.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} // Make it silent.
  44. cmdinstance3 := exec.Command("cmd", "/K", "start", "server.exe")
  45. cmdinstance3.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} // Make it silent.
  46. cmdoutput, cmderr := cmdinstance.Output()
  47. if cmderr != nil {
  48. fmt.Println(cmderr)
  49. fmt.Println(cmdoutput)
  50. }
  51. cmdoutput2, cmderr2 := cmdinstance2.Output()
  52. if cmderr != nil {
  53. fmt.Println(cmderr2)
  54. fmt.Println(cmdoutput2)
  55. }
  56. cmdoutput3, cmderr3 := cmdinstance3.Output()
  57. if cmderr != nil {
  58. fmt.Println(cmderr3)
  59. fmt.Println(cmdoutput3)
  60. }
  61. }