简体   繁体   English

具有不同名称的服务安装程序

[英]Service installer with a different name

I am using below cmd code to install a windows service 我正在使用下面的cmd代码安装Windows服务

        @echo off
    :: BatchGotAdmin
    ::-------------------------------------
    REM  --> Check for permissions
    >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

    REM --> If error flag set, we do not have admin.
    if '%errorlevel%' NEQ '0' (
        echo Requesting administrative privileges...
        goto UACPrompt
    ) else ( goto gotAdmin )

    :UACPrompt
        echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
        set params = %*:"="
        echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

        "%temp%\getadmin.vbs"
        del "%temp%\getadmin.vbs"
        exit /B

    :gotAdmin
        pushd "%CD%"
        CD /D "%~dp0"
    ::--------------------------------------

    ::ENTER YOUR CODE BELOW:
    cmd /k "C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil -i C:\fgbk\WindowsService\installer\OurIntegrationService.exe"

So this creates a service with name OurIntegrationService and i want to create another instance of same service with a different name OurIntegrationServiceStage 因此,这将创建一个名称为OurIntegrationService的服务,而我想创建一个名称为OurIntegrationServiceStage的同一服务的另一个实例

How can i do this ? 我怎样才能做到这一点 ?

The ServiceName identifies the service to the Service Control Manager. ServiceName向服务控制管理器标识服务。 The value of this property must be identical to the name recorded for the service in the ServiceInstaller.ServiceName property of the corresponding installer class. 此属性的值必须与相应安装程序类的ServiceInstaller.ServiceName属性中为服务记录的名称相同。 In code, the ServiceName of the service is usually set in the main() function of the executable. 在代码中,通常在可执行文件的main()函数中设置服务的ServiceName。

https://docs.microsoft.com/en-us/dotnet/api/system.serviceprocess.servicebase.servicename?view=netframework-4.7.2 https://docs.microsoft.com/en-us/dotnet/api/system.serviceprocess.servicebase.servicename?view=netframework-4.7.2

To give a different name, I suggest you change the service (if you have the code) to read name from app.config, or any other config location. 要提供其他名称,建议您更改服务(如果有代码)以从app.config或任何其他配置位置读取名称。

You can also change the display name (not the service name) by directly changing it in registry. 您还可以通过直接在注册表中更改显示名称(而不是服务名称)来进行更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM