question

heyangben-3420 avatar image
0 Votes"
heyangben-3420 asked heyangben-3420 commented

set execution timeout for batch

For example, if I execute a "start /w PKGMGR /iu:" installation command, If the execution has not been completed for more than ten minutes, a prompt will pop up. How do I set the timeout and prompt?

windows-server-powershellwindows-10-setup
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @heyangben-3420 ,

The openspec-* tags are dedicated to supporting issues related to open specifications. You can find open specifications here https://docs.microsoft.com/en-us/openspecs/

Since your question does not pertain to one of these specifications, I've removed the openspecs-windows tag and added the windows-server-powershell tag. Hopefully this will get your post the proper attention.

If I've misunderstood your question and you believe this is related to the Open Specifications documents, please clarify, providing the document name and section with which you have the question or issue.

Best Regards,

Michael Bowen
Escalation Engineer - Microsoft Open Specifications

0 Votes 0 ·
MotoX80 avatar image MotoX80 MikeBowen-1599 ·

heyangben-3420 asked the question.

0 Votes 0 ·

You are correct, I fixed my post, thanks for catching that!

0 Votes 0 ·

thanks

0 Votes 0 ·

1 Answer

MotoX80 avatar image
0 Votes"
MotoX80 answered heyangben-3420 commented

You will need to use Powershell to do that.

 [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
 $process = Start-Process "PkgMgr.exe" -PassThru
 $StartTime = Get-Date
 Write-Host "You have 15 seconds to do something."
 while ($true) {
     if ($process.HasExited) {
         Write-Host "It ended."
         break
     }
     Start-Sleep 5 
     Write-Host "Testing."
     $ts = New-TimeSpan –Start $StartTime –End (Get-Date) 
     if ($ts.TotalSeconds -gt 15) {
         $oReturn=[System.Windows.Forms.Messagebox]::Show("What is taking so long??????")
         Write-Host "You took too long."
         $process.Kill() 
         break
     }
 }

This site shows how to generate a prompt.

https://michlstechblog.info/blog/powershell-show-a-messagebox/

· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Think you very much
But I want to be able to achieve in the Win7 system
Win7 can achieve it?

0 Votes 0 ·
MotoX80 avatar image MotoX80 heyangben-3420 ·

It should, but I no longer have a Win7 machine to test with. Open Powershell_ISE and paste the script into a code window and run it.

195772-capture.png



0 Votes 0 ·
capture.png (164.4 KiB)

thank you,I go to try

0 Votes 0 ·

Last I was wondering,Can you do that with CMD?

0 Votes 0 ·
Show more comments