473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Interactive service problems

1
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.html
On that there is a solution, but I got an error on this line:
GetMethodParameters("Change");
The error is: "Not found".
I dont know what should I do to make it work.

Thanks for help!
Jul 24 '08 #1
1 1347
Plater
7,872 Expert 4TB
did you try the follow up code?
Add following class to the cs file that contains the Installer class (class
derived from System.Configuration.Install.Installer).
Change the class ServiceInstaller into ServiceInstallerEx and create an
instance of ServiceInstallerEx instead of ServiceInstaller .
Finally add - using System.Management;
Expand|Select|Wrap|Line Numbers
  1. class ServiceInstallerEx : System.ServiceProcess.ServiceInstaller
  2. {
  3. public ServiceInstallerEx() : base()
  4. {
  5. // Set eventhandler to call UpdateServiceConfig when install commited
  6. base.Committed += new InstallEventHandler( this.UpdateServiceConfig );
  7. }
  8. // Eventhandler, called after service installer committed.
  9. // This method uses System.Management classes to change service config.
  10. // Note that enabling "DesktopInteract" will fail if Service account is not
  11. LocalSystem !!
  12. void UpdateServiceConfig(object sender, InstallEventArgs e)
  13. {
  14. int ret;
  15. ManagementBaseObject inParams = null;
  16. ManagementObject srvc = new ManagementObject("Win32_Service=" + "\"" +
  17. this.ServiceName + "\"");
  18. inParams = srvc.GetMethodParameters("Change");
  19. inParams["DesktopInteract"] = true; // Enable interactive mode (Interact
  20. With Desktop)
  21. ManagementBaseObject outParams = srvc.InvokeMethod("Change", inParams,
  22. null);
  23. if((ret = Convert.ToInt32(outParams.Properties["ReturnValue"].Value)) !=
  24. 0)
  25. Console.WriteLine("Failed to set option: {0}", ret);
  26. else
  27. Console.WriteLine("Option set");
  28. }
  29. }
  30.  
Jul 24 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: flat_ross | last post by:
I have a service running under SYSTEM in XP that needs to notify the interactive user. From all of my newsgroup reading it looks like it is no longer acceptable to set the service as "Interact...
6
by: Microsoft | last post by:
I'm new to CSharp, previously having done all my development in Delphi. I need to create a service, and for the development cycle I wish it to be an interactive service and use message boxes to...
1
by: amwi | last post by:
I have tried to find a solution on this problem "everywhere" without any luck. I am writing a service to track the time that the current logged on interactive user is using the computer. Perhaps...
0
by: Vaibhav Podutwar. | last post by:
Hi, I am developing windows service in C#, I have to develop interactive service but this service can be used by the user who has not have the administrative writes. I am facing the problem...
3
by: Lubomir | last post by:
Hi, I read that interactive windows services will not be allowed to run under Wista. I would like to ask what exactly is the interactive service. It is supposed to be a service that communicates...
1
by: Andreas | last post by:
Hi, I'm developing a non-interactive C++ windows service (as support for interactive services will run out...) that shall communicate with a .net application on the local host. What's the best...
2
by: ranadhirnag | last post by:
To create a 'interactive' service on windows - we use a localsystem account ,with 'Interact with desktop' option. Is there any other account which allows a service to be interactive - e.g. can a...
0
by: Accessed | last post by:
"(MSSQLSERVER) service is marked as an interactive service. However, the system is configured to not allow interactive services" This problems may solve a recurring failure in my automatic...
0
balabaster
by: balabaster | last post by:
Hi, I know this question has been answered before (somewhat) but I have a twist... I've written a client/server application where the server portion runs as a windows service and allows...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.