Recently wrote a WINODWS service for downloading files from a LAN computer, initially thinking there should be no big problem. No problems were found with local debugging. However, when I publish the program and found that the service error "Access path is denied", my first feeling, must be the network folder access rights issues. Well, it's the stupidest way to set the permissions of a folder to everyone. But I ran out of service and found out that I was ignoring you, or the same mistake. Is there an error in the module that downloaded the file? Later I put the download module into a console program and a Web page, all successfully passed. Really do not understand, and then to search the Internet to see homesickness eldest brother's reply, is the Windows service account does not have permission to access network resources. So, I set the service account to NetworkService, debugging is OK. Boss is the boss, great! But with the new problem, the function of my write service log is invalid. What's the reason? is should for my original service account is LocalSystem, service can find local file "C:\DownLoadFileLog.txt",
private void Addtextline (string line)
{
Try
{
FileStream fs = new FileStream (@ "C:\DownLoadFileLog.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter m_streamwriter = new StreamWriter (FS);
M_streamWriter.BaseStream.Seek (0, Seekorigin.end);
M_streamwriter.writeline (line + "\ r \ n");
M_streamwriter.flush ();
M_streamwriter.close ();
Fs. Close ();
}
catch (Exception ex)
{
}
}
And now I've changed it to NetworkService, and it certainly doesn't know where C:\DownLoadFileLog.txt is. Then change it to your web directory and set it up for sharing OK!
such as "//192.168.8.188/share/downloadfilelog.txt/".
Http://www.cnblogs.com/peak-weng/archive/2008/07/29/1255485.html
Access to Windows service (with NetworkService and LocalSystem distinction)