第一种方法:

1. 开始 ->运行 ->cmd

2. cd到C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727(Framework版本号按IIS配置)

3. 安装服务: 运行命令行 InstallUtil.exe E:/test.exe

卸载服务: 运行命令行 InstallUtil.exe -u E:/test.exe

这样就能删除了,但如果还是不能删除的话,没关系下面还有一种方法。

第二种方法:

运行-->cmd-->到c:\windows\system32文件夹下-->输入sc delete <服务名称>,然后就可以把服务卸载了

这时候,我们可以用另外一个命令来卸载,如下:

C:\WINDOWS\system32>sc delete MyService

其中的 MyService 是你的服务的名字,比如如下的服务截图,它的卸载命令就可以如下写:

sc delete "服务名"

当然你也可以用这个工具create,start,stop服务。比如,我们就可以用下面的命令,安装服务,并把服务启动起来。

installutil HongjunGuo.JobsWindowsService.exe

sc start "服务名"

C# 卸载windows服务

//卸载服务
        private void btnUninstall_Click(object sender, EventArgs e)
        {
            string path = GetWindowsServiceInstallPath("KylintechService");
            string p_Path = path + "\\Kylintech_Service.exe";
            string p_ServiceName = "KylintechService";
            UnInstallService(p_Path, p_ServiceName);
            this.lblStart.Text = "状态:服务已卸载";
        }

//二、卸载windows服务:
        private void UnInstallService(string filepath, string p_ServiceName)
        {
            try
            {
                if (ServiceIsExisted(p_ServiceName))
                {
                    //UnInstall Service
                    AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller();
                    myAssemblyInstaller.UseNewContext = true;
                    myAssemblyInstaller.Path = filepath;
                    myAssemblyInstaller.Uninstall(null);
                    myAssemblyInstaller.Dispose();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("unInstallServiceError\n" + ex.Message);
            }
        }

//三、判断window服务是否存在:
        private bool ServiceIsExisted(string serviceName)
        {
            ServiceController[] services = ServiceController.GetServices();
            foreach (ServiceController s in services)
            {
                if (s.ServiceName == serviceName)
                {
                    return true;
                }
            }
            return false;
        }

用命令 安装/卸载 windows服务(转)的更多相关文章

  1. 二种方法安装卸载Windows服务的命令

    第一种方法:通过Dos命令安装系统服务1. 开始 运行输入 cmd 进入dos窗口2. cd命令进入到C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727目录下, ...

  2. 安装&卸载Windows服务

    使用.NET Framework的工具InstallUtil.exe. 安装服务 C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.e ...

  3. C# 远程服务器 安装、卸载 Windows 服务,读取远程注册表,关闭杀掉远程进程

    这里安装windows服务我们用sc命令,这里需要远程服务器IP,服务名称.显示名称.描述以及执行文件,安装后需要验证服务是否安装成功,验证方法可以直接调用ServiceController来查询服务 ...

  4. 使用InstallUtil安装及卸载Windows服务的具体操作 Visual Studio 2012版本

    关于Visual Studio 2012中使用InstallUtil对Windows服务进行安装与卸载的文章,在MSDN中的http://msdn.microsoft.com/en-us/librar ...

  5. 批处理文件安装与卸载Windows服务

    //安装Windows服务 将RECPost.exe和RECPostService替换成自己的项目名称和服务名称,并将文件保存成bat格式.其中%cd%是获取相对路径 @echo off set fi ...

  6. 【先定一个小目标】Redis 安装成windows服务-开机自启

    1.第一步安装成windows服务的,开机自启动 redis-server --service-install redis.windows.conf 2.启动\关闭 redis-server --se ...

  7. 【C#】使用bat文件安装卸载Window服务

    1.安装服务 @echo off @title 安装windows服务path %SystemRoot%\Microsoft.NET\Framework\v4.0.30319echo========= ...

  8. Redis是可以安装成windows服务-开机自启

    其实Redis是可以安装成windows服务的,开机自启动,命令如下 redis-server --service-install redis.windows.conf 安装完之后,就可看到Redis ...

  9. 使用srvany.exe将程序安装成windows服务的详细教程

    srvany.exe介绍 srvany.exe是Microsoft Windows Resource Kits工具集的一个实用的小工具,用于将任何EXE程序作为Windows服务运行.也就是说srva ...

随机推荐

  1. easyui combobox 智能提示搜索

    <!-- 获取机会点名称列表 --><script> function initOpportunityNameFuzzyQuery() { $('#jihuidianmingc ...

  2. 图像fft和wavelet变换矩阵和向量区别 dwt2和wavedec2联系

    1.  对于小波变换,dwt2 :单级离散2维小波变换 wavedec2 :多级2-D小波分解 matlab中这两者联系是都能对图像进行小波分解,区别是dwt2是二维单尺度小波变换,只能对输入矩阵X一 ...

  3. windows redis:Uncaught exception 'RedisException' with message 'Redis server went away'

    window-exe-redis-2.8.12服务,当你复制好php_igbinary.dll,php_redis.dll时候,你运行redis报错:Fatal error: Uncaught exc ...

  4. HTML5自学笔记[ 7 ]defer和async

    defer:给位于最前面的script标签设置defer="defer",外联js就会在onload触发之前才加载. async:给script标签设置async="as ...

  5. Qt之Threads和QObjects

    简述 QThread继承自QObject,它发射信号(signals)以表明线程执行开始或结束,并提供了一些槽函数(slots). 更有趣的是,QObjects可以在多线程中使用,发射信号以在其它线程 ...

  6. IO流--文件处理

    import java.io.*; public class io { public static void main(String[] args) { ListDemo(); File dir = ...

  7. Angularjs学习——(一)

    去年就接触过AngularJS吧,只可惜那时候仅仅是跟着“老大”机械的完成了“饿了么”——一个单页面的手机App,而其中的什么原理,怎样来实现,自己也是似懂非懂,直至今天自己再次拿起来它,并一个人来研 ...

  8. WCF练习小程序总结

    1.什么是WCF 严格的说,WCF就是专门用于服务定制.发布与运行以及消息传递和处理的一组专门类的集合,也就是所谓的“类库”.这些类通过一定方式被组织起来,共同协 作,并为开发者提供了一个统一的编程模 ...

  9. .net matlab 数据类型转换

    http://wenku.baidu.com/link?url=HWqh7fna8d4UKz7FniwMzaqC5aW2M4wi5H-lWaRXDlxJlJsPilK_tjMDgRBnNiw7rjTm ...

  10. Tomcat性能调优-让小猫飞奔[转]

      http://blog.csdn.net/lifetragedy/article/details/7708724   http://blog.csdn.net/lifetragedy/articl ...