简体   繁体   中英

Program is started by Task Scheduler (in Windows 10) with '/ru SYSTEM' can't execute other programs?

I am make a simple program that can run in the background then open an URL in Windows. I use Task Scheduler to make it happens. It contains two parts: the program and and the batch file. In the program code, I am using this function to open my URL in browser:

func openBrowser(url string) bool {
    var args []string
    switch runtime.GOOS {
    case "darwin":
        args = []string{"open"}
    case "windows":
        args = []string{"cmd", "/c", "start"}
    default:
        args = []string{"xdg-open"}
    }

    cmd := exec.Command(args[0], append(args[1:], url)...)
    fmt.Println(cmd)
    return cmd.Start() == nil
}

And to run my program in background, I just create a batch file that helps me to run several commands to create a Task by the program in Task Scheduler. In the.bat file, I am using these commands:

schtasks /create /xml "Forward_Base.xml" /tn "Forward" /ru SYSTEM
schtasks /run /tn "Forward"

where Forward_Base.xml is my exported Task Scheduler file. And when I started this batch file, the task is created and run. But the command that open browser didn't work. Then, when I remove the parameter /ru SYSTEM and re-run the batch file again. My program worked, however it didn't run in the background anymore!

So my question is how did the /ru SYSTEM affect my program and how could I keep both using this feature with running openBrowser()? Thanks!

P/S: So sorry for not uploading full of the file or code in here because of security reason.

I have a solution for this. Because of some policies in Windows, when running a program in SYSTEM role, everything will execute in SYSTEM role. This means my program opens a browser, but it in another world (I notice that by checking Task Manager).

So the solution is moving my execution file to Startup folder or Windows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM