We help IT Professionals succeed at work.
Get Started

Automate the check box "Allow service to interact with desktop"

rakhy_rakey
rakhy_rakey asked
on
1,894 Views
Last Modified: 2013-12-17
Hi...

I have been working on the following issue since a week. If anybody help me to come out of this issue this is really really really a great and big help.

I developed a windows service. When I install it, it should check the check box "Allow service to interact with desktop" in the Logon tab of the properties of the windows servic and then it should start the service automatically.  It is doing it fine with my code. But it is not giving me the required output.

It is giving me required output, when I did it manually(Check the check box) and start the service.

Thank you very much,
Rakhy.


//for installation mode and service startup type
            this.Installers.Clear();
            _service = new ServiceInstaller();
            _service.ServiceName = strServiceName;
            _service.StartType = ServiceStartMode.Automatic;
            _service.Description = "Communicates between Client and Server with acknowledgement on both sides";
            this.Installers.Add(_service);

            _serviceProcess = new ServiceProcessInstaller();
            _serviceProcess.Account = ServiceAccount.LocalSystem;
            this.Installers.Add(_serviceProcess);

//part2: code to automate the check box "Allow service to interact with desktop"

RegistryKey ckey = Registry.LocalMachine.OpenSubKey(
              @"SYSTEM\CurrentControlSet\Services\VerizonClientServerWindowsService", true);

            if (ckey != null)
            {
                // Make sure the "Type" value is there, 

                //and then do bitwise operation on it.

               if (ckey.GetValue("Type") != null)
                {
                    ckey.SetValue("Type", ((int)ckey.GetValue("Type") | 256));
                }
              }


//part3: code to start the service

var controller = new ServiceController(strServiceName);
            controller.Start();
           



Case1: If I don't have part2 and part3, then I need to manually check the check box of "alllow to interact with desktop" and then start the service. In this case I am able to get my required output (able to display Form on desktop.) 

Case2: If I include part2 and part3, it is installing, checking the check box and running the service fine. 
But I am unable to get my required output(form on desktop) in this case.

Open in new window

Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 11 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE