2016-08-09 3 views

답변

0

PopUp에 대해 time to live을 설정할 수있는 Windows 스크립트 호스트의 PopUp Method이 있습니다. PowerShell에서 메시지 상자를 새로 고침 할 방법이 없다고 생각하지 않습니다. (저를 인용하지 마십시오). 두 줄의 코드는 here에서 왔습니다. @JonDechiro 제시 한 해결책은 무엇을 요구 영업 이익 나보다 훨씬 깨끗하고 apropriate입니다 :

$timer = New-Object System.Timers.Timer 
$timer.AutoReset = $true #resets itself 
$timer.Interval = 1000 #ms 
$initial_time = Get-Date 
$end_time = $initial_time.AddSeconds(12) ## don't know why, but it needs 2 more seconds to show right 

# create windows script host 
$wshell = New-Object -ComObject Wscript.Shell 
# add end_time variable so it's accessible from within the job 
$wshell | Add-Member -MemberType NoteProperty -Name endTime -Value $end_time 

Register-ObjectEvent -SourceIdentifier "PopUp Timer" -InputObject $timer -EventName Elapsed -Action { 
    $endTime = [DateTime]$event.MessageData.endTime 
    $time_left = $endTime.Subtract((Get-Date)).Seconds 

    if($time_left -le 0){ 
     $timer.Stop() 
     Stop-Job -Name * -ErrorAction SilentlyContinue 
     Remove-Job -Name * -ErrorAction SilentlyContinue 
     #other code 
     # logoff user? 
    } 
    $event.MessageData.Popup("Your PC will be shutdown in $time_left sec",1,"Message Box Title",64) 
} -MessageData $wshell 

$timer.Start() 

편집 : 당신이 원하는이,하지만이 (원액) 작동하는지

확실하지 않음 .

1

메시지 상자의 텍스트를 새로 고치는 방법이 없습니다. 이 작업을 수행해야한다면 레이블이있는 다른 양식이 나타나고 각 틱에서 레이블 텍스트를 새로 고치는 타이머를 사용합니다. 여기

는 잠재적 인 시작점을 사용하는 코드 예제입니다

Add-Type -AssemblyName System.Windows.Forms 
Add-Type -AssemblyName System.Drawing 
$Form = New-Object system.Windows.Forms.Form 
$script:Label = New-Object System.Windows.Forms.Label 
$script:Label.AutoSize = $true 
$script:Form.Controls.Add($Label) 
$Timer = New-Object System.Windows.Forms.Timer 
$Timer.Interval = 1000 
$script:CountDown = 60 
$Timer.add_Tick(
    { 
     $script:Label.Text = "Your system will reboot in $CountDown seconds" 
     $script:CountDown-- 
    } 
) 
$script:Timer.Start() 
$script:Form.ShowDialog() 
당신은 당신이 원하는대로 행동 할 수있는 조건부 논리로 요구를 충족하기 위해 확장해야합니다

(예를 들면, 재부팅) 할 때 계수 아래로 0, 어쩌면 중단을위한 단추를 추가하십시오.

관련 문제