powershellpowershell-dsc

Powershell DSC: Whats the recommendation if we want a process to be always running


I want a process (exe) to be always running on machine, even after it reboots. I've setup powershell DSC and currently I had it as a WindowsProcess and its not launched after reboot. Can someone tell me whats the recommended resource to be used for this scenario ?


Solution

  • You dont really need DSC for that, just create a service with startup type of auto with the sc command. plenty of examples online.

    sc create <servicename> binpath= "<pathtobinaryexecutable>" [option1] [option2] [optionN]
    

    You can use Service to create services as well. Something like this should work:

    configuration ServiceTest
    {
        Import-DscResource -ModuleName PSDesiredStateConfiguration
        Node localhost
        {
    
            Service ServiceExample
            {
                Name        = "TermService"
                StartupType = "Manual"
                State       = "Running"
                Path        = "path\to\binary
            }
        }
    }