我一直将我的 USB 驱动器连接到我部门的实验室机器上。到目前为止,我很幸运总能在失物招领处找到它,但在需要的时候却找不到它,这就有点烦人了。
是否有可用的实用程序/脚本,可以在我注销之前提示我将其删除?
我正在寻找在 Windows 和 Linux 中执行此操作的解决方案。
有没有关于如何编写的指示?
答案1
检查可移动设备是否存在的简单 VBScript 如下所示:
boolDeviceFound = False
strComputer = InputBox("Enter the name of the computer to search for USB devices:")
strComputer = Trim(strComputer)
If LenB(strComputer) = 0 Then
strComputer = "."
End If
'Query the WMI service for the computer name
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
'Display the connected computer
WScript.Echo "You have successfully connected to computer " & strComputer
Set colItems = objWMIService.ExecQuery("SELECT * from Win32_LogicalDisk WHERE Description = 'Removable Disk'")
For Each objItem in colItems
WScript.Echo "The computer " & strComputer & " has a removable USB drive connected with drive letter: " & objItem.Name
WScript.Echo "Please remove this device from " & strComputer & " to comply with Lab policies!"
boolDeviceFound = True
Next
If boolDeviceFound = False Then
WScript.Echo "No USB devices found!"
End If
如果你将其保存为类似检测USB,可以使用 来从命令行或批处理文件执行wscript DetectUSB.vbs
。也可以使用 PowerShell 编写类似的东西,批处理文件/PS 脚本可以是设置为注销脚本。唯一的问题是,您是否拥有足够的权限在实验室电脑上安装注销脚本?