jindalee
asked on
Running an exe file as a servcie
I have an application I am building that a customer wants to run both as a service (without windows, dialogs etc) and, occasionally, as a full blown Windows application with all the bells and whistles.
Their idea is that they can schedule a job to run when the network is quiet but also have the ability, if required, for an admin user to run the program.
Is this possible or do I have to re-write as a service?
Their idea is that they can schedule a job to run when the network is quiet but also have the ability, if required, for an admin user to run the program.
Is this possible or do I have to re-write as a service?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You could create the app as a Console App, which inherits System.ServiceProcess.Serv iceBase.
Then, depending on which arguments are passed to the Main(args() as string) method, you can either start it as a service, or as a windows form application
Then, depending on which arguments are passed to the Main(args() as string) method, you can either start it as a service, or as a windows form application
class Foo inherits System.ServiceProcess.ServiceBase
public shared sub Main(args() as string)
if (args.length == 0) then
System.ServiceProcess.ServiceBase.Run(new Foo())
else
Application.Run(new Form1())
end if
end sub
protected override sub OnStart(args() as string)
end sub
protected override sub OnStop()
end sub
end class
Oops, my Vb is a tad rusty
class Foo inherits System.ServiceProcess.ServiceBase
public shared sub Main(args as string())
if (args.length = 0) then
System.ServiceProcess.ServiceBase.Run(new Foo())
else
Application.Run(new Form1())
end if
end sub
protected override sub OnStart(args as string())
end sub
protected override sub OnStop()
end sub
end class
ASKER
I'll have to translate from C# ti VB I guess butthis looks to me to be the best answer
As an alternative, you could load the EXE from the Windows service using AppDomain class. check out the example code I gave. This way, you can run the EXE from the windows service, plus you could run the EXE manually. Alos check out these links:
http://msdn.microsoft.com/
http://it.toolbox.com/blog
Cheers.
Jas.
Open in new window