Link to home
Start Free TrialLog in
Avatar of gubbalasree
gubbalasree

asked on

Not able to start windows service written in vb.net

Hi All,
        I have written windows service in vb.net that will read the registry entires from Current User. Code was working fine on windows application but same code is not working while trying to start the service. Its giving the following error

Could not start the FileConverter(name of my service) service on Local computer.
The service did not return an error. This could be an internal windows error or an internal service error. If the problem persists, contact your system administrator.

Here is my code:

Imports System.ServiceProcess
Imports System.IO
Imports Microsoft.Win32
Imports System.Security.Permissions

<Assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum, All:="HKEY_CURRENT_USER")>


Protected Sub InitializeService()

        Dim rk As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\VB and VBA Program Settings\File Convertor\Inbox", False)
        Dim cnt As Int32

        cnt = rk.GetValue("Source") ' Source is the value under Inbox  key
End Sub

Thanks in advance

Srinivas


Avatar of tinchos
tinchos

are you trying to start it using an administrator account?
(I believe that you need full permits in order to start a service)
Avatar of gubbalasree

ASKER

I have tried with administrator acct but getting the same error.

ASKER CERTIFIED SOLUTION
Avatar of Fahad Mukhtar
Fahad Mukhtar
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Desp that key exists in the registry and if the service starts then i can debug by attaching the process to the debugger.

If i remove the registry access code then the service is starting and i m able to debug by attaching to the debugger.




       
You can try getting the permissions imperatively.
Put the following as first lines of InitializeService():

Dim f As New RegistryPermission(RegistryPermissionAccess.Read, "HKEY_CURRENT_USER\Software\VB and VBA Program Settings\File Convertor\Inbox")

Are you sure this is where your error is coming from?
Have you tried hardcoding a value instead of reading from registry? Did it work?

Hope this helps some,
ZRH
Recommendation: Delete/Not refund