开发者

Windows services permission problems

I have written a windows service that uses the openpop mail client and retreives emails. Then it goes through the subject and body update databases and all kinds of stuff. It also downloads the attachments and creates a folder directory on the drive based on the timestamp of the email it goes by year, then the month, then the day, and then saves the image. So, I built this service on my machine in development using a class library project, a winform project for debugging, and a windows service project. All the logic is contained in a Classlibrary. I build the library and reference the dll in both the form and the windows service. When I build the service on my machine and install it using installutil it works fine, and does what it's supposed to do. But when I went to production, the OS is Windows Server 2003 R2, and it is using a different connection string for the LIVE database.

The only things that changed were the connection string and the operating system. I installed the service and it installed fine, but does nothing. It doesnt create the folders or save the images to disk. I know I should have been logging errors, but this is my first job and I am new in this field. So I tried writing some logging events, but it doesn't create the log and write the events. As a matter of fact, if I try to create the log and write an event, as my first call in the onstart sub, it doesnt do it. Now I'm lost, and I am not sure where to go from here. If you took time to read this, I appreciate any input you may have.

This is the code in my OnStart method.

    Dim LiveEvents As New EventLog
    If Not EventLog.SourceExists("MySource") Then
        EventLog.CreateEventSource("MySource", "GL")
    End If
    LiveEvents.Source = "MySource"
    LiveEvents.Log = "GL"
    LiveEvents.WriteEntry("ServiceStarted and is working.", EventLogEntryType.Information)
    Dim Logic As New ProcessMail
    workTimer开发者_运维技巧 = New Timer(New TimerCallback(AddressOf Logic.ProcessMessages), Nothing, (1000 * 60 * 10), (1000 * 60 * 10))
    LiveEvents.WriteEntry("Called Our DLL", EventLogEntryType.Information)
    MyBase.OnStart(args)

So, if you dont know the questions here they go. 1. If i need to create directorys and save files with a windows service in Windows Server 2003 R2. What System System.ServiceProcess.ServiceInstaller Account property should i be using ? 2. Is there any kind of special setup process that i would need to do in winows server 2003 R2 to allow the service i install to have permissions to have read write acces to directories ?

Thank you for any information and help you can provide.


The account that you choose will need to have sufficient permissions to directories. There is nothing special about the account as long as you set up correct permissions on the folders . The easiest way to troubleshoot is to start with a powerful account (local system for example, you can change accounts at will via service properties applet under "log on" tab, just stop and restart the service and see if the account change makes any difference). You can also allow 'everyone" to have full access to the folder and see if hat makes any difference. Just remember to leave only necessary and as little as possible powers and permissions after you diagnose the problem.

Also, it's possible that your problem is somewhere else. You should check the Event Viewer for any errors. You can use a few tools from sysinternals that could help you find the problem (http://technet.microsoft.com/en-us/sysinternals/bb545027). The account that the service runs as will need to have sufficient permission to write to event log. So this is one more reason to try to run that service as a privileged user to see if it will start writing to the log. And of course as you mentioned adding more logging could be a good option too.

Make sure that the service installed without errors and shows as running in the services applet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜