Access to Windows service (with NetworkService and LocalSystem distinction)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.