我有一个功能内的作业,它需要一个屏幕截图。脚本本身由Taskscheduler作为域管理员执行。我还检查了“以最高权限运行”。为什么我的屏幕截图功能不能作为工作
工作应该做一个截图,然后发送电子邮件,但这两件事情都不会发生。我也没有看到错误信息(可能是因为它是后台工作?)。也许电子邮件不会被发送,因为它要将截图附加到电子邮件上,但不能因为屏幕截图未被创建。
为什么我的功能没有截图?域管理员有权写入目标。当我运行start-job
以外的功能时,屏幕截图会被创建。如果我具有start-job
内部的功能,它不会被创建,如果脚本是通过Taskscheduler启动或手动启动,则无关紧要。
我错过了什么?
下面的代码开始工作,并采取截图:
Start-Job -Name LogikWebserverWatch {
function Take-Screenshot([string]$outfile)
{
[int]$PrtScrnWidth = (gwmi Win32_VideoController).CurrentHorizontalResolution
[int]$PrtScrnHeight = (gwmi Win32_VideoController).CurrentVerticalResolution
$bounds = [Drawing.Rectangle]::FromLTRB(0, 0, $PrtScrnWidth, $PrtScrnHeight)
$bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height
$graphics = [Drawing.Graphics]::FromImage($bmp)
$graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)
$bmp.Save($outfile)
$graphics.Dispose()
$bmp.Dispose()
}
while ((Get-Process LogikWebserver).Responding) {sleep -Milliseconds 50}
if (!(Get-Process LogikWebserver).Responding) {
Try{
$utf8 = New-Object System.Text.utf8encoding
$datetime = (get-date).ToString('yyyyMMdd-HHmmss')
Take-Screenshot -outfile C:\Install\LogikWebserverErrorReporting\Screenshot-$datetime.png
# some more code [...]
} Catch { some more code [...] }
}}
当我运行函数的前两行时,出现'System.Object [ ]“来键入”System.Int32“。 - 你没有明白吗? – Bassie
@Bassie nope。我已经在其他脚本中多次使用过该函数。如何在“CurrentHorizontalResolution”中有两个或更多值?你有两张图形卡吗? – SimonS
你确定'脚本本身是由Taskscheduler作为域管理员来执行吗?这是很多特权。 – vonPryz