|
Hi!
This code Service1. Service call notepad.exe (with my form the same). In task manager on tab process I see notepad.exe. But on tab application it is not.
using System;
using System.ServiceProcess;
using System.Windows.Forms;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Drawing;
using System.Collections;
namespace InteractiveService
{
public class Service1 : System.ServiceProcess.ServiceBase
{
private System.Diagnostics.EventLog eventLog1;
private System.ComponentModel.Container components = null;
public Service1()
{
InitializeComponent();
}
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service1() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
private void InitializeComponent()
{
this.eventLog1 = new System.Diagnostics.EventLog();
((System.ComponentModel.ISupportInitialize)(this.eventLog1)).BeginInit();
this.eventLog1.Log = "Application";
this.eventLog1.Source = "InteractiveService";
this.CanHandlePowerEvent = true;
this.CanHandleSessionChangeEvent = true;
this.CanPauseAndContinue = true;
this.CanShutdown = true;
this.ServiceName = "InteractiveService";
((System.ComponentModel.ISupportInitialize)(this.eventLog1)).EndInit();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
protected override void OnStart(string[] args)
{
try
{
InteractiveService.MakeServiceInteractive();
eventLog1.WriteEntry("Service Started Succesfully");
startprc(@"C:\WINDOWS\system32\notepad.exe");
eventLog1.WriteEntry("Started Process Succesfully");
}
catch (System.Exception ex)
{
eventLog1.WriteEntry(String.Format("Service OnStart ERROR :'" + ex.Message + "'"));
}
}
protected override void OnStop()
{
eventLog1.WriteEntry("Service Stoped Succesfully");
Killprc("notepad");
}
protected override void OnContinue()
{
eventLog1.WriteEntry("Service work started after pause succesfully");
}
protected override void OnPause()
{
eventLog1.WriteEntry("Service work paused succesfully");
}
private void startprc(string prcName)
{
try
{
eventLog1.WriteEntry(String.Format("startprc :'" + prcName + "'"));
ShellLib.ShellExecute shellExecute = new ShellLib.ShellExecute();
shellExecute.Path = prcName;
shellExecute.Execute();
}
catch (System.Exception ex)
{
eventLog1.WriteEntry(String.Format("Service work start process ERROR :'" + ex.Message + "'"));
}
}
private void Killprc(string processName)
{
foreach (Process p in System.Diagnostics.Process.GetProcessesByName(processName))
{
try
{
p.Kill();
p.WaitForExit();
eventLog1.WriteEntry(String.Format("Process Kill Succesfully :'" + processName + "'"));
}
catch (InvalidOperationException invalidException)
{
eventLog1.WriteEntry(String.Format("process has already exited - might be able to let this one go, InvalidOperationException :'" + invalidException + "'"));
}
catch (System.Exception ex)
{
eventLog1.WriteEntry(String.Format("Service work start process, System.Exception :'" + ex.Message + "'"));
}
}
}
}
}
In this case, Form call notepad.exe (with my form the same). In task manager on tab process I see notepad.exe. And on tab application I see notepad.exe too.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WinTester2
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox grpLaunchApp;
private System.Windows.Forms.Button btnExploreFolder;
private System.Windows.Forms.Button btnFindInFolder;
private System.Windows.Forms.Button btnEditBmp;
private System.Windows.Forms.Button btnShowBmp;
private System.Windows.Forms.Button btnOpenExe;
private System.Windows.Forms.GroupBox grpFileOp;
private System.Windows.Forms.Button btnCopy;
private System.Windows.Forms.Button btnMove;
private System.Windows.Forms.Button btnDelete;
private System.Windows.Forms.Button btnClearList;
private System.Windows.Forms.Button btnAddFile;
private System.Windows.Forms.GroupBox grpRecentDocs;
private System.Windows.Forms.GroupBox grpPrinter;
private System.Windows.Forms.Button btnOpenPrinter;
private System.Windows.Forms.Button btnShowProperties;
private System.Windows.Forms.Button btnTestPage;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void btnOpenExe_Click(object sender, System.EventArgs e)
{
ShellLib.ShellExecute shellExecute = new ShellLib.ShellExecute();
shellExecute.Path = @"C:\WINDOWS\system32\notepad.exe";
shellExecute.Execute();
}
}
}
I think that this is the reason that myForm is not working as it should be.
What can I run the myForm from the service, that it should appear on the tab application? Or how to make a different decision?
|
|
|
|
|
Services are not supposed to open any kind of window, that's why it fails, the main purpose of a service is to run background "formless" processes. I want to die like my grandfather- asleep, not like the passengers in his car, screaming!
|
|
|
|
|
|
Another question. How to do the visualize without form, which could run from the service? May service run the form as a background process?
|
|
|
|
|
If I set checkbox interactive desctop in my service, my form runs as aplication, but it disabled and not call form_load(). How can I get around?
|
|
|
|
|
http://www.cyberforum.ru/windows-forms/thread101334.html#post580926
|
|
|
|
|
Ask the question here. Don't post a link I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Message Closed
modified 23-Nov-14 6:40am.
|
|
|
|
|
When I wish to use listBox1 in a thread gives out an error:
"Cross-thread operation not valid: Control 'listBox1' accessed from a thread other
than the thread it was created on.".
I badly understand delegates.
public delegate void ListBoxCallback(string s);
public void listBox_1_ItemsAdd(string value1)
{
ListBoxCallback callback = new ListBoxCallback(listBox_1_ItemsAdd);
Invoke(callback); // Here a problem: "parameter count mismatch"
listBox1.Items.Add(value1);
}
I transfer to a method listBox_1_ItemsAdd string value value1.
listBox_1_ItemsAdd(dataGridView1[2, i].Value.ToString());
Also, how to transfer parametre here.
private delegate void ChangeProgressBarCallback(int size);
public void changeProgressBar(int MaxSize)
{
if (progressBar1.InvokeRequired)
{
// instantiate the callback instance out of this very method
ChangeProgressBarCallback callback = new ChangeProgressBarCallback(changeProgressBar);
// invoke it, when it comes to it again InvokeRequired will be false
Invoke(callback);
}
else
{
progressBar1.Minimum = 0;
progressBar1.Maximum = MaxSize;
progressBar1.Step = 1;
for (int x = 1; x <= MaxSize; x++)
{
progressBar1.PerformStep();
}
}
}
How to transfer parametre in the delegate.
That I to do not so prompt please
|
|
|
|
|
hello,
I write to excel in my project (c#.net) and i do that white command "File.AppendAlltText(filename,string);"
this is a simple way to write file in .net .
Now i need to add color and bold word in my excel file.
i cant do that with that command or i need to use a different command?
Thank You and Good Shabec!!
|
|
|
|
|
|
I know this, but more comfortable working with File.AppendAllText(filename,string);
You may not know a way to do it via File command?
|
|
|
|
|
You've been given the correct way to accomplish the task. You're on you own if you want something else. I know the language. I've read a book. - _Madmatt
|
|
|
|
|
|
File.AppendAllText works for text file. An excel spreadsheet is not a text file, so you can't use File static methods to write on it.
|
|
|
|
|
|
Well then...this is a great opprtunity to get away from what your comfortable with and learn something new, isn't it?
|
|
|
|
|
|
If you can't do this and teach yourself new ways to do something, you're not going to last very long as a programmer.
|
|
|
|
|
You right,in fact i learned that before two minutes..
|
|
|
|
|
Hello every one,
I want to know the code to Enable/Disable local area network connection.
if it is applicable also , to define IP and subnetmask;
ThanksAll You Need Is A Good Friend
|
|
|
|
|
|
hey
This is for outlook vba for loading a ref at outlook
Whit this you can load a reference in it whitout any manual input the only thing you need
= a refernce to let vbe work
so this is no solution if you only whant to load 1 reference
Application.VBE.ActiveVBProject.References.AddFromFile "C:\WINDOWS\system32\redemption.dll"
is there a other way at vba
or a way true c#.net or vb.net to load a ref en set active in outlook
thanks
|
|
|
|
|
Original is here[^].
Do NOT post the same question over and over again and do not post them in different forums. It makes collaborating on an answer very difficult.
|
|
|
|
|
i want to get the url from the address bar each time when the new address is entered.
i have the code to get the url of current opened IE instances.
But i donot know how to programatically get the url each time without pressing the button.
|
|
|
|