sc命令以及InstallUtil安装service
1.安装
https://stackoverflow.com/questions/8164859/install-a-windows-service-using-a-windows-command-prompt
https://docs.microsoft.com/en-us/dotnet/framework/tools/installutil-exe-installer-tool
Navigate to the installutil.exe in your .net folder (for .net 4 it's C:\Windows\Microsoft.NET\Framework\v4.0.30319 for example) and use it to install your service, like this:
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe" "c:\myservice.exe"
C:\Windows\Microsoft.NET\Framework64\v4.0.30319
C:\Windows\Microsoft.NET\Framework\v4.0.30319
这两个路径下的InstallUtil.exe都可以使用,如果项目使用的是AnyCPU进行编译
需要注意的是:必须使用管理员权限运行命令行工具。
Example
installutil /servicename="LFXSVC_FileExchange5.0_20170818" /displayname="FileExchange5.0_SourceCode" /description="description of application" .\LISA.FileExchange.Service.exe
Remarks
需要注意的是,servicename不可以重复,并且displayname也不可以重复
2.移除,启动,停止
sc delete
C:\Windows\system32>sc delete LFXSVC_FileExchange5.0_20170831151735.535
[SC] DeleteService SUCCESS
sc start
sc stop
3.重命名Service
https://superuser.com/questions/975832/how-to-change-windows-service-name-after-creating-it
To change the display name of a service you can run:
sc config "Old service name" displayname= "New service name"
需要注意的是,config后面的参数是service name。这个必须通过服务的property才能看到,控制面板上显示的是DisplayName。
C:\Windows\system32>sc config LFXSVC_FileExchange5.0 DisplayName= "FileExchange5.0_Installer"
这个命令只在cmd中有效,在powershell中会遇到问题
PowerShell中的sc不是cmd中的,可以使用help sc查看
NAME
Set-Content
SYNTAX
Set-Content [-Path] <string[]> [-Value] <Object[]> [-PassThru] [-Filter <string>] [-Include <string[]>] [-Exclude <
string[]>] [-Force] [-Credential <pscredential>] [-WhatIf] [-Confirm] [-UseTransaction] [-NoNewline] [-Encoding <Fi
leSystemCmdletProviderEncoding> {Unknown | String | Unicode | Byte | BigEndianUnicode | UTF8 | UTF7 | UTF32 | Ascii
| Default | Oem | BigEndianUTF32}] [-Stream <string>] [<CommonParameters>]
Set-Content [-Value] <Object[]> -LiteralPath <string[]> [-PassThru] [-Filter <string>] [-Include <string[]>] [-Excl
ude <string[]>] [-Force] [-Credential <pscredential>] [-WhatIf] [-Confirm] [-UseTransaction] [-NoNewline] [-Encodin
g <FileSystemCmdletProviderEncoding> {Unknown | String | Unicode | Byte | BigEndianUnicode | UTF8 | UTF7 | UTF32 |
Ascii | Default | Oem | BigEndianUTF32}] [-Stream <string>] [<CommonParameters>]
ALIASES
sc
REMARKS
Get-Help cannot find the Help files for this cmdlet on this computer. It is displaying only partial help.
-- To download and install Help files for the module that includes this cmdlet, use Update-Help.
-- To view the Help topic for this cmdlet online, type: "Get-Help Set-Content -Online" or
go to http://go.microsoft.com/fwlink/?LinkID=113392.
4.查询服务
http://www.cnblogs.com/chucklu/p/5847330.html 查看这篇文章里的1.5
http://www.cnblogs.com/chucklu/p/7248604.html
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2016-07-11 TeeChart曲线平滑 Line.Smoothed
2014-07-11 UDP的socketasynceventargs
2014-07-11 项目管理,各种文件的存放位置