运行 PowerShell [System.windows.forms.messagebox] 通过不显示 cmd window 的批处理文件

Run PowerShell [System.windows.forms.messagebox] through a Batch file without cmd window showing

我正在尝试创建一个自动化流程,用于在每次登录笔记本电脑时清除用户数据。主要部分已经完成,我正处于抛光阶段。我在启动时有两个批处理文件 运行,它们从正在登录的配置文件中清除用户数据,它们都可以工作。我的问题是出现在我的对话框后面的 cmd window(见图)。

研究如何让这个 cmd 框不可见引导我使用 VBS。我确实找到了解决方案,但现在对话框根本不显示。我相信这可能是因为 VBS 脚本使所有 windows 提示不可见。

最重要的是,如何在不使用 CMD window 打开的情况下让我的对话框出现?

VBScript 当前 运行正在此处的公共启动文件夹下:

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp

删除脚本:

@echo off

::Set color of script
color 0a

::Title
title Loaner data wipe
set userpreserve="Administrator,All Users,Default,Public,barfiej"

::All files and folders within the parent folders below will be deleted.
c:
del /S /F/ Q "C:\Users\%USERNAME%\AppData\Local\Microsoft\Outlook\*"
del /S /F/ Q "C:\Users\%USERNAME%\Contacts\*"
del /S /F/ Q "C:\Users\%USERNAME%\Desktop\*"
del /S /F/ Q "C:\Users\%USERNAME%\Documents\*"
del /S /F/ Q "C:\Users\%USERNAME%\Downloads\*"
del /S /F/ Q "C:\Users\%USERNAME%\Favorites\*"
del /S /F/ Q "C:\Users\%USERNAME%\Links\*"
del /S /F/ Q "C:\Users\%USERNAME%\Music\*"
del /S /F/ Q "C:\Users\%USERNAME%\OneDrive\*"
del /S /F/ Q "C:\Users\%USERNAME%\OneDrive - Six Continents Hotels, Inc\*"
del /S /F/ Q "C:\Users\%USERNAME%\Pictures\*"
del /S /F/ Q "C:\Users\%USERNAME%\Saved Games\*"
del /S /F/ Q "C:\Users\%USERNAME%\Searches\*"
del /S /F/ Q "C:\Users\%USERNAME%\Videos\*"

::Clear credential manager
For /F "tokens=1,2 delims= " %G in ('cmdkey /list ^| findstr Target') do cmdkey /delete %H

对话框cmd:

powershell -Command "Add-Type -AssemblyName System.Windows.Forms; C:\ProgramData\LoanerBatchFile\dialogue_box.ps1;"

dialogue_box.ps1:

Add-Type -AssemblyName System.Windows.Forms

[System.windows.forms.messagebox]::show("Welcome to your loaner computer.

`nPlease keep the follow the following instructions while using the loaner laptop.

`n- Save all documents to OneDrive. Data is set to be removed from the user profile at each logoff

`n- Use Webmail

`n- Please keep the computer clean

`n- Be sure to return loaner when picking up your computer");

VBS 脚本:

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run chr(34) & "C:\ProgramData\LoanerBatchFile\UserDataDeletion.bat" & Chr(34), 0
WshShell.Run chr(34) & objShell.Run("C:\ProgramData\LoanerBatchFile\dialogue.bat") & Chr(34), 0
Set WshShell = Nothing

您可以尝试另一种方式:

$wsh = New-Object -ComObject Wscript.Shell 
[Void]$wsh.PopUp("Message content here")

作为我上面最初评论的后续。

未经测试,因为我没有任何东西可以测试这个概念,但是,大致类似于...

Add-Type -AssemblyName System.Windows.Forms

& cmd.exe set userpreserve="Administrator,All Users,Default,Public,barfiej"

# All files and folders within the parent folders below will be deleted.

'C:\Users\%USERNAME%\AppData\Local\Microsoft\Outlook\*',
'C:\Users\%USERNAME%\Contacts\*',
'C:\Users\%USERNAME%\Desktop\*',
'C:\Users\%USERNAME%\Documents\*',
'C:\Users\%USERNAME%\Downloads\*',
'C:\Users\%USERNAME%\Favorites\*',
'C:\Users\%USERNAME%\Links\*',
'C:\Users\%USERNAME%\Music\*',
'C:\Users\%USERNAME%\OneDrive\*',
'C:\Users\%USERNAME%\OneDrive - Six Continents Hotels, Inc\*',
'C:\Users\%USERNAME%\Pictures\*',
'C:\Users\%USERNAME%\Saved Games\*',
'C:\Users\%USERNAME%\Searches\*',
'C:\Users\%USERNAME%\Videos\*' | 
ForEach { Remove-Item -Path $PSItem -Recurse -Force}

<#
https://docs.microsoft.com/en-us/archive/blogs/rmilne/script-to-clear-credman
#>

& cmd.exe For /F "tokens=1,2 delims= " %G in ('cmdkey /list ^| findstr Target') do cmdkey /delete %H

[System.windows.forms.messagebox]::show(
"Welcome to your loaner computer.
`nPlease keep the follow the following instructions while using the loaner laptop.
`n- Save all documents to OneDrive. Data is set to be removed from the user profile at each logoff
`n- Use Webmail
`n- Please keep the computer clean
`n- Be sure to return loaner when picking up your computer"
)

同样,将其放入分配给 RunOnce 或登录时的 logon/startup 计划任务中。