0

I am using System.Diagnostics.Process in a Windows service application. The application that I call uses DropBox API and Google Drive API. When I login on Google Drive or DropBox it is supposed to open the Web browser and allow access to Drop or Drive, but it doesn't open it. Other functions works properly (create folder on local computer, read files, write logfiles etc).

When I open this application manually with double click, the login process works properly, the web browser is shown and I can allow access.

Something similar happens with other application using Saraff Twain. If I open it manually it works properly, I can scan and save files (on this process some alerts or message box are shown, like a "scanning", "no paper", "no scanner" messages) but when the windows service call it no messages are shown, it scans and save files but without messages.

If I call this application from another windows form or console application the applications works properly.

I don't know what is the problem with the Windows service.

Thanks for your help.

Here is the code that I used in the Windows service app (here it fails), and Windows forms app (here it works fine). I have tried calling CMD.exe and application path as argument, and directly the path on file name.

p.StartInfo.UseShellExecute = false;
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/C" + " \"" + execName+"\" " + argument;
//p.StartInfo.Verb = "runas";
// writeLogLine(argument + " " + execName);
p.Start();
output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
writeLogLine("out" + output);
yacc
  • 2,915
  • 4
  • 19
  • 33
  • 1
    https://blog.lextudio.com/web-application-differences-in-visual-studio-and-iis-60fec7e311b3 IIS is a typical Windows service, so most I wrote about IIS applies to your situation. You won't see any browsers/prompts as they are popped up in system session, and isolated from your desktop. – Lex Li Jan 16 '20 at 19:07
  • 1
    You aren't allowed to do this since Windows XP. To solve this, don't run your app as a service. Run it in the user space. [Here](https://stackoverflow.com/questions/4237225/allow-service-to-interact-with-desktop-in-windows) is a nice thread discussing possible workarounds. My suggestion is to run your stuff as a background app. – Señor CMasMas Jan 16 '20 at 21:26

1 Answers1

0

A Windows Service is not meant for user interaction as it should be capable of running without any users logged in.

Windows Services are isolated from the users' desktops as a security measure this is why any interaction with a desktop is bound to fail.

Either replace the Windows Service with a regular desktop application or change the Windows Service in such a way that it doesn't need desktop access.

Emond
  • 50,210
  • 11
  • 84
  • 115