TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ankit Agarwal
NA
379
254.1k
How to run external exe from windows service in C# .NET?
Aug 30 2016 2:38 PM
Hello,
How to run external exe from windows service in c# .net?
I want to run external exe from windows service but its getting error regarding just-in-time compilation.
I have tried this code in windows service.
protected override void OnStart(string[] args)
{
try
{
//Debugger.Break();
TraceService("Start Service" + " " + DateTime.Now.ToString());
//timer1.Interval = 1000;
timer1.Elapsed += new ElapsedEventHandler(OnElapsedTime);
timer1.Enabled = true;
//Debugger.Break();
}
catch (Exception ex)
{
TraceService("Error: " + ex);
//EventLog.WriteEntry("Error: " + ex.Message);
}
}
private void bw_DoWork(object sender, DoWorkEventArgs e)
{
Process proc = new Process();
//string DirectoryName = @"D:\TaskbarNotifierDemo.exe";
//RemoveDirectorySecurity(DirectoryName, "Administrators", FileSystemRights.ExecuteFile, AccessControlType.Deny);
proc.StartInfo = new ProcessStartInfo(@"D:\TaskbarNotifierDemo.exe");
//proc.StartInfo.UseShellExecute = true;
//proc.StartInfo.Verb = "runas";
proc.Start();
proc.WaitForExit();
base.Stop();
}
private void OnElapsedTime(object source, ElapsedEventArgs e)
{
bool connection = NetworkInterface.GetIsNetworkAvailable();
if (connection == true)
{
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.RunWorkerAsync();
}
}
Please help me.
Thanks in Advance.
Ankit Agarwal
Software Engineer
Reply
Answers (
7
)
Windows Service Application exe file not updating
UI Automation using Windows Service