locked
Changing registry value for services RRS feed

  • Question

  • I have written a service, that needs to interact with the users desktop and execute a .exe file. Since there is not settings to set this property, I have written the code to change the registry value of this service. But my issue it when I do this, it does not execute the exe file. If I manually go to the properties and check "Allow service to interact with desktop" then I could see the exe is running. When I do it from the code exe runs in the background. Could any one let me know how to fix this? Any help is greatly appreciated. Following is my code:

    Dim serviceName As String = "PortalReportScanner"
        Dim key As RegistryKey = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\" & serviceName & "\", True)
    
        If key IsNot Nothing Then
          ' get the value of the Type key. 
          Dim obj As Object = key.GetValue("Type")
    
          If obj IsNot Nothing AndAlso TypeOf obj Is Integer Then
            Dim value As Integer = CInt(obj)
            ' set the flag. 
            value = value Or &H100
            ' set the value back. 
            If key.GetValue("Type") <> value Then
              key.SetValue("Type", value)
            End If
          End If
        End If
    

    donsls
    Wednesday, September 22, 2010 2:33 PM

Answers

  • Hi Donsls,

    Actually I'm not quite sure what the problem is... so please correct me if I got it wrong. Are you saying that you have a Windows Service which needs to interact with the users loggin to their desktops?

    If this is the case, then I'd suggest you to read this KB article before deciding continuing the design this way (I mean interactive service):
    Descriptions of some best practices when you create Windows Services

    Basically we don't recommend interactive services at all. This is the point.

    If you want to have a UI for your users to config/control your service, you can consider create a seperate Windows desktop application that runs in user's desktop, and talk to the service via some .NET communication features, for example WCF or Remoting.

    If you have any further questions regarding the implementation, you can always post your questions in the corresponding forums.

    Regards,
    Jie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    If you have any feedback, please tell us.

    The All-In-One Code Framework Project
    My Blog (in Simplified Chinese)
    • Marked as answer by Jing0 Tuesday, October 5, 2010 4:11 AM
    Tuesday, September 28, 2010 9:45 AM
  • Thanks for the reply. Actually my service does not need user's interaction. It has a timer that reads a specific table in my SQL server database. When certain conditions are met, it must execute another exe. And this exe has a user interface, where users could do certain functions. If I don't have the option "Allow service to interact with desktop" checked, when the service runs the executable, it does not show the interface. I could see the executable running in the task manage, but the user interface is hidden. This is what I am trying to achieve with the service. Is there any other way to run the exe from the service without checking "Allow service to interact with desktop"?
    donsls


    1. Allow service to interact with desktop is NOT recommended in general.

    2. I don't recommend start the EXE from your service and make it run in your user's desktop. It will be quite complicate to make it work. And what if there are more than one users logged onto the system interactively at the same time? How do you decide on which user's desktop the EXE shall show up?

    3. Comparing to the previous solution, I strongly recommend the way I mentioned in my previous post. Configure your UI EXE to run in the background when a user logs in, and start listening to the service's events. Once the service signals, the EXE shows the UI and let the user interact with it.

    Regards,
    Jie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    If you have any feedback, please tell us.

    The All-In-One Code Framework Project
    My Blog (in Simplified Chinese)
    • Marked as answer by Jing0 Tuesday, October 5, 2010 4:11 AM
    Friday, October 1, 2010 8:45 AM
  • In addition to Wang Jie,

    Direct Interaction in managed languages between a service and the desktop (and your code is VB from a language version newer than VB7) is made impossible.

     


    Success
    Cor
    • Marked as answer by Jing0 Tuesday, October 5, 2010 4:11 AM
    Friday, October 1, 2010 9:53 AM

All replies

  • Hi Donsls,

    Actually I'm not quite sure what the problem is... so please correct me if I got it wrong. Are you saying that you have a Windows Service which needs to interact with the users loggin to their desktops?

    If this is the case, then I'd suggest you to read this KB article before deciding continuing the design this way (I mean interactive service):
    Descriptions of some best practices when you create Windows Services

    Basically we don't recommend interactive services at all. This is the point.

    If you want to have a UI for your users to config/control your service, you can consider create a seperate Windows desktop application that runs in user's desktop, and talk to the service via some .NET communication features, for example WCF or Remoting.

    If you have any further questions regarding the implementation, you can always post your questions in the corresponding forums.

    Regards,
    Jie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    If you have any feedback, please tell us.

    The All-In-One Code Framework Project
    My Blog (in Simplified Chinese)
    • Marked as answer by Jing0 Tuesday, October 5, 2010 4:11 AM
    Tuesday, September 28, 2010 9:45 AM
  • Thanks for the reply. Actually my service does not need user's interaction. It has a timer that reads a specific table in my SQL server database. When certain conditions are met, it must execute another exe. And this exe has a user interface, where users could do certain functions. If I don't have the option "Allow service to interact with desktop" checked, when the service runs the executable, it does not show the interface. I could see the executable running in the task manage, but the user interface is hidden. This is what I am trying to achieve with the service. Is there any other way to run the exe from the service without checking "Allow service to interact with desktop"?
    donsls
    Wednesday, September 29, 2010 2:33 PM
  • Thanks for the reply. Actually my service does not need user's interaction. It has a timer that reads a specific table in my SQL server database. When certain conditions are met, it must execute another exe. And this exe has a user interface, where users could do certain functions. If I don't have the option "Allow service to interact with desktop" checked, when the service runs the executable, it does not show the interface. I could see the executable running in the task manage, but the user interface is hidden. This is what I am trying to achieve with the service. Is there any other way to run the exe from the service without checking "Allow service to interact with desktop"?
    donsls


    1. Allow service to interact with desktop is NOT recommended in general.

    2. I don't recommend start the EXE from your service and make it run in your user's desktop. It will be quite complicate to make it work. And what if there are more than one users logged onto the system interactively at the same time? How do you decide on which user's desktop the EXE shall show up?

    3. Comparing to the previous solution, I strongly recommend the way I mentioned in my previous post. Configure your UI EXE to run in the background when a user logs in, and start listening to the service's events. Once the service signals, the EXE shows the UI and let the user interact with it.

    Regards,
    Jie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    If you have any feedback, please tell us.

    The All-In-One Code Framework Project
    My Blog (in Simplified Chinese)
    • Marked as answer by Jing0 Tuesday, October 5, 2010 4:11 AM
    Friday, October 1, 2010 8:45 AM
  • In addition to Wang Jie,

    Direct Interaction in managed languages between a service and the desktop (and your code is VB from a language version newer than VB7) is made impossible.

     


    Success
    Cor
    • Marked as answer by Jing0 Tuesday, October 5, 2010 4:11 AM
    Friday, October 1, 2010 9:53 AM