Chamar programas apartir de um serviço
22/08/2012
0
protected override void OnStart(string[] args)
{
System.Diagnostics.Process.Start("calc");
}
Se for somente isso, não está funcionando. O que mais preciso informar?
Pjava
Posts
22/08/2012
Fabio Rosa
Acredito que como você está em um serviço, deverá informar o path completo da aplicação, pois as variáveis de sistema não são vistas pelo serviço... Então você não pode informar apenas "Calc" e sim "%windir%\system32\calc.exe"
Tente isto... acho que pode resolver.
Att.
23/08/2012
Pjava
{
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
Timer timer;
timer = new Timer(new TimerCallback(timer_Tick), null, 15000, 60000);
}
protected override void OnStop()
{
}
private void timer_Tick(object sender)
{
//System.Diagnostics.Process.Start("%windir%\\system32\\calc.exe");
System.Diagnostics.Process.Start("C:\\Windows\\system32\\calc.exe");
}
}
Já coloquei essa linha direto no OnStart e também não funciona
System.Diagnostics.Process.Start("C:\\Windows\\system32\\calc.exe");
23/08/2012
Edson Oliveira
Process oProcess = null; ProcessStartInfo oProcessStartInfo = new ProcessStartInfo("C:\\WINDOWS\\SYSTEM32\\CALC.EXE"); string pwd = "mypassword";// System.Security.SecureString securePwd = new System.Security.SecureString(); foreach (char c in pwd) securePwd.AppendChar(c); oProcessStartInfo.UseShellExecute = false; oProcessStartInfo.Password = securePwd; oProcessStartInfo.UserName = "myserviceaccount"; oProcessStartInfo.Domain = "MyCompanyDomain"; oProcess = Process.Start(oProcessStartInfo); oProcess.WaitForExit(); oProcess.Close();
23/08/2012
Pjava
//foreach (char c in pwd)
// securePwd.AppendChar(c);
//oProcessStartInfo.UseShellExecute = false;
//oProcessStartInfo.Password = securePwd;
//oProcessStartInfo.UserName = "psilva";
//oProcessStartInfo.Domain = "CasaNova";
E se comento, a calculadora não sobe
23/08/2012
Pjava
System.Timers.Timer MyTimer;
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
//Tempo para 20 segundos
MyTimer = new System.Timers.Timer(20000);
MyTimer.Elapsed += new ElapsedEventHandler(MyTimer_Elapsed);
MyTimer.Start();
}
void MyTimer_Elapsed(object sender, ElapsedEventArgs e)
{
try
{
MyTimer.Stop();
System.Diagnostics.Process.Start("C:\\Windows\\system32\\calc.exe");
}
catch (Exception)
{
//ALGUM LOG, MAS NÃO DEIXE LEVANTAR A EXCEÇÃO
}
finally
{
MyTimer.Start();
}
}
protected override void OnStop()
{
}
private void timer_Tick(object sender)
{
//System.Diagnostics.Process.Start("%windir%\\system32\\calc.exe");
System.Diagnostics.Process.Start("C:\\Windows\\system32\\calc.exe");
}
}
23/08/2012
Pjava
24/08/2012
Pjava
24/08/2012
Edson Oliveira
Serviço
Process oProcess = new Process(); oProcess.EnableRaisingEvents = false; oProcess.StartInfo.FileName = @"ConsoleApplication1.exe"; oProcess.StartInfo.Arguments = "--calc"; oProcess.Start();
Console
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { if (args.Length > 0) { if (args[0] == "--calc") { Process.Start("calc.exe"); } } } } }
É so colocar o .exe do console junto com o .exe do serviço.
Clique aqui para fazer login e interagir na Comunidade :)