Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass arguments to windows services in c#?

I just want to know how to pass arguments to windows services . The problem is , i am developed a windows application and then called it from Onstart() method . Now , i want to call the particular function from another project .

 protected override void OnStart(string[] args)
        {

            Process.Start("C:\\Program Files\\macro.exe");

        }

I want to call a function inside the macro.exe project with arguments . Any suggestions

like image 701
eurekha_ananth Avatar asked Jan 31 '26 16:01

eurekha_ananth


1 Answers

If you want to use arguments passed to service, you can try:

Process.Start(@"C:\Program Files\macro.exe", String.Join(" ", args))

Note that using @Tudor answer you can have better control on started process, redirect input/output/error, show/hide window and many other nice things.

like image 169
Marco Avatar answered Feb 03 '26 04:02

Marco