0

我创建了一个 powershell 脚本,它在执行时询问我是否正确卸载了某个 U 盘(已定义名称和标签)。但前提是它仍然插入并且具有定义的驱动器号)。

原因是加密软件必须在卸载 U 盘之前自行卸载它(加密并释放驱动器)。如果这没有发生并且 PC 关闭,则 USB 记忆棒必须在再次启动时重新加密,这需要大约 30 分钟,这是不希望的。

使用该脚本,现在应该通过弹出窗口通知客户相应的 USB 记忆棒仍然插入,并且卸载命令可能仍需要在加密软件中执行(不会自动工作)。如果他刚刚忘记拔掉摇杆,他可以继续通过弹出“是 - 忘记”来关闭。使用“否”应取消关机。

到目前为止一切顺利,脚本可以工作,但是当 PC 关闭时我无法运行脚本。

我已经尝试过的:

  • powercfg.exe / hibernate off 在命令行中
  • 在 gpedit.msc 中将脚本作为 Powershell 输入,并将其设置为“先执行”
  • 在 gpedit.msc 中激活脚本执行和消息输出
  • 文件路径为:C:\Windows\System32\GroupPolicy\Machine\Scripts\Shutdown\umount.ps1

发生了什么:出现 Windows 关机屏幕,但没有消息。关机进程挂起。

我的脚本:

$driveLabel = 'USBSTICK'
$driveLetter = (Get-Volume -FileSystemLabel $driveLabel).DriveLetter
$driveletterShouldBe = 'F'
write-host (get-date -format s) " Drive name = " $driveLetter
write-host (get-date -format s) " Drive label = " $driveLabel
# Execute process if drive matches specified condition(s)
if ($driveLetter -eq $driveletterShouldBe){
    [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    $result = [System.Windows.Forms.MessageBox]::Show('Ist der USB Stick absteckbar?' , "Info" , 4)
    if ($result -eq 'Yes') {
        $Eject = New-Object -comObject Shell.Application    
        $Eject.NameSpace(17).ParseName($driveLetter+“:”).InvokeVerb(“Eject”)
    }else{
        exit
    }
} else {
    #just for testing in console
    write-host (get-date -format s) " Drive letter = " $driveLetter
    write-host (get-date -format s) " Drive letter should be = " $driveletterShouldBe
    write-host (get-date -format s) " Drive label = " $driveLabel
    sleep(5)
}
´´´

Hope someone can help me
Thank you in advance
Best
Cypherfax
4

0 回答 0