Windows:使用File.listRoots显示映射的网络驱动器 [英] Windows: Display mapped network drives with File.listRoots
问题描述
import java.io. *;
public class TestFileRoots {
public static void main(String [] args){
for(File f:File.listRoots()){
System.out.println(f.getAbsolutePath());
$ b
当我启动cmd并运行这个类,我所有的驱动器都列出来了。当我以管理员身份启动cmd并运行此操作时,映射的网络驱动器未列出。
另外,当我手动启动服务器并调用File.listRoots ,我所有的驱动器都列出来了。但是,当我使用服务启动服务器时,网络驱动器未列出。
如何始终列出我的网络驱动器?我读了我可以映射在一个服务的网络驱动器,但这不是一个选项。驱动器已经在那里,我不能改变它的一些东西。
映射的驱动器是用户特定的在登录期间)而不是计算机特定的。因此,驱动器上的 userA
日志被映射。当您以不同的用户身份启动程序(即以管理员身份或以SYSTEM身份运行的服务)时,映射的驱动器不可用,因此您无法访问它们。您的选项是:
$ ul
s:\blah
use \\server\shared_folder\blah
Code:
import java.io.*;
public class TestFileRoots {
public static void main(String[] args) {
for(File f : File.listRoots()){
System.out.println(f.getAbsolutePath());
}
}
}
When I start cmd and run this class, all of my drives are listed. When I start cmd as an administrator and I run this, my mapped network drives are not listed.
Also, when I start my server manually and call File.listRoots(), all of my drives are listed. But when I start the server using a service, the network drives are not listed.
How can I always list my network drives? I read I can map the network drive within a service, but that's not an option. The drives are already there and I am not permitted to change something about it.
Mapped drives are user-specific (probably mapped during log-on) and not computer specific. So, when userA
logs on the drives are mapped. When you start your program as a different user (i.e. as administrator or as a service running as SYSTEM) the mapped drives are not available so you can't access them. Your options are:
- Map the drives again as the new user (i.e. service)
- Run your application in the current user's context
- Access the files you need by the UNC path (i.e. instead of
s:\blah
use\\server\shared_folder\blah
这篇关于Windows:使用File.listRoots显示映射的网络驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!