访问作为服务运行时拒绝访问网络路径

时间:2015-05-27 06:05:25

标签: .net

此代码:

public class Register1 {

    String name;
    String location;
    int id;
    int salary;

    public Register1(String name, String location, int id, int salary) {
        this.name = name;
        this.location = location;
        this.id = id;
        this.salary = salary;

    }

}


import java.util.*;

public class Employee {

    public static void main(String[] args) {
        ArrayList<Register1> Emp = new ArrayList<Register1>();
        Emp.add(new Register1("Jack", "London", 101, 800));
        Emp.add(new Register1("Mike", "UK", 100, 60000));
        Emp.add(new Register1("Andrew", "China", 103, 2000));
        Emp.add(new Register1("Michel", "Korea", 106, 300000));
        Emp.add(new Register1("Donald", "London", 102, 90000));

        List<Register1> reg = new ArrayList<Register1>();
        String input = "London";
        for (Register1 adrs : Emp) {
            if (adrs.location.equals(input)) {
                reg.add(adrs);

            }
        }

        for (Register1 adrs : reg) {
            System.out.println("Employee from London:" + adrs.salary + " "
                    + adrs.location + " " + adrs.id + " " + adrs.name);
        }
    }
}

给了我这个错误:

  

拒绝访问路径'\\ 10.31.42.249 \ share \ file.txt'。

当我将其作为Windows服务运行时。同一台PC上的控制台应用程序中的相同代码工作正常。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

我认为这是一项维权问题。您应该让拥有该共享权限的用户运行该服务,可能是具有最小权限的网络用户。你应该检查:

  1. 服务凭证;
  2. 在服务器上的文件共享上发布的权限。