简体   繁体   中英

Service installer with a different name

I am using below cmd code to install a windows service

        @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

How can i do this ?

The ServiceName identifies the service to the Service Control Manager. 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. In code, the ServiceName of the service is usually set in the main() function of the executable.

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.

You can also change the display name (not the service name) by directly changing it in registry.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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