有什么方法可以从Windows Service启动应用程序/进程. [英] What are all the ways to launch the application/process from Windows Service.
问题描述
大家好,
我有以下要求和以下方法:
I am having the following requirement and the below approaches:
方法1:在系统启动时启动应用程序/进程.我尝试过的是将应用程序连接到无法在系统引导上运行的寄存器启动.
Approach1 : Launch the application/process on system startup. What I have tried is wring the application to the register startup which is not working on system boot.
方法2:使用" CreateProcessAs用户"从Windows服务启动应用程序/进程. api方法.即使采用这种方法,我也无法解决问题.
Approach2 : Launch the application/process from windows service, using the "CreateProcessAs User" api method. Even with this approach also I am not getting the solution.
需要一些有关解决问题的指南,或在系统启动时启动应用程序的任何其他方法.
Need some guidance on fixing the issues or any other approach to launch the application on system startup.
注意:我必须使用C#以编程方式进行此操作.
Note: I have to do this programatically in C#.
推荐答案
嗨shekar.chandra,
Hi shekar.chandra,
谢谢您在这里发布.
对于您的问题,请尝试以下代码.
For your question, please try the following code.
在运行程序之前,启动页面如下.
Before I run the program, the startup page is below.
这是代码.当我将RegisterInStartup的值设置为true时,该应用程序将添加到启动页面.如果将值设置为false,则应用程序将在启动页面中删除.
Here is the code. When i set the value of RegisterInStartup true, the application will be add to the startup page. If I set the value false, the application will delete in startup page.
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;
namespace set_startup_application
{
class Program
{
static void Main(string[] args)
{
RegisterInStartup(true);
}
private static void RegisterInStartup(bool isChecked)
{
RegistryKey registryKey = Registry.CurrentUser.OpenSubKey
("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (isChecked)
{
registryKey.SetValue("listview.exe", @"C:\Users\v-wezan\Documents\Visual Studio 2015\Projects\WindowsFormsApplication\listview\bin\Debug");
}
else
{
registryKey.DeleteValue("listview.exe");
}
}
}
}
这是输出.
我希望这会对您有所帮助.
I hope this would be helpful to you.
如果还有其他问题,请随时与我们联系.
If you have something else, please feel free to contact us.
最好的问候,
温迪
这篇关于有什么方法可以从Windows Service启动应用程序/进程.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!