Windows服务权限问题
我编写了一个使用 openpop 邮件客户端并检索电子邮件的 Windows 服务。然后它会检查主题和正文更新数据库以及各种内容。它还会下载附件,并根据电子邮件的时间戳(按年、月、日)在驱动器上创建文件夹目录,然后保存图像。因此,我在开发中的机器上使用类库项目、用于调试的 winform 项目和 Windows 服务项目构建了此服务。 所有逻辑都包含在类库中。我构建了库并在表单和 Windows 服务中引用了 dll。当我在我的计算机上构建该服务并使用 installutil 安装它时,它工作正常,并且执行了它应该执行的操作。但当我投入生产时,操作系统是 Windows Server 2003 R2,并且它对 LIVE 数据库使用不同的连接字符串。
唯一改变的是连接字符串和操作系统。我安装了该服务并且安装得很好,但什么也没做。它不会创建文件夹或将图像保存到磁盘。我知道我应该记录错误,但这是我的第一份工作,而且我是这个领域的新手。所以我尝试编写一些日志记录事件,但它不会创建日志并写入事件。事实上,如果我尝试创建日志并写入事件,作为我在 onstart 子中的第一次调用,它不会执行此操作。现在我迷路了,我不知道从这里该去哪里。如果您花时间阅读本文,我非常感谢您提供的任何意见。
这是我的 OnStart 方法中的代码。
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)
所以,如果你不知道这里的问题,那就去吧。 1. 如果我需要在 Windows Server 2003 R2 中使用 Windows 服务创建目录并保存文件。我应该使用什么系统 System.ServiceProcess.ServiceInstaller 帐户属性? 2. 我需要在 winows server 2003 R2 中执行任何类型的特殊设置过程,以允许我安装的服务有权对目录进行读写访问吗?
感谢您提供的任何信息和帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您选择的帐户需要对目录具有足够的权限。只要您对文件夹设置正确的权限,该帐户就没有什么特别的。最简单的故障排除方法是从一个强大的帐户开始(例如本地系统,您可以通过“登录”选项卡下的服务属性小程序随意更改帐户,只需停止并重新启动服务,看看帐户更改是否有任何影响)。您还可以允许“每个人”完全访问该文件夹,看看这是否有什么不同。只要记住在诊断问题后只保留必要且尽可能少的权力和权限。
此外,您的问题可能是您应该检查事件查看器是否有任何错误。您可以使用 sysinternals 中的一些工具来帮助您找到问题 (http://technet.microsoft.com/en-us/sysinternals/bb545027)。服务运行的帐户需要有足够的权限才能写入事件日志,因此这是尝试以特权用户身份运行该服务以查看它是否会开始写入日志的又一个原因。您提到添加更多日志记录也可能是一个不错的选择,
请确保服务安装没有错误并在服务小程序中显示为正在运行。
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.