简体   繁体   中英

Why doesn't my application show when started by my service

[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

const int SW_SHOW =5;

string Tartgetfile = @"C:\BringLog.exe";
p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
p.StartInfo.CreateNoWindow = false;
p.StartInfo.FileName = Tartgetfile;
try
 {
  if (p.Start() == true)
   {
     ShowWindow(p.Handle, SW_SHOW);
     WriteToLog("PROCESS STARTED");
   }
  else
   {
    WriteToLog("FAILED TO START PROCESS");
   }
 }
catch (Exception ex)
 {
  WriteToLog("FAILED TO START PROCESS" + ex.Message+ ex.Source);
 }                     

i have used this code in my service onsessionchange event, the service start my application on logon event but application is hidden but running. i couldn't view

By default, services do not have access to any session - not the logon session, not the secure UAC in Vista, not even the common user sessions. Hence, there's nowhere for them to show their windows. This is good. There are hacks around it, but the proper way is probably to create the process in Windows Station "Winsta0". Set STARTUPINFO.lpDesktop ="winsta0\\default"; when calling CreateProcess( )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM