最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Process.Start does not work on TAskScheduler - Stack Overflow

programmeradmin0浏览0评论

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\\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");
}
发布评论

评论列表(0)

  1. 暂无评论