MailSharp / MailSharp.WebManager / _install.cmd
Code · 55 lines · 1411 bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55@echo off
setlocal

net session >nul 2>&1
if %ERRORLEVEL% neq 0 (
    echo ERROR: Run this script as Administrator.
    pause
    exit /b 1
)

set SERVICE_NAME=MailSharp
set EXE_PATH=%~dp0MailSharp.WebManager.exe

if not exist "%EXE_PATH%" (
    echo ERROR: Executable not found: %EXE_PATH%
    pause
    exit /b 1
)

echo Stopping existing service (if running)...
sc stop %SERVICE_NAME% >nul 2>&1
timeout /t 3 /nobreak >nul

echo Removing existing service (if present)...
sc delete %SERVICE_NAME% >nul 2>&1
timeout /t 2 /nobreak >nul

echo Creating service...
sc create %SERVICE_NAME% binPath= "\"%EXE_PATH%\"" DisplayName= "MailSharp" start= delayed-auto
if %ERRORLEVEL% neq 0 (
    echo ERROR: Failed to create service.
    pause
    exit /b 1
)

echo Configuring service dependencies...
sc config %SERVICE_NAME% depend= Eventlog/RPCSS/Dhcp

echo Configuring failure actions (restart after 60s, three times)...
sc failure %SERVICE_NAME% reset= 86400 actions= restart/60000/restart/60000/restart/60000

echo Setting service start timeout...
REG ADD "HKLM\SYSTEM\CurrentControlSet\Control" /v ServicesPipeTimeout /t REG_DWORD /d 120000 /f >nul

echo Starting service...
sc start %SERVICE_NAME%
if %ERRORLEVEL% neq 0 (
    echo WARNING: Service created but failed to start. Check Event Viewer for details.
    pause
    exit /b 1
)

echo.
echo Service "%SERVICE_NAME%" installed and started successfully.
pause