none
Controlling JAWS service RRS feed

  • Question

  • How could I controll a secure service?

    I would like the above mentioned screen reader (running as a service) to controll programatically. It must be stopped and restarted programatically by users of my program. When I try to retreive its version information or try to controll it otherwise, I get the "Access denied" error message. I get this message also at time when I'm loging on as administrator and let run the program. How could I control the  programs permissions? I think I should use ServiceControllerPermission class, but I have not found any examples about how to use it and I have no idea how to begin... (I use VB.NET 2005 - .NET Framework 2.0)

    Because my program will be used by blind persons, it should do anything automatically, I have no possibility to ask my users to do it manually.
    Could tell me any body some examples? Also I'm blind so a working example would be the greatest help form me to understand the whole security stuff. Thanks in advance.

    Tuesday, December 18, 2012 2:00 PM

Answers

  • Hi Shepherd,

    Welcome to the MSDN Forum.

    To get the version information, please take a look at this similar thread: 

    http://stackoverflow.com/questions/4555350/get-the-version-information-of-an-installed-service 

    Private Shared Function GetExecutablePathForService(serviceName As String, registryView As RegistryView, throwErrorIfNonExisting As Boolean) As String
    	Dim registryPath As String = "SYSTEM\CurrentControlSet\Services\" & serviceName
    	Dim key As RegistryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView).OpenSubKey(registryPath)
    	If key Is Nothing Then
    		If throwErrorIfNonExisting Then
    			Throw New ArgumentException("Non-existent service: " & serviceName, "serviceName")
    		Else
    			Return Nothing
    		End If
    	End If
    	Dim value As String = key.GetValue("ImagePath").ToString()
    	key.Close()
    	If value.StartsWith("""") Then
    		value = Regex.Match(value, """([^""]+)""").Groups(1).Value
    	End If
    
    	Return Environment.ExpandEnvironmentVariables(value)
    End Function

    And you can start or stop or restart the service by this class: http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicecontroller.aspx 

    The start / stop method can be your reference.

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, December 19, 2012 8:07 AM
    Moderator

All replies

  • A service is started by the windows operating system and is set to either automatic startup when the computer is turned on or manually.  In your case it should start automatically.  The permissions of running the service should not be set in your code, but the credentials need to be set before the service is started in the permissions for the executable file that the service is running.

    jdweng

    Tuesday, December 18, 2012 5:30 PM
  • How are you trying to control the service?  Exactly what API is returning an Access Denied error message/code?

    -cd Mark the best replies as answers!

    Tuesday, December 18, 2012 7:23 PM
    Moderator
  • Hi Shepherd,

    Welcome to the MSDN Forum.

    To get the version information, please take a look at this similar thread: 

    http://stackoverflow.com/questions/4555350/get-the-version-information-of-an-installed-service 

    Private Shared Function GetExecutablePathForService(serviceName As String, registryView As RegistryView, throwErrorIfNonExisting As Boolean) As String
    	Dim registryPath As String = "SYSTEM\CurrentControlSet\Services\" & serviceName
    	Dim key As RegistryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView).OpenSubKey(registryPath)
    	If key Is Nothing Then
    		If throwErrorIfNonExisting Then
    			Throw New ArgumentException("Non-existent service: " & serviceName, "serviceName")
    		Else
    			Return Nothing
    		End If
    	End If
    	Dim value As String = key.GetValue("ImagePath").ToString()
    	key.Close()
    	If value.StartsWith("""") Then
    		value = Regex.Match(value, """([^""]+)""").Groups(1).Value
    	End If
    
    	Return Environment.ExpandEnvironmentVariables(value)
    End Function

    And you can start or stop or restart the service by this class: http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicecontroller.aspx 

    The start / stop method can be your reference.

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, December 19, 2012 8:07 AM
    Moderator
  • Hi Mike,

    Thank you for your answer! The only problem with your code is, that it is not compatible with .NET 2.0. The RegistryView class available only since .NET 4.0.

    Because the 2005 version of VS IDE is the only one, which is fully compatible with the version of JAWS (v11.0) I use by development, so I have to solve thisproblem within this version of .NET. :( 
    (I would be really happy, if I could use a newer version of VS, but it seems Microsoft does not take accesssiblity into  account by developing newer versions. The developers of VS, I think, does not test their product against the most popular screen readers, so our community are closed out from the modern technologies...)

    But your code is a good point of beginning to understand the things and I hope I could downgrade it to .NET 2.0 level. :)

    Best regards,

    Shepherd

    Wednesday, December 19, 2012 10:15 AM
  • Hi Carl,

    This is what I do exactly when I receive the "Access denied" message:

    1. I have a control on my form (type: System.ServiceProcess.ServiceController nabed JAWSService).
    2. I have the following code in a Sub called on Form_Load event:

    Private Sub StopJAWS()

            Try
                JAWSService.MachineName = System.Environment.MachineName
                JAWSService.ServiceName = "jfw"

     ' Controll if JAWS is really found in the meomory (for text purposes only)
                MsgBox("JAWS Service: " & JAWSService.ServiceName)

     ' Try to stop it
                JAWSService.Stop()

            Catch ex As Exception
                MsgBox("Error message (generic exception): " & ex.Message)
            Catch exp As Security.SecurityException
                MsgBox("Error message: (security exception)" & exp.Message)
            End Try
        End Sub

    (Running this procedure I get the error message as follows:
    "Error message (generic exception): The service (JFW) could not be opened at the following machine: CSABA_PC")

    3. I have an other procedure, which sould get the version number of the running JAWS as follows:
    Private Sub GetJAWSVersion()

    ' JAWS process variable is created and filled on Form_Load
     If Not JAWSProcess.Equals(Nothing) Then
     ' Is JAWS running?
                    MsgBox("JAWS is running in the memory.")

                    ' Which version is running?
                    Try
                        Dim jpm As ProcessModule
     dim strVersion as String

                        jpm = JAWSProcess.MainModule
                        strVersion = jpm.FileVersionInfo.ToString()
                    Catch ex As Exception
                        MsgBox("Error message: " & ex.Message, , "GetJawsVersion")
                    End Try
                End If

    End Sub

    (In this procedure I get the error message: "Access denied", when I try to access the process main modele, the JFW.EXE.)

    So I don't know what I do wrong.

    I should have to know which version is running currently, because on my form's "Installed versions of JAWS" list should be marked the currently running to

    inform my user about which version will be updated.

    That is the first occassion I have to controll a service so I'm very newby on ths playground. :)

    Wednesday, December 19, 2012 10:23 AM
  • Hi Shepherd,

    Thank you for your clarification.

    If your code just working on a 32bit OS, so you can try this method: http://msdn.microsoft.com/en-us/library/8zha3xws(v=vs.80).aspx  

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 20, 2012 1:37 AM
    Moderator
  • Hi Mike,

    I'll kill myself. I give it up! It is more complicated than developing database applications.
    So as last try I've began it from the begining.

    JAWS is started automatically at the start of the system so I thought it works as a service, but I had no success to handle it as service process. So I thougth to handle it as simple process and I try to geht its version information, but I have the well known "Access denied" error.
    JAWS runs every time on local machines and it is user dependent if it started automatically at system start. Even it is user dependent, which version will be started if more then one is installed on the machine. My version of program is dedicated to JAWS 32bit versions running on XP, Vista, Win7, Win8.

    It is my very simple code. The line where I get the error is signed. I think I should have permission to read process module properties, but how can I grant it? I have no idea. In a database app is it a more simple process...

    Private Sub GetJAWSProcess()

            'Enumerate al processes to find out which JAWS IS running
            Try
                Dim ProcessList() As Process
                Dim JAWSModule As ProcessModule

                ProcessList = Process.GetProcesses()

                For Each p As Process In ProcessList
                    Try
                        If p.ProcessName = "jfw" Then
                            JAWSProcess = p
                            JAWSModule = p.MainModule
                            MsgBox("JAWS process name: " & JAWSProcess.ProcessName)

                            ' >>Raising error here: Access denied
                            MsgBox("JAWS process: " & JAWSModule.FileName)
                        End If
                    Catch ex As Exception
                        MsgBox("Error in in process iteration: " & ex.Message, , "GetJAWSProcess")
                    End Try
                Next

            Catch ex As Exception
                MsgBox(ex.Message, , "GetJAWSProcess")
            End Try

        End Sub

    Friday, December 21, 2012 4:04 AM
  • Hi Stepherd,

    I am a little confused about this.

    Do you still need the version?

    If so, as you mentioned, "My version of program is dedicated to JAWS 32bit versions running on XP, Vista, Win7, Win8." so you can try my above code and use this overload method to avoid to involve the .net 4.0 feature: http://msdn.microsoft.com/en-us/library/8zha3xws(v=vs.80).aspx 

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, December 21, 2012 5:53 AM
    Moderator