This won't work. Problem is that you are trying to show UI (Console) from a Windows Service and Windows Service is not running in the context of any particular user. Starting from Vista and later OS Windows Services are running in an isolated session and are disallowed to interact with a user or desktop making it impossible to run.
Depending on what you need there are two solutions to this problem.
- If you want the
cmd
to be opened you might consider using a task scheduled action from Windows Task Scheduler and then perform your actions
- If you need just to execute some actions with the
cmd.exe
, for example copy file, that does not require the UI to be displayed then you can achieve that with the following
Start cmd
without creating a window:
ProcessStartInfo processInfo = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Normal,
CreateNoWindow = true,
UseShellExecute = false,
FileName = "cmd.exe",
Arguments = @"/C copy /b Image1.jpg + Archive.rar Image2.jpg"
};
For the further details please check following links: