How to open notepad from windows service
-
Hi , This is ravindra,currently working on Windows Service. I implemented the following two methods to call notepad.exe from windows service,but its not working.So,please anybody help to complete my task. Method1: ======= STARTUPINFO si = new STARTUPINFO(); PROCESS_INFORMATION pi = new PROCESS_INFORMATION(); CreateProcess("C:\\WINDOWS\\SYSTEM32\\notepad.exe", null, IntPtr.Zero, IntPtr.Zero, false, 0, IntPtr.Zero, null, ref si, out pi); EventLog.WriteEntry("After notepad"); } [DllImport("kernel32.dll")] static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation); } } Method2: ======== EventLog.WriteEntry("In the notepad"); ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "notepad.exe"; psi.UseShellExecute = false; psi.Domain = "sys43."; psi.UserName = "Acer OEM User"; SecureString secure = new SecureString(); string password = "nopassword"; foreach (char c in password) { secure.AppendChar(c); } psi.Password = secure; Process process = new Process(); process.StartInfo = psi; process.Start();
-
Hi , This is ravindra,currently working on Windows Service. I implemented the following two methods to call notepad.exe from windows service,but its not working.So,please anybody help to complete my task. Method1: ======= STARTUPINFO si = new STARTUPINFO(); PROCESS_INFORMATION pi = new PROCESS_INFORMATION(); CreateProcess("C:\\WINDOWS\\SYSTEM32\\notepad.exe", null, IntPtr.Zero, IntPtr.Zero, false, 0, IntPtr.Zero, null, ref si, out pi); EventLog.WriteEntry("After notepad"); } [DllImport("kernel32.dll")] static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation); } } Method2: ======== EventLog.WriteEntry("In the notepad"); ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "notepad.exe"; psi.UseShellExecute = false; psi.Domain = "sys43."; psi.UserName = "Acer OEM User"; SecureString secure = new SecureString(); string password = "nopassword"; foreach (char c in password) { secure.AppendChar(c); } psi.Password = secure; Process process = new Process(); process.StartInfo = psi; process.Start();
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Process p = new Process();
p.StartInfo.FileName = "notepad.exe";
//p.StartInfo.Arguments = "yourFileName.txt";
p.Start();
}
}
}SkyWalker
-
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Process p = new Process();
p.StartInfo.FileName = "notepad.exe";
//p.StartInfo.Arguments = "yourFileName.txt";
p.Start();
}
}
}SkyWalker
This is how you would open Notepad from a win forms application however this won't work from a windows service. A service does not have a "display" to show the notepad application. I have had a look around and had a play but I cant get this to work. Sorry. :( Hopefully someone else might have some better ideas. Also be sure to consider the account the service is running under, some accounts will restrict such activities.
-
This is how you would open Notepad from a win forms application however this won't work from a windows service. A service does not have a "display" to show the notepad application. I have had a look around and had a play but I cant get this to work. Sorry. :( Hopefully someone else might have some better ideas. Also be sure to consider the account the service is running under, some accounts will restrict such activities.
it was no win form outhere :sigh: It was a console example. ... and starting a process has nothing to do with any display ...
SkyWalker
-
it was no win form outhere :sigh: It was a console example. ... and starting a process has nothing to do with any display ...
SkyWalker
Mircea Puiu wrote:
. and starting a process has nothing to do with any display ...
It does if its from a windows service which is not marked as "Interactive". Without a display to start a windowed process like notepad, it will not show up if started from the service.
-
Hi , This is ravindra,currently working on Windows Service. I implemented the following two methods to call notepad.exe from windows service,but its not working.So,please anybody help to complete my task. Method1: ======= STARTUPINFO si = new STARTUPINFO(); PROCESS_INFORMATION pi = new PROCESS_INFORMATION(); CreateProcess("C:\\WINDOWS\\SYSTEM32\\notepad.exe", null, IntPtr.Zero, IntPtr.Zero, false, 0, IntPtr.Zero, null, ref si, out pi); EventLog.WriteEntry("After notepad"); } [DllImport("kernel32.dll")] static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation); } } Method2: ======== EventLog.WriteEntry("In the notepad"); ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "notepad.exe"; psi.UseShellExecute = false; psi.Domain = "sys43."; psi.UserName = "Acer OEM User"; SecureString secure = new SecureString(); string password = "nopassword"; foreach (char c in password) { secure.AppendChar(c); } psi.Password = secure; Process process = new Process(); process.StartInfo = psi; process.Start();
Windows services generally are not required to show other applications. You can check the box to mark the service as "Interactive" which will allow it limited use of the logged-in users screen. Without testing, I would think that marking it interactive and using the standard Process.Start code that is ubiquitous would result in the behaviour you are expecting.
-
Mircea Puiu wrote:
. and starting a process has nothing to do with any display ...
It does if its from a windows service which is not marked as "Interactive". Without a display to start a windowed process like notepad, it will not show up if started from the service.
of course :-)
SkyWalker
-
Hi , This is ravindra,currently working on Windows Service. I implemented the following two methods to call notepad.exe from windows service,but its not working.So,please anybody help to complete my task. Method1: ======= STARTUPINFO si = new STARTUPINFO(); PROCESS_INFORMATION pi = new PROCESS_INFORMATION(); CreateProcess("C:\\WINDOWS\\SYSTEM32\\notepad.exe", null, IntPtr.Zero, IntPtr.Zero, false, 0, IntPtr.Zero, null, ref si, out pi); EventLog.WriteEntry("After notepad"); } [DllImport("kernel32.dll")] static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation); } } Method2: ======== EventLog.WriteEntry("In the notepad"); ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "notepad.exe"; psi.UseShellExecute = false; psi.Domain = "sys43."; psi.UserName = "Acer OEM User"; SecureString secure = new SecureString(); string password = "nopassword"; foreach (char c in password) { secure.AppendChar(c); } psi.Password = secure; Process process = new Process(); process.StartInfo = psi; process.Start();
You do not normally start an interactive process from a Windows Service. Probably, it is an option in your case when debugging something (then you must enable the service to interact with the desktop, as already said by someone here). The reason is that each service runs in an invisible secured desktop environment, therefore no user interface is shown to users.
SkyWalker
-
Windows services generally are not required to show other applications. You can check the box to mark the service as "Interactive" which will allow it limited use of the logged-in users screen. Without testing, I would think that marking it interactive and using the standard Process.Start code that is ubiquitous would result in the behaviour you are expecting.
It does - this was the step I was missing when I attempted it.