PsExec 运行 远程注册表文件。在 PC 上禁用 USB

PsExec run registry file remotely. disabling USB on a PC

我想在 PC 上阻止 USB 大容量存储设备,我想使用 powershell 远程执行此操作。

$computer = 'hostname';
$username = 'hostname_username';
$password = 'password';
$usb      = '//remote/installer/lockRemovableStorageDevices.reg';

$usb_command = "psExec -i -d -c -f -s \$computer -u $computer$username -p $password `"$usb`"";

Write-Output "Disabling USB in $computer.";

Invoke-Expression $usb_command; 

根据 运行 这段代码,我得到了这个错误。

PsExec could not start lockRemovableStorageDevices.reg on computer_name:

谢谢,

在 PowerShell 中有多种方法可以做到这一点 "better"。您可以使用远程注册表提供程序和 WMI 访问注册表来直接操作远程注册表。或者,使用 Invoke-Command 在远程计算机上调用命令。

如果您确实想坚持使用 psExec,则必须导入 .reg 文件。 在您的脚本中试试这个:

$usb = 'regedit /s //remote/installer/lockRemovableStorageDevices.reg'