Interactive service problems

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ati88
    New Member
    • Jul 2008
    • 1

    Interactive service problems

    Hello!

    I made a Windows Service which logs user activities. There is an option called "Allow service to interact with desktop", and I would like to check this box programatically . I found this page: http://bytes.com/forum/thread258609.ht ml
    On that there is a solution, but I got an error on this line:
    GetMethodParame ters("Change");
    The error is: "Not found".
    I dont know what should I do to make it work.

    Thanks for help!
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    did you try the follow up code?
    Add following class to the cs file that contains the Installer class (class
    derived from System.Configur ation.Install.I nstaller).
    Change the class ServiceInstalle r into ServiceInstalle rEx and create an
    instance of ServiceInstalle rEx instead of ServiceInstalle r .
    Finally add - using System.Manageme nt;
    Code:
    class ServiceInstallerEx : System.ServiceProcess.ServiceInstaller
    {
    public ServiceInstallerEx() : base()
    {
    // Set eventhandler to call UpdateServiceConfig when install commited
    base.Committed += new InstallEventHandler( this.UpdateServiceConfig );
    }
    // Eventhandler, called after service installer committed.
    // This method uses System.Management classes to change service config.
    // Note that enabling "DesktopInteract" will fail if Service account is not
    LocalSystem !!
    void UpdateServiceConfig(object sender, InstallEventArgs e)
    {
    int ret;
    ManagementBaseObject inParams = null;
    ManagementObject srvc = new ManagementObject("Win32_Service=" + "\"" +
    this.ServiceName + "\"");
    inParams = srvc.GetMethodParameters("Change");
    inParams["DesktopInteract"] = true; // Enable interactive mode (Interact
    With Desktop)
    ManagementBaseObject outParams = srvc.InvokeMethod("Change", inParams,
    null);
    if((ret = Convert.ToInt32(outParams.Properties["ReturnValue"].Value)) !=
    0)
    Console.WriteLine("Failed to set option: {0}", ret);
    else
    Console.WriteLine("Option set");
    }
    }

    Comment

    Working...