I have windows service which runs under local system account. I am checking File.Exist(File in the network). this works fine with User account but it return false for file.exists() in local system account. I can not run service using user account. Thanks in advance.

protected override void OnStart(string[] args) {
  m_objLogFile.LogError("******************Servicestarted*****************", "", "");
  Thread th = new Thread(new ThreadStart(StartIndexing));
  th.Start(); 
} 
private void StartIndexing() 
{ 
  bool bVal = File.Exists(@"100.100.1.1\f\Files\abc.txt"); 
}
有帮助吗?

解决方案 2

Impersonate your account to access the file.

http://msdn.microsoft.com/en-us/library/ff647248.aspx

其他提示

The Local System account (LSA) is a machine specific account - while it is highly privileged on the machine, it doesn't by rights have any privileges on the network.

To fix this either:

  • run the service under the credentials of an existing user who does have network access privileges
  • or create a new lowly privileged domain account and assign it just the rights it needs, then run the service using the credentials of that user

You also cannot use 100.100.1.1\f\Files\abc.txt as a path for a file - try prefixing it with a double backslash first: \\100.100.1.1\f\Files\abc.txt. Without that double backslash the OS will search for a folder called 100.100.1.1 in your current working directory. (Note that you say this works under normal user credentials - either you are mistaken or you have made a mistake when copying the code here).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top