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='" + "Service1" + "'");
ManagementBaseObject InParam = wmiService.GetMethodParameters("Change");
InParam["DesktopInteract"] = true;
wmiService.InvokeMethod("Change", InParam, null);
}
catch (Exception ex)
{
//TODO: Log this error
StreamWriter sw;
sw = File.AppendText("C:\\Sashidhar.txt");
sw.WriteLine("Trying to open Service");
sw.Close();
}
}
{
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='" + "Service1" + "'");
ManagementBaseObject InParam = wmiService.GetMethodParameters("Change");
InParam["DesktopInteract"] = true;
wmiService.InvokeMethod("Change", InParam, null);
}
catch (Exception ex)
{
//TODO: Log this error
StreamWriter sw;
sw = File.AppendText("C:\\Sashidhar.txt");
sw.WriteLine("Trying to open Service");
sw.Close();
}
}