I've spent the last 2 hours trying every conceivable way to create a service using sc.exe and pass arguments but I can't seem to get it right.
I've read this SO question and all the answers about 5 times and it's been no help!
From what I read there it seems I should construct the command like this:
sc create MyService binPath= "C:\path\to\myservice.exe --param1=TestString"
My Service OnStart
method looks like this:
Protected Overrides Sub OnStart(ByVal args() As String)
If Not IsNothing(args) Then
Library.WriteLog("Number of args = " & args.Count)
If args.Count > 0 Then
For i = 0 To args.Count - 1
Library.WriteLog("Arg" & i & ": " & args(i))
Next
End If
End If
End Sub
But everything I've tried yields "Number of Args = 0" in the log
For clarity I've tried the following (plus a few more probably):
sc create MyService binPath= "C:\path\to\myservice.exe --param1=TestString"
sc create MyService binPath= "C:\path\to\myservice.exe --TestString"
sc create MyService binPath= "C:\path\to\myservice.exe --param1=\"TestString\""
sc create MyService binPath= "C:\path\to\myservice.exe -param1=TestString"
sc create MyService binPath= "C:\path\to\myservice.exe -TestString"
sc create MyService binPath= "C:\path\to\myservice.exe -param1=\"TestString\""
I must be missing something really silly here but I'm banging my head off a wall with it!