Hello
I developed an application in PowerShell with windows Forms.
I would like to make a condition for the executable to expire on the date I determine.
I made this condition in another application that I developed in VB.NET, but I didn't find how to do it in power shell
in VB it looked like this:
Dim dt1 = DateTime.Now
Dim dt2 = DateTime.Parse("30/09/2019")
If dt1 >= dt2 Then
MsgBox("Expired Date - Please Contact Administrator")
Application.Exit()
End If
Does anyone know how I do this in powerShell? no need to have msgbox, just want the program not to run, not open, do nothing when it arrives on the set date
Thank you very much in advance.
PowerShell - Expirate the 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: PowerShell - Expirate the Program
help Get-Date -online
or
[datetime]::ParseExact('30/09/2019','dd/MM/yyyy',$null)
For a message box use the Microsoft.VisualBasic namespace to access the MsgBox.
[Microsoft.VisualBasic.Interaction]::MsgBox( " my message" )
or
[datetime]::ParseExact('30/09/2019','dd/MM/yyyy',$null)
For a message box use the Microsoft.VisualBasic namespace to access the MsgBox.
[Microsoft.VisualBasic.Interaction]::MsgBox( " my message" )
Re: PowerShell - Expirate the Program
Example Project Attached,
Super simple addition to your code required... I also have a more advanced version
Where you can use the creation date (signing time stamp) +x days,
So each build expires after a defined period of time...
Super simple addition to your code required... I also have a more advanced version
Where you can use the creation date (signing time stamp) +x days,
So each build expires after a defined period of time...
- [System.IO.FileInfo]$Filename = $($hostinvocation.MyCommand.path)
- #region Add this Region to Expire
- ##Needs to either be added above Main, or in a seperate file
- $DTCurrent = get-date
- $DTExpiry = [datetime]::new(2019, 10, 30)
- if ($DTCurrent -gt $DTExpiry)
- {
- Write-Host "Thats all folks, $($Filename.Name) is expired"
- break
- }
- else
- {
- Write-Host "Keep Running: $($Filename.Name)"
- }
- #endregion Add this Region to Expire
- Attachments
-
- Test-AppRun.zip
- (1.71 KiB) Downloaded 159 times
Re: PowerShell - Expirate the Program
Do not use break in this way as it can create unexpected issues. An if/else filter never requ9ies a break.Nillth wrote: ↑Tue Oct 08, 2019 3:42 pm Example Project Attached,
Super simple addition to your code required... I also have a more advanced version
Where you can use the creation date (signing time stamp) +x days,
So each build expires after a defined period of time...
[System.IO.FileInfo]$Filename = $($hostinvocation.MyCommand.path) #region Add this Region to Expire ##Needs to either be added above Main, or in a seperate file $DTCurrent = get-date $DTExpiry = [datetime]::new(2019, 10, 30) if ($DTCurrent -gt $DTExpiry) { Write-Host "Thats all folks, $($Filename.Name) is expired" break } else { Write-Host "Keep Running: $($Filename.Name)" } #endregion Add this Region to Expire
"[codebox}" is not correct and will do nothing.. Use "
Code: Select all
" to post code.
Re: PowerShell - Expirate the Program
it worked with the code below
$DTCurrent = get-date
$DTExpiry = [datetime]::ParseExact('30/11/2019','dd/MM/yyyy',$null)
if ($DTCurrent -gt $DTExpiry)
{
Write-Host "Thats all folks, $($Filename.Name) is expired"
break
}
else
{
Write-Host "Keep Running: $($Filename.Name)"
}
Thank you all
$DTCurrent = get-date
$DTExpiry = [datetime]::ParseExact('30/11/2019','dd/MM/yyyy',$null)
if ($DTCurrent -gt $DTExpiry)
{
Write-Host "Thats all folks, $($Filename.Name) is expired"
break
}
else
{
Write-Host "Keep Running: $($Filename.Name)"
}
Thank you all