KiYugadgeter
KiYugadgeter

Reputation: 4014

Process.Start does not work on TAskScheduler

I want to start ClickOnce program from C# Program with Process.Start.
I also would like to use TaskScheduler to run C# Program periodically.

But Process.Start does not start ClickOnce program only in case run C# program from TaskScheduler.
In another case that if the C# program run normally, it works.

Why only when run program from TaskScheduler, Process.Start does not work?

The user account that run this program with TaskScheduler has administration privilege.

Process? StartKabuS()
{
    Process? p = null;
    var psi = new ProcessStartInfo();
    var appref = "C:\\Users\\user\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\kabu.com\\kabuステーション.appref-ms";
    psi.FileName = appref;
    psi.UseShellExecute = true;
    Process.Start(psi);
    Thread.Sleep(20000); // wait until start program actually
    Console.WriteLine("Wait is over");
    var ps = Process.GetProcessesByName("KabuS"); // KabuS is program name that run when click kabuステーション.appref-ms.
    if (ps.Length > 0)
    {
        p = ps[0];
    }
    return p;
}

var p = StartKabuS();
if (p == null) {
    Console.WriteLine("KabuS is not running");
}

Upvotes: 0

Views: 16

Answers (0)

Related Questions