I've been looking during 2 days for a sotfware which allows me to limit the time I play(or use any program) and I found nothing usefull so I decided to put my coding cape back since 6 years ago and program it myself.
A friend recommended me powershell as the easiest and faster way to do it. I have no idea of powershell but I've come to this: With
gps | ? { $_.MainWindowTitle }
I check the running processes . Then with an if clause I would define if the game is being runned, if it is being runned I use
$StartTime = Get-Process processOfTheGame | select starttime
to know when the game started. And then I should use another if clause to compare it with actual date
Get-Date
but im finding problems to compare it as Get-Process processOfTheGame | select starttime data type is PSCustomObject so it is throwing me errors when I try to change the format to datetype.
So i need help to convert the $StartTime variable to datetype and then to compare it with the actual date. and if the actual date is 2 houres more than $StartTime close the program with
Stop-process -name GAME
Things i've tried
$testConversion = [datetime]::ParseExact($StartTime, 'dd/MM/yyyy' ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
[datetime]::parseexact($StartTime, 'dd-MMM-yy', $null)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
$Date = get-date $StartTime -Format "dd-MM-yyyy"
+ ~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-Date], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCommand
PS> $Obj = ((get-date "10/22/2020 12:51:1") - (get-date "10/22/2020 12:20:1 "))
I tried it with a "flat" date cause it is supposed to work that way but it does not. It neither works with the variable StartTime
PS> $Obj = ((get-date "10/22/2020 12:51:1") - (get-date "10/2 ...
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-Date], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCommand