用命令 安装/卸载 windows服务(转)
第一种方法:
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服务(转)的更多相关文章
- 二种方法安装卸载Windows服务的命令
第一种方法:通过Dos命令安装系统服务1. 开始 运行输入 cmd 进入dos窗口2. cd命令进入到C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727目录下, ...
- 安装&卸载Windows服务
使用.NET Framework的工具InstallUtil.exe. 安装服务 C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.e ...
- C# 远程服务器 安装、卸载 Windows 服务,读取远程注册表,关闭杀掉远程进程
这里安装windows服务我们用sc命令,这里需要远程服务器IP,服务名称.显示名称.描述以及执行文件,安装后需要验证服务是否安装成功,验证方法可以直接调用ServiceController来查询服务 ...
- 使用InstallUtil安装及卸载Windows服务的具体操作 Visual Studio 2012版本
关于Visual Studio 2012中使用InstallUtil对Windows服务进行安装与卸载的文章,在MSDN中的http://msdn.microsoft.com/en-us/librar ...
- 批处理文件安装与卸载Windows服务
//安装Windows服务 将RECPost.exe和RECPostService替换成自己的项目名称和服务名称,并将文件保存成bat格式.其中%cd%是获取相对路径 @echo off set fi ...
- 【先定一个小目标】Redis 安装成windows服务-开机自启
1.第一步安装成windows服务的,开机自启动 redis-server --service-install redis.windows.conf 2.启动\关闭 redis-server --se ...
- 【C#】使用bat文件安装卸载Window服务
1.安装服务 @echo off @title 安装windows服务path %SystemRoot%\Microsoft.NET\Framework\v4.0.30319echo========= ...
- Redis是可以安装成windows服务-开机自启
其实Redis是可以安装成windows服务的,开机自启动,命令如下 redis-server --service-install redis.windows.conf 安装完之后,就可看到Redis ...
- 使用srvany.exe将程序安装成windows服务的详细教程
srvany.exe介绍 srvany.exe是Microsoft Windows Resource Kits工具集的一个实用的小工具,用于将任何EXE程序作为Windows服务运行.也就是说srva ...
随机推荐
- commonJS — 数组操作(for Array)
for Array github: https://github.com/laixiangran/commonJS/blob/master/src/forArray.js 代码 /** * Creat ...
- java 基础(第一天)
1. 一个文件里面只能有一个 public 修饰的方法 且方法名与文件名保持一致. 如: public class main(){ } class car(){ } class dog(){ } ...
- jq实现某个标签内,达到一定字数后,剩下的用 ... 显示
$(".infom_con").each(function(){ var text=$(this).find("a").text(); var len=text ...
- hdu 1026 Ignatius and the Princess I (bfs+记录路径)(priority_queue)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1026 Problem Description The Princess has been abducted ...
- Node.js 开发模式(设计模式)
Asynchronous code & Synchronous code As we have seen in an earlier post (here), how node does th ...
- hdu----(1950)Bridging signals(最长递增子序列 (LIS) )
Bridging signals Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Simple Data
Git地址:https://github.com/markrendle/Simple.Data 来源:http://bbs.nfinal.com/read-13
- HTML5标签学习之~~~
<article> 标签 article 字面意思为“文章”.在web页面中表现为独立的内容,如一篇新闻,一篇评论,一段名言,一段联系方式.这其中包括两方面,一为整个页面的主旨内容,另外就 ...
- Codeforces Round #313 (Div. 2) C. Gerald's Hexagon
C. Gerald's Hexagon time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- for循环语句以及迭代法和穷举法
循环语句: 四要素:初始条件,循环条件,状态改变,循环体 for(初始条件;循环条件;状态改变){ //循环体} 案例1:打印等腰直角三角形和菱形 左上三角 static void Main(stri ...