I'm trying to open an application(with it's GUI) thorough the windows service. It's not throwing any exception or error. Its not opening the application. When I executed the same code with windows Forms app the applicaiton is opening. Why the windows service is not opening any other application? My code is like below:
protected override void OnStart(string[] args)
{
try
{
bool isinstalled = checkInstalled("AnyDesk");
if (isinstalled)
{
Process.Start(@"C:\Program Files (x86)\AnyDesk\AnyDesk.exe");
}
}
catch (Exception ex)
{
this.EventLog.WriteEntry(ex.Message, EventLogEntryType.Information);
}
}
public static bool checkInstalled(string c_name)
{
string displayName;
string registryKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey);
if (key != null)
{
foreach (RegistryKey subkey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName)))
{
displayName = subkey.GetValue("DisplayName") as string;
if (displayName != null && displayName.Contains(c_name))
{
return true;
}
}
key.Close();
}
registryKey = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
key = Registry.LocalMachine.OpenSubKey(registryKey);
if (key != null)
{
foreach (RegistryKey subkey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName)))
{
displayName = subkey.GetValue("DisplayName") as string;
if (displayName != null && displayName.Contains(c_name))
{
return true;
}
}
key.Close();
}
return false;
}
Windows Service applications run in a different "window station" than the logged-on user. Your application is opening and displaying on a hidden desktop that nobody can see.
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.