|
/*
* Please leave this Copyright notice in your code if you use it
* Written by Decebal Mihailescu [http://www.codeproject.com/script/articles/list_articles.asp?userid=634640]
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using Microsoft.Win32;
using System.ServiceProcess;
using System.Management;
namespace ScreenmonitorService
{
[RunInstaller(true)]
public partial class ProjectInstaller : Installer
{
public ProjectInstaller()
{
InitializeComponent();
}
private void ServiceMonitorInstaller_AfterInstall(object sender, InstallEventArgs e)
{
ManagementObject wmiService = null;
ManagementBaseObject InParam = null;
try
{
//ConnectionOptions coOptions = new ConnectionOptions();
//coOptions.Impersonation = ImpersonationLevel.Impersonate;
//ManagementScope mgmtScope = new System.Management.ManagementScope(@"root\CIMV2", coOptions);
//mgmtScope.Connect();
wmiService = new ManagementObject(string.Format("Win32_Service.Name='{0}'", ServiceMonitorInstaller.ServiceName));
InParam = wmiService.GetMethodParameters("Change");
InParam["DesktopInteract"] = true;
wmiService.InvokeMethod("Change", InParam, null);
}
finally
{
if (InParam != null)
InParam.Dispose();
if (wmiService != null)
wmiService.Dispose();
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Decebal Mihailescu is a software engineer with interest in .Net, C# and C++.