简体   繁体   English

访问远程计算机文件时Windows服务问题

[英]Windows service Problem When Accessing Remote Machine File

I created a Windows Service which Access File from Remote Machine. 我创建了一个Windows服务,可以从远程计算机访问文件。 but It gives error in Log file that File Does Not Exist.When i deployed it then and then only it gives error otherwise when i am debugging from Visual Studio 2005 then it is working fine. 但是它在日志文件中给出了文件不存在的错误。当我部署它然后又只有它给出错误时,否则当我从Visual Studio 2005进行调试时,它就可以正常工作。 I tried to change Properties of Service from Log On tab. 我试图从“登录”选项卡更改“服务属性”。 gives Logon as: then choose this Account and Gives Name of Remote Machine and Password Still it is not working. 将登录名指定为:然后选择此帐户,并提供远程计算机的名称和密码仍然无法正常工作。 Please Help me out. 请帮帮我。

Code: 码:

if (File.Exists(FileName))
{


}
else
{
  Log.append("File Not Exist Path=:" + FileName, 75);
}

Error: 错误:

File Not Exist Path=: \\Computer-01\\Trend Till_04Feb\\Trend Till_04Feb\\TREND\\128.DBF 文件不存在路径=:\\ Computer-01 \\趋势Till_04Feb \\趋势Till_04Feb \\ TREND \\ 128.DBF

I assume you are using ServiceProcessInstaller and ServiceInstaller. 我假设您正在使用ServiceProcessInstaller和ServiceInstaller。

The most important property is Account within the ServiceProcessInstaller class. 最重要的属性是ServiceProcessInstaller类中的Account。 It specifies the Windows account under which the service runs (security context). 它指定运行服务的Windows帐户(安全上下文)。 The following options are available: 提供以下选项:

LocalService: Service presents the computer's credentials to remote servers. LocalService:服务将计算机的凭据提供给远程服务器。

LocalSystem: Service presents anonymous credentials to remote servers. LocalSystem:服务向远程服务器提供匿名凭据。

NetworkService: Service has limited local privileges and presents the computer's credentials to remote servers. NetworkService:服务具有有限的本地特权,并向远程服务器提供计算机的凭据。

User: A local or network account is specified. 用户:指定了本地或网络帐户。 You may specify the necessary username and password via properties, or you may type them during installation. 您可以通过属性指定必要的用户名和密码,也可以在安装过程中键入它们。 The Service uses the security context of the specified user account. 该服务使用指定用户帐户的安全上下文。

Following three options are provided to specify how your service is started. 提供以下三个选项以指定如何启动服务。

Manual :- The user starts the service. 手册:-用户启动服务。

Automatic :- The service starts automatically when the system starts. 自动:-服务在系统启动时自动启动。

Disabled :- The service is not available for use. 已禁用:-该服务不可用。

  1. Go to Properties of ServiceInstaller object and set ServiceName and StartType to Automatic. 转到ServiceInstaller对象的属性,然后将ServiceName和StartType设置为Automatic。

  2. Go to Properties of ServiceProcessInstaller and set Account property to LocalService. 转到ServiceProcessInstaller的属性,然后将“帐户”属性设置为LocalService。 This causes the service to run on local service account. 这会使服务在本地服务帐户上运行。

HTH 高温超导

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM