From this site I'm trying to download the timer example script. I have Deleted all Cookies from with Chrome and IE 11. Yet from both browsers when I try to access the Downloads page I get this error.
Disallowed Key Characters.
If you are seeing this message, please delete the cookie "__utmt_~1" and try again.
Is this downloads link working?
can't download sample program
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: can't download sample program
For your convenience, I have uploaded the file here. We have modified our site so that you should no longer receive the error message. However, our site is hosted in the cloud and it may take a bit of time for all nodes to be updated with the new code. Our apologies for the inconvenience.
- Attachments
-
- PassingAndReturningValuesSampleProject.zip
- (7.07 KiB) Downloaded 197 times
June Alane Reif
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: can't download sample program
My apologies. I posted the wrong sample. Here is the timer control sample script.
- Attachments
-
- TimerControl.zip
- (79.68 KiB) Downloaded 209 times
June Alane Reif
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: can't download sample program
The downloads (.zip)now work. Don't see the errors anymore. Thanks for the fast response.
Re: can't download sample program
Thank you. That time control script works as expected but when I try to merge that logic with my existing code it does not work. What is interesting is the following code complies and runs without error, but I never see my countdown. Any hints of why/where my code is wrong?
$FormEvent_Load = {
#TODO: Initialize Form Controls here
$TotalTime = 10
$labelTime.Text = "{0:D2}" -f $TotalTime
$script:StartTime = (Get-Date).AddSeconds($TotalTime)
$timerUpdate.Start()
}
$buttonDelayRebootFor1Hour_Click = {
#TODO: Place custom script here
$regkeypath = "hklm:\Software\MGH"
$value1 = (Get-ItemProperty $regkeypath).OneHour
If ($value1 -contains '1') { Start-Sleep -m 1 }
ELSE { New-ItemProperty HKLM:\SOFTWARE\MGH -name "OneHour" -Value "1" }
$MainForm.Close()
}
$buttonRebootNow_Click = {
#TODO: Place custom script here
remove-itemproperty -path HKLM:\Software\MGH -name OneHour
Restart-Computer localhost -Force
$MainForm.Close()
}
$timerUpdate_Tick = {
#Use Get-Date for Time Accuracy
[TimeSpan]$span = $script:StartTime - (Get-Date)
#Update the display
$formSampleTimer.Text = $labelTime.Text = "{0:N0}" -f $span.TotalSeconds
if ($span.TotalSeconds -le 0)
{
$MainForm.Close()
}
}
$FormEvent_Load = {
#TODO: Initialize Form Controls here
$TotalTime = 10
$labelTime.Text = "{0:D2}" -f $TotalTime
$script:StartTime = (Get-Date).AddSeconds($TotalTime)
$timerUpdate.Start()
}
$buttonDelayRebootFor1Hour_Click = {
#TODO: Place custom script here
$regkeypath = "hklm:\Software\MGH"
$value1 = (Get-ItemProperty $regkeypath).OneHour
If ($value1 -contains '1') { Start-Sleep -m 1 }
ELSE { New-ItemProperty HKLM:\SOFTWARE\MGH -name "OneHour" -Value "1" }
$MainForm.Close()
}
$buttonRebootNow_Click = {
#TODO: Place custom script here
remove-itemproperty -path HKLM:\Software\MGH -name OneHour
Restart-Computer localhost -Force
$MainForm.Close()
}
$timerUpdate_Tick = {
#Use Get-Date for Time Accuracy
[TimeSpan]$span = $script:StartTime - (Get-Date)
#Update the display
$formSampleTimer.Text = $labelTime.Text = "{0:N0}" -f $span.TotalSeconds
if ($span.TotalSeconds -le 0)
{
$MainForm.Close()
}
}
Re: can't download sample program
You cannot use Start-Sleep in a GUI.
Look closely at the example and read the blog articles on how to use the controls.
YOU have to start simple and learn how to add a timer to a form so it can get events. You cannot just copy and paste code. It has to be hooked up to the controls on the form.
1. place timer on form.
2. set time values
3. create event for the tick by clicking on the time.
4. place code to update screen value with time value on each tick.
Once you can do that you will understand how forms and timers work.
Look closely at the example and read the blog articles on how to use the controls.
YOU have to start simple and learn how to add a timer to a form so it can get events. You cannot just copy and paste code. It has to be hooked up to the controls on the form.
1. place timer on form.
2. set time values
3. create event for the tick by clicking on the time.
4. place code to update screen value with time value on each tick.
Once you can do that you will understand how forms and timers work.
Re: can't download sample program
Question, why can't you put a start-sleep in a form? It seems to work fine. In fact within another form I have this line of code:
if ($GetBootValue1 = '1') { remove-itemproperty -path HKLM:\Software\MGH -name OneHour | start-sleep -s 3600 | shutdown.exe /r /f /t 180 /c "Your computer will be rebooted in 3 minutes as part our MGH computer maintenance process. Please close all open program." }
and it works perfect. It waits and then runs the shutdown.exe
if ($GetBootValue1 = '1') { remove-itemproperty -path HKLM:\Software\MGH -name OneHour | start-sleep -s 3600 | shutdown.exe /r /f /t 180 /c "Your computer will be rebooted in 3 minutes as part our MGH computer maintenance process. Please close all open program." }
and it works perfect. It waits and then runs the shutdown.exe
Re: can't download sample program
I cannot understand why you wanted the sample program when you are just running a simple two line program. You cannot have the user click on anything while the form is "sleeping"
Re: can't download sample program
I have 2 programs.
Program One: has no dialogs. It checks to see if your machine has been up for 7 days. If you have not rebooted in 7 days or more Program Two gets called. Program One will get launched either via Scheduled Task or at Logon Via Group Policies.
Program Two: This has 2 buttons. Delay Reboot for 1 hour & Reboot Now. If this pops up and the user never chooses either button I need the countdown to run for 5 min and then Auto-Reboot the system.
CODE FOR PROGRAM ONE:
function Get-Uptime
{
$o = Get-WmiObject -Class win32_operatingsystem
(Get-Date).date - $o.ConvertToDateTime($o.LastBootUpTime)
}
if ((Get-Uptime).TotalDays -lt 7)
{
cmd.exe /c "\\ServerName\Scripts\Tools\MGHRebootTool\MGHRebootTool.exe"
Start-Sleep -s 10
$GetBootValue1 = (get-ItemProperty hklm:\SOFTWARE\MGH).OneHour
if ($GetBootValue1 = '1') { remove-itemproperty -path HKLM:\Software\MGH -name OneHour | start-sleep -s 3600 | shutdown.exe /r /f /t 180 /c "Your computer will be rebooted in 3 minutes as part our MGH computer maintenance process. Please close all open program." }
}
}
--------------------------------------------------------------
CODE FOR PROGRAM TWO
$OnLoadFormEvent={
#TODO: Initialize Form Controls here
}
$buttonDelayRebootFor1Hour_Click={
#TODO: Place custom script here
$regkeypath = "hklm:\Software\MGH"
$value1 = (Get-ItemProperty $regkeypath).OneHour
If ($value1 -contains '1') { Start-Sleep -m 1 }
ELSE { New-ItemProperty HKLM:\SOFTWARE\MGH -name "OneHour" -Value "1" }
$MainForm.Close()
}
$buttonRebootNow_Click={
#TODO: Place custom script here
remove-itemproperty -path HKLM:\Software\MGH -name OneHour
Restart-Computer localhost -Force
$MainForm.Close()
}
So it is within Program Two that I need the time countdown. And I'm not sure how to add the code yet but that is where I'm at.
I hope this clears things up and sorry for not being clear off the bat.
Program One: has no dialogs. It checks to see if your machine has been up for 7 days. If you have not rebooted in 7 days or more Program Two gets called. Program One will get launched either via Scheduled Task or at Logon Via Group Policies.
Program Two: This has 2 buttons. Delay Reboot for 1 hour & Reboot Now. If this pops up and the user never chooses either button I need the countdown to run for 5 min and then Auto-Reboot the system.
CODE FOR PROGRAM ONE:
function Get-Uptime
{
$o = Get-WmiObject -Class win32_operatingsystem
(Get-Date).date - $o.ConvertToDateTime($o.LastBootUpTime)
}
if ((Get-Uptime).TotalDays -lt 7)
{
cmd.exe /c "\\ServerName\Scripts\Tools\MGHRebootTool\MGHRebootTool.exe"
Start-Sleep -s 10
$GetBootValue1 = (get-ItemProperty hklm:\SOFTWARE\MGH).OneHour
if ($GetBootValue1 = '1') { remove-itemproperty -path HKLM:\Software\MGH -name OneHour | start-sleep -s 3600 | shutdown.exe /r /f /t 180 /c "Your computer will be rebooted in 3 minutes as part our MGH computer maintenance process. Please close all open program." }
}
}
--------------------------------------------------------------
CODE FOR PROGRAM TWO
$OnLoadFormEvent={
#TODO: Initialize Form Controls here
}
$buttonDelayRebootFor1Hour_Click={
#TODO: Place custom script here
$regkeypath = "hklm:\Software\MGH"
$value1 = (Get-ItemProperty $regkeypath).OneHour
If ($value1 -contains '1') { Start-Sleep -m 1 }
ELSE { New-ItemProperty HKLM:\SOFTWARE\MGH -name "OneHour" -Value "1" }
$MainForm.Close()
}
$buttonRebootNow_Click={
#TODO: Place custom script here
remove-itemproperty -path HKLM:\Software\MGH -name OneHour
Restart-Computer localhost -Force
$MainForm.Close()
}
So it is within Program Two that I need the time countdown. And I'm not sure how to add the code yet but that is where I'm at.
I hope this clears things up and sorry for not being clear off the bat.