窗口服务无法触发exe [英] Window services cant trigger exe

查看:106
本文介绍了窗口服务无法触发exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在c#

中创建一个窗口服务以在特定时间运行exe。但是它可以打开那个exe,

下面是代码





  private   static   string  checkdatentime()
{
currentdate = DateTime.Now;
string value = 1;
for int i = 0 ; i < xml_date.Count; i ++)
{
value = 2;
if (currentdate.Date < xml_date [i] .Date)
{
value = 3;
break ;
// 一边走一圈;

}
else if (currentdate.Date > xml_date [i] .Date)
{
value = 4;
// 不执行任何操作意味着循环继续

}
else
{
value = 5;
// 如果两个日期相同

if (currentdate.Date == xml_date [i] .Date)
{
value = 99;
currentTime = currentdate.ToString( hh:mm);
TriggerTime = newItem.TriggerTime.ToString( hh:mm);

if (currentTime == TriggerTime)
{
value = 6;
// 运行EXE
System.Diagnostics.Process.Start( E:\\SqlBackup_Programs \\console-backup \\Backup_Console_App 22July Latest\\Backup_Console_App\\ \\\Backup_Console_App\\bin\\Debug\\Backup_Console_App);
return value ;
}

}


}


}

return value ;
}







注意:这里我返回值因为验证是我的代码运行正确与否,并在文本文件上写入VALUE,所以同时我得到VALUE = 6,意味着代码没有问题,

但仍然服务无法打开这个exe,

通过相同的代码我制作了控制台应用程序并且它的运行完美,所以为什么不运行?



这是命令的任何问题,





 System.Diagnostics.Process.Start(); 





请帮助我!!

解决方案

Windows服务无法使用用户界面运行/启动进程。没有办法解决这个问题,这是设计的。



Eduard


我得到了答案,我检查了选项Windows服务属性中的允许与桌面交互现在它正在工作。 : - )

I make one window service in c#
to run exe on particular time., but it could open that exe,
Below is code


private static string   checkdatentime()
       {
           currentdate = DateTime.Now;
           string value = "1";
           for (int i = 0; i < xml_date.Count; i++)
           {
               value = "2";
               if (currentdate.Date < xml_date[i].Date)
               {
                   value = "3";
                   break;
                   // go out side for loop;

               }
               else if (currentdate.Date > xml_date[i].Date)
               {
                   value = "4";
                   //Do nothing means loops continues

               }
               else
               {
                   value = "5";
                   //if both date are same

                   if (currentdate.Date == xml_date[i].Date)
                   {
                       value = "99";
                       currentTime = currentdate.ToString("hh:mm");
                       TriggerTime = newItem.TriggerTime.ToString("hh:mm");

                       if (currentTime == TriggerTime)
                          {
                              value = "6";
                           //Run EXE
                              System.Diagnostics.Process.Start("E:\\SqlBackup_Programs\\console-backup\\Backup_Console_App 22July Latest\\Backup_Console_App\\Backup_Console_App\\bin\\Debug\\Backup_Console_App");
                           return value;
                        }

                   }


               }


           }

           return value;
       }




NOTE: here I return value because to verify is my code runs correct or not and write VALUE on text file, so on same time I am getting VALUE=6, means there is no problem in code,
But still service cant open this exe,
by same code i made console application and its runs perfectly, so why not services??

Is this any problem with command,


System.Diagnostics.Process.Start();



kindly help me!!

解决方案

A Windows service just cannot run/start a process with a user interface. There is no way to solve this, it's by design.

Eduard


I got the answer, I had checked the option "Allow to interact with the Desktop" in the Windows service properties And now its Working. :-)


这篇关于窗口服务无法触发exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆