【发布时间】:2021-06-09 06:25:24
【问题描述】:
我是 powershell 新手!
感谢任何抽出时间来帮助我的人。
注意:我不是管理员,我的 POWERSHELL 正在受限模式下运行 - 由于工作政策,无法更改:D
到目前为止,我有以下代码:
Add-Type -AssemblyName System.Windows.Forms
$global:balloon = New-Object System.Windows.Forms.NotifyIcon
Get-Member -InputObject $Global:balloon
[void](Register-ObjectEvent -InputObject $balloon -EventName MouseDoubleClick -SourceIdentifier IconClicked -Action {
#Perform cleanup actions on balloon tip
$global:balloon.dispose()
Unregister-Event -SourceIdentifier IconClicked
Remove-Job -Name IconClicked
Remove-Variable -Name balloon -Scope Global
})
$path = (Get-Process -id $pid).Path
$balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
[System.Windows.Forms.ToolTipIcon] | Get-Member -Static -Type Property
$balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning
$balloon.BalloonTipText = 'What do you think of this balloon tip?'
$balloon.BalloonTipTitle = "Attention $Env:USERNAME"
$balloon.Visible = $true
$balloon.ShowBalloonTip(5000)
遗憾的是,这在受限工作中不起作用 - 我无法使用 Add-Type 功能。是否有代码允许没有管理员权限的人在受限模式下在 powershell 中进行气球类型提示通知(或任何类似的 - 只需要弹出消息)。
错误:
Cannot invoke method. Method invocation is supported only on core types in this language mode.
如果这根本不可能,请不要担心,有人可以澄清一下,以便我可以告诉我的网络管理员。
【问题讨论】:
-
如果只运行
Add-Type -AssemblyName System.Windows.Forms命令会出现什么错误? -
感谢您的评论:D 无法调用方法。仅此语言模式下的核心类型支持方法调用。
-
要求约束模式的目的是什么? (PowerShell 是一个程序,而不是安全边界。)
-
老实说,我完全同意,这很令人沮丧,但我无能为力:(
标签: powershell powershell-2.0 powershell-3.0 powershell-4.0 powershell-remoting