JAR file as a Windows Service – Service cannot be started. System.ComponentModel.Win32Exception: The directory name is invalid

I’m trying to run a Spring Boot application JAR file as a Windows service using procrun. I’ve installed the service and it was listed in Windows Services. When I’ve started the service, it stopped after few seconds, and in the Event Viewer log, the below error came

Service cannot be started. System.ComponentModel.Win32Exception: The directory name is invalid
   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
   at winsw.Util.ProcessHelper.StartProcessAndCallbackForExit(Process processToStart, String executable, String arguments, Dictionary`2 envVars, String workingDirectory, Nullable`1 priority, ProcessCompletionCallback callback, Boolean redirectStdin, LogHandler logHandler, Boolean hideWindow)
   at winsw.WrapperService.StartProcess(Process processToStart, String arguments, String executable, LogHandler logHandler, Boolean redirectStdin)
   at winsw.WrapperService.OnStart(String[] args)
   at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)

This is the .bat file script I have used for installation of Service.

@echo off
setlocal

REM Set variables
set SERVICE_NAME=E-invoice
set DISPLAY_NAME="E-invoice Service"
set DESCRIPTION="E-invoice API as a Windows Service"
set SERVICE_JAR=e-invoice.jar
REM I have also tried with Absolute path for classpath, still not worked
set PRUNSRV=D:procrunprunsrv.exe
set PRUNSRV_LOG=D:JARLogs%SERVICE_NAME%.log
set PRUNSRV_ERR=D:JARLogs%SERVICE_NAME%-error.log
set START_PATH=D:JAR

REM Check if directories and files exist
if not exist "%SERVICE_JAR%" (
  echo Error in Service JAR path
)
if not exist "%PRUNSRV%" (
  echo Error in prunsrv path
)
if not exist "%START_PATH%" (
  echo Error in start path
)
if not exist "D:JARLogs" (
    echo Log path not found: D:JARLogs
    mkdir "D:JARLogs"
    if %errorlevel% neq 0 (
      echo Failed to create log directory: C:spring-boot-applogs
    )
)

REM Install and configure the service with all parameters
%PRUNSRV% //IS//%SERVICE_NAME% ^
    --DisplayName="%DISPLAY_NAME%" ^
    --Description="%DESCRIPTION%" ^
    --Startup=auto ^
    --Install="%PRUNSRV%" ^
    --LogPath="D:JARLogs" ^
    --LogLevel=Debug ^
    --StdOutput="%PRUNSRV_LOG%" ^
    --StdError="%PRUNSRV_ERR%" ^
    --Jvm=auto ^
    --Classpath="%SERVICE_JAR%" ^
    --StartMode=Java ^
    --StartClass=org.springframework.boot.loader.JarLauncher ^
    --StartMethod=main ^
    --StartParams=start ^
    --StopMode=Java ^
    --StopClass=org.springframework.boot.loader.JarLauncher ^
    --StopMethod=main ^
    --StopParams=stop ^
    --LogLevel=Debug ^
    --Startup=auto ^
    --StartPath="%START_PATH%"

REM Check if the service installation was successful
if %errorlevel% neq 0 (
  echo Service installation failed
)

echo Service %SERVICE_NAME% installed and configured successfully.
exit /b 0

Additionally, the logs are also not generated in the specified directory. After running the command(procrun_install_service.bat) in administrator CMD, the below response came

[2024-07-07 22:32:56] [warn] [10624] Failed to grant service user ‘NT AUTHORITYLocalService’ write permissions to log path ‘C:Windowssystem32LogFilesApache’ due to error ’19: The media is write protected.’

Service E-invoice installed and configured successfully.

I’m new to this process and every time I’m getting stuck at somewhere, so your timely help will be highly appreciated..

Thanks in Advance..

New contributor

Sai from CDM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật