Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to use a window service to open a webpage or run an exe file,can someone tell me how to do this.(window 7,vs2010)

my code is like this:
C#
public partial class Service1 : ServiceBase
    {
        public Service1()
        {
            InitializeComponent();

            System.Timers.Timer t = new System.Timers.Timer();
            t.Interval = 1000;
            t.Elapsed += new System.Timers.ElapsedEventHandler(RunWork);
            t.AutoReset = true;
            t.Enabled = true;
        }

        protected override void OnStart(string[] args)
        {
        }
        public void RunWork(object source, System.Timers.ElapsedEventArgs e)
        {


                File.Open(@"E:\1.txt", FileMode.Open);
                File.Open(@"E:\2.txt", FileMode.OpenOrCreate);

                System.Diagnostics.Process.Start("http://www.baidu.com");
                 //It doesn't run


}
}
Posted
Updated 16-Apr-12 22:02pm
v4

Try this:

C#
using System.Diagnostics; 
... 
Process proc = new Process(); 
proc.StartInfo = new ProcessStartInfo("IExplore.exe", "http://www.baidu.com");

proc.Exited += new EventHandler(Your_Process_Exited_Handler_Here);

proc.Start(); 


hope it helps :)
 
Share this answer
 
v2
Comments
harry~ 17-Apr-12 3:49am    
Thank you for your answer, but it also doesn't work.
See this link may help you or not

http://forums.asp.net/t/1413608.aspx/1[^]
 
Share this answer
 
Comments
harry~ 18-Apr-12 22:11pm    
Thank you.
sravani.v 18-Apr-12 23:30pm    
Welcome Harry

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900