Windows service is not found in Amazon EC2 Windows Instance

Arjun Goel (DevOn) 0 Reputation points
2023-09-17T15:01:16.53+00:00

Hi Microsoft, I have deployed a windows service using CI/CD pipeline through GitHub Actions. The runner is self-hosted runner configured on Amazon EC2 instance. The weird part is the commands are working fine but the service name is not showing in services.msc console even after I did a lot of refresh but when I am doing it manually in the EC2 instance it is working absolutely fine. The instance size is t2.micro and the AMI is jammy 2022 Base Image.

What could be the potential reasons for this:

  1. Is it because of the instance type?
  2. Do I need to restart the server?
  3. Is it something else which I am not aware of?

Here is the CI/CD code:

name: "Deploying a CI/CD for Windows Service using GitHub Actions"

on:
  workflow_dispatch:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]

jobs:
  build:

      runs-on: windows-latest
      defaults:
        run:
          shell: cmd

      steps:
      - name: Checkout code repository
        uses: actions/checkout@v3
      
      - name: Setup MSBuild
        uses: microsoft/setup-msbuild@v1

      - name: Setup NuGet
        uses: NuGet/setup-nuget@v1.0.5

      - name: Restore Packages
        run: nuget restore WindowsServiceDemo.sln

      - name: Build solution
        run: msbuild WindowsServiceDemo.sln /p:Configuration=Release /p:DeployOnBuild=true

  deploy:
    needs: build
    runs-on: [ self-hosted, Windows, X64 ]
    defaults:
      run:
        shell: cmd
    
    steps:
    
     - name: Set AWS credentials
       uses: aws-actions/configure-aws-credentials@v1
       with:
         aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
         aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
         aws-region: ${{ secrets.AWS_REGION }}
         
     - name: Install a service using Powershell
       shell: powershell
       run: Start-Process powershell -ArgumentList 'New-Service -Name "WinServDemo" -BinaryPathName "D:\a\WindowsServiceDemo\WindowsServiceDemo\WindowsServiceDemo\bin\Release\WindowsServiceDemo.exe"' -Verb RunAs

     - name: Start a service using Poweshell
       shell: powershell
       run: Start-Process powershell -ArgumentList 'Start-Service -Name "WinServDemo"' -Verb RunAs

     - name: Display the service status
       shell: powershell
       run: Start-Process powershell Get-Service -Verb RunAs

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,911 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.