In Windowservice with Process.Start () Launcher no interface-record

Source: Internet
Author: User

Original: In Windowservice with Process.Start () Launcher no interface-record

1.在服务程序安装时编程实现,ProjectInstaller.csusingSystem;usingSystem.Collections;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Configuration.Install;//using System.Linq;usingMicrosoft.Win32; //对注册表操作一定要引用这个命名空间namespaceMonitorService{    [RunInstaller(true)]    public partial classProjectInstaller : Installer    {        publicProjectInstaller()        {            InitializeComponent();                        //this.Context.Parameters["ServerCode"].ToString(); // 读取安装时输入的服务器编号                   }        privatevoidProjectInstaller_AfterInstall(objectsender, InstallEventArgs e)        {            //设置允许服务与桌面交互            SetServiceTable("MonitorService");                    }        /// <summary>        /// 设置允许服务与桌面交互 ,修改了注册表,要重启系统才能生效        /// </summary>        /// <param name="ServiceName">服务程序名称</param>        privatevoidSetServiceTable(string ServiceName)        {            RegistryKey rk = Registry.LocalMachine;            stringkey = @"SYSTEM\CurrentControlSet\Services\"+ ServiceName;            RegistryKey sub = rk.OpenSubKey(key, true);            intvalue = (int)sub.GetValue("Type");            sub.SetValue("Type", value | 256);        }    }}2.注册表修改onstart的时候修改注册表      [HKEY_LOCAL_MACHINE"SYSTEM"CurrentControlSet"Services"你的服务名]      "Type"=dword:00000010      key    value+256      比如现在00000010是16+256=272      16精制就是00000110 3.SC程序修改, 允许与桌面进行交互 在dos命令提示符下输入:sc config MonitorService type= interact type= own  回车即可。可以用批处理的方式实现,把下面代码保存为 myservice.bat 即可: rem 配置服务程序为允许与桌面进行交互方式@echo "准备停止服务程序..."sc stop MyService@echo "设置允许与桌面进行交互方式允许"sc config MyService type= interact type= own@echo "正在重新启动服务..."sc start MyService@echo "启动服务成功!"取消“允许与桌面进行交互”DOS命令提示符下运行下面语句即可: sc config MyService type= own经测试:1,2 可以选中“允许与桌面进行交互”,但启动服务的时候,不能弹出应用程序的界面。           3 可以完美实现所有要求。

On the Login tab of the properties of the service, check the Allow service to interact with the desktop and try again.

In Windowservice with Process.Start () Launcher no interface-record

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.