java - 使用 powershell 系统用户映射的驱动器无法被其他人访问

标签 java amazon-web-services powershell

我正在尝试使用 powershell 中的“系统”帐户将驱动器映射到另一台服务器。我成功了,但是只有以系统身份登录才能访问服务器,而不能以管理员或普通用户身份登录。

如果我使用管理员 powershell 或 dos 命令 shell 映射它,那么每个人都可以使用它。不幸的是,我无法做到这一点,因为我使用 Amazon Web Service (AWS) SendCommand 功能来进行映射,并且它仅使用系统级 powershell。即使我将映射命令放入批处理文件中并让它运行,映射的驱动器仍然仅对系统 powershell 用户可用。

以下是通过 AWS SendCommand 发送的两个命令的示例:

cd "C:/Program Files/Enventive/EnCOM Listener 1.0/lib/"
start-process "cmd.exe" "/c MapNetworkDrive 172.31.26.59"

批处理文件执行如下 net use 命令:

net use D: \\%1\Company /USER:Administrator /PERSISTENT:YES "<password>"

有没有办法让所有用户都可以使用系统级 powershell 映射的驱动器?

我还在系统级 powershell 中尝试了以下方法,但得到了相同的结果:

$user = "Administrator"
$pass = ConvertTo-SecureString -String '<password>' -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user,$pass
New-PSDrive -Name D -PSProvider FileSystem -Root \\172.31.26.59\Company -Credential $cred -Persist

执行此操作后,D: 驱动器可从系统级 powershell 中使用,但不能从 DOS 命令 shell 或管理员级 powershell 中使用

最佳答案

有没有办法让所有用户都可以使用系统级 Powershell 映射的驱动器? 没有。

New-PSDrive

Mapped network drives are specific to a user account. Mapped network drives that you create in sessions that are started by using the Run as administrator option or by using the credential of another user are not visible in a session that was started without explicit credentials, or by using the credentials of the current user.

顺便说一下,you can run into drive letter collisions将映射的驱动器号分配给 D...

A and B are typically reserved for the floppy drives of last century, and C and D are usually reserved for the hard drive and optical drive, so the card reader will use E, F, G, and H.

关于java - 使用 powershell 系统用户映射的驱动器无法被其他人访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50158170/

相关文章:

Powershell - 如何检查具有所需创建时间的文件是否存在?

java - 如何从命令行将参数传递到 JMX MBean 函数

java - JSNI 方法显然不会被编译或添加到生成的 JavaScript 中

java - 带有 SimpleCursorAdapter 的 Android ListView - 恢复时崩溃

amazon-web-services - 扫描 DynamoDB 中的关键属性

powershell - 如何使用巧克力创建和安装 powershell 命令包?

c++ - 如何编写使用 powershell 而不是 cmd 的控制台应用程序

java - 如何解决Java堆空间错误

amazon-web-services - 如何使用 pulumi aws provider 定义默认标签

postgresql - 如何为 PostgreSQL 设置 AWS RDS 的跨区域副本