首页 > 系统相关 >Windows Service 服务中,不能访问挂载目录(网络映射盘)

Windows Service 服务中,不能访问挂载目录(网络映射盘)

时间:2023-03-21 14:35:31浏览次数:51  
标签:Service 映射 Windows result path 挂载

Windows Service 服务中,不能访问挂载目录(网络映射盘)

网盘挂载(映射网络驱动器)

详见:https://www.cnblogs.com/vipsoft/p/17059153.html

测试代码

@GetMapping("/network")
public String testPath(HttpServletRequest request) {
    String path=request.getParameter("path");
    String result = "";
    if (FileUtil.exist(path)) {
        result = ("挂载目录,存在 => " + path);
    } else {
        result = ("挂载目录,不存在 => " + path);
    }
    return result;
}

正常运行

http://localhost:8080/demo/network?path=D%3A\
image

做成服务

SpringBoot 做成 Windows Service 服务:https://www.cnblogs.com/vipsoft/p/17236063.html
做成 Windows Service 服务后,挂载盘不可访问,如下图所示:
image

解决方案

下载PsExec

https://learn.microsoft.com/zh-cn/sysinternals/downloads/psexec
image

执行命令

  1. 运行CMD,执行 psexec -i -s cmd.exe
    image
  2. 在新开的CMD窗口中运行网络映射 net use z: \\10.10.x.xxx\test /persistent:yes
    image
  3. 输入用户名和密码映射成功
  4. 再运行服务,成功访问网络映射盘
    image

标签:Service,映射,Windows,result,path,挂载
From: https://www.cnblogs.com/vipsoft/p/17239713.html

相关文章