I am working to create a GUI to run a number of computer configuration tasks. I have successfully configured the form and commands. The issue I am running into at this point is that some of the tasks take some time to complete. I am trying to enact some action that will inform the user that the tasks are running. At this point, clicking on the Complete Actions button will start the tasks and grey out the button to advise the user that it is running. I am struggling to add a visual cue for the user based on the running tasks. I am not picky on its implementation. Whether it be the button changing back to an actionable state, a progress bar of some sort, or output showing the completion of tasks. Any guidance or assistance on this would be greatly appreciated.
GUI progress info for running tasks
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: GUI progress info for running tasks
- # Some dummy jobs for illustration purposes
- Start-Job -ScriptBlock{Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server'-name "fDenyTSConnections" -Value 0 } -Name RemoteDesktop
- Start-Job -ScriptBlock{Set-TimeZone -Id "US Mountain Standard Time" } -Name MountainTime
- Start-Job -ScriptBlock{powercfg /change monitor-timeout-ac 10 | powercfg /change monitor-timeout-dc 10 | powercfg /change standby-timeout-ac 0 | powercfg /change standby-timeout-dc 15 } -Name PowerSettings
- Start-Job -ScriptBlock{gpupdate /force } -Name GroupPolicy
- Start-Job -ScriptBlock{Invoke-WMIMethod -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000113}" } -Name SCCMUpdate
- # Get all the running jobs
- $jobs = get-job | ? { $_.state -eq "running" }
- $total = $jobs.count
- $runningjobs = $jobs.count
- # Loop while there are running jobs
- while($runningjobs -gt 0) {
- # Update progress based on how many jobs are done yet.
- write-progress -activity "Events" -status "Progress:" `
- -percentcomplete (($total-$runningjobs)/$total*100)
- # After updating the progress bar, get current job count
- $runningjobs = (get-job | ? { $_.state -eq "running" }).Count
- }
Re: GUI progress info for running tasks
I found the above code that works independently in the ISE but I am unsure how to integrate it into my existing form.
Re: GUI progress info for running tasks
To run asynchronous tasks consider the following article:
https://info.sapien.com/index.php/guis/ ... sive-forms
https://info.sapien.com/index.php/guis/ ... sive-forms