"Allow Service to interact with Desktop" Windows Services
-
"Allow Service to interact with Desktop" in Services property. How can i set this property programmatically. Thanks ........
-
"Allow Service to interact with Desktop" in Services property. How can i set this property programmatically. Thanks ........
Setting this property at all is not generally advisable. Services aren't meant to provide UI or allow any other type of user interaction.
Scott Dorman
Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]
Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
-
"Allow Service to interact with Desktop" in Services property. How can i set this property programmatically. Thanks ........
You should ask yourself if you should be doing this. The reason I used this code was I had a windows service that logged into a DB2 database via an ODBC driver. They routinely changed their passwords and sometimes would forget to tell us. When we tried to login in after a password had been changed the ODBC driver would pop up (attempt to pop up) a dialog allowing you to enter the new password which of course never showed up as it didn't have permissions. We didn't realize any problem until the client called telling us that they hadn't received any new data. Anyways the following code worked for me. Reference System.Management
/// Start the service
protected override void OnStart(string[] args)
{
ServiceDesktopPermission();
}/// Using Management Object services the option "Allow service to interact with desktop"
/// can be enabled. This gets unchecked/disabled each time a new install or update of the
/// service is performed.
static public void ServiceDesktopPermission()
{
try
{
ConnectionOptions coOptions = new ConnectionOptions();coOptions.Impersonation = ImpersonationLevel.Impersonate; // CIMV2 is a namespace that contains all of the core OS and hardware classes. // CIM (Common Information Model) which is an industry standard for describing // data about applications and devices so that administrators and software // management programs can control applications and devices on different // platforms in the same way, ensuring interoperability across a network. ManagementScope mgmtScope = new ManagementScope(@"root\\CIMV2", coOptions); mgmtScope.Connect(); ManagementObject wmiService; wmiService = new ManagementObject("Win32\_Service.Name='" + "My Service Name" + "'"); ManagementBaseObject InParam = wmiService.GetMethodParameters("Change"); InParam\["DesktopInteract"\] = true; wmiService.InvokeMethod("Change", InParam, null); }
catch(Exception ex)
{
//TODO: Log this error
}
} -
You should ask yourself if you should be doing this. The reason I used this code was I had a windows service that logged into a DB2 database via an ODBC driver. They routinely changed their passwords and sometimes would forget to tell us. When we tried to login in after a password had been changed the ODBC driver would pop up (attempt to pop up) a dialog allowing you to enter the new password which of course never showed up as it didn't have permissions. We didn't realize any problem until the client called telling us that they hadn't received any new data. Anyways the following code worked for me. Reference System.Management
/// Start the service
protected override void OnStart(string[] args)
{
ServiceDesktopPermission();
}/// Using Management Object services the option "Allow service to interact with desktop"
/// can be enabled. This gets unchecked/disabled each time a new install or update of the
/// service is performed.
static public void ServiceDesktopPermission()
{
try
{
ConnectionOptions coOptions = new ConnectionOptions();coOptions.Impersonation = ImpersonationLevel.Impersonate; // CIMV2 is a namespace that contains all of the core OS and hardware classes. // CIM (Common Information Model) which is an industry standard for describing // data about applications and devices so that administrators and software // management programs can control applications and devices on different // platforms in the same way, ensuring interoperability across a network. ManagementScope mgmtScope = new ManagementScope(@"root\\CIMV2", coOptions); mgmtScope.Connect(); ManagementObject wmiService; wmiService = new ManagementObject("Win32\_Service.Name='" + "My Service Name" + "'"); ManagementBaseObject InParam = wmiService.GetMethodParameters("Change"); InParam\["DesktopInteract"\] = true; wmiService.InvokeMethod("Change", InParam, null); }
catch(Exception ex)
{
//TODO: Log this error
}
} -
"Allow Service to interact with Desktop" in Services property. How can i set this property programmatically. Thanks ........
Try this C# code href="http://it.expertmonster.com/question/Allow-service-to-interact-with-desktop-112.html
-
You should ask yourself if you should be doing this. The reason I used this code was I had a windows service that logged into a DB2 database via an ODBC driver. They routinely changed their passwords and sometimes would forget to tell us. When we tried to login in after a password had been changed the ODBC driver would pop up (attempt to pop up) a dialog allowing you to enter the new password which of course never showed up as it didn't have permissions. We didn't realize any problem until the client called telling us that they hadn't received any new data. Anyways the following code worked for me. Reference System.Management
/// Start the service
protected override void OnStart(string[] args)
{
ServiceDesktopPermission();
}/// Using Management Object services the option "Allow service to interact with desktop"
/// can be enabled. This gets unchecked/disabled each time a new install or update of the
/// service is performed.
static public void ServiceDesktopPermission()
{
try
{
ConnectionOptions coOptions = new ConnectionOptions();coOptions.Impersonation = ImpersonationLevel.Impersonate; // CIMV2 is a namespace that contains all of the core OS and hardware classes. // CIM (Common Information Model) which is an industry standard for describing // data about applications and devices so that administrators and software // management programs can control applications and devices on different // platforms in the same way, ensuring interoperability across a network. ManagementScope mgmtScope = new ManagementScope(@"root\\CIMV2", coOptions); mgmtScope.Connect(); ManagementObject wmiService; wmiService = new ManagementObject("Win32\_Service.Name='" + "My Service Name" + "'"); ManagementBaseObject InParam = wmiService.GetMethodParameters("Change"); InParam\["DesktopInteract"\] = true; wmiService.InvokeMethod("Change", InParam, null); }
catch(Exception ex)
{
//TODO: Log this error
}
}Excellent, thank you. Just what I was looking for. I only have one suggestion: do it in the service installer after service installation is completed, before the service starts up. This way the first time the service starts, it's already able to interract with the desktop: private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e) { ServiceDesktopPermission(); var controller = new ServiceController("SERVICE_NAME"); controller.Start(); }