When the service starts, there are two different argument lists.
The first is taken from the command line, as shown in the "path to the executable" in the administrative tool "Services". Here you put the argument 8081, as shown in the screenshot.
In the .NET service, these arguments are passed to the Main() function.
The second is the service start options that are provided when the service starts manually. If you use the "Service" utility tool to start the service, this argument list is taken from the "start parameters" field, which is empty in your screenshot.
In the .NET service, these arguments are passed to the OnStart() function.
Therefore, in your script, you must modify Main() so that it passes command-line arguments to the service class. You usually provide them in the constructor, although you can use a global variable if you want.
(See also this answer for a more detailed description of starting the service.)
source share