Reputation: 16228
Motivation: I'm addicted to a particular online game.
Goal: write a program that will impose a daily limit on the time this particular game can be played.
Background: I have never written code for Windows.
My thoughts: Windows certainly has some API for management of software permissions. I need to write a program that runs in background and periodically checks whether the game is played. If it is - sum the total daily time and use Windows API to block the game when the limit was exceeded. Maybe it is even possible to register a listener that will be notified when the game is started, such that there will be no need for periodic polling of game status.
Questions:
Please help me with defining the global arch of such a program and point to the parts of Windows API that might be of interest.
Are there any potential pitfalls that I need to be aware of?
What programming language should I use (can I use any of them or windows API is restricted to certain languages)?
I know that there are many programs that do what I need, but I really want to write this program myself.
Thanks.
Upvotes: 0
Views: 171
Reputation: 6940
Sounds like a job for the PowerShell. Since it's a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. Also it is very easy to manage user permissions.
By the Task Scheduler you'll be able to create such daemon that
runs in background and periodically checks whether the game is played
The simple workflow, can be implemented like this:
For the script design:
#Parameter Set: Name
Get-Process [[-Name] <String[]> ] [-ComputerName <String[]> ] [-FileVersionInfo] [-Module] [ <CommonParameters>]
you can see how here. Then
$file = Get-Content my_time_file.utf8
will keep history for daily time limit. How to read and write files. Aplly some parsing and conditional logic. When time is over - give a warning pop-up and terminate PID in (let's say 5 mins):
[System.Windows.Forms.MessageBox]::Show("You are about the exceed the daily time limit. Please save your game. Game process will be terminated in 5 minutes!")
But after all it's up to you. Very often people who are
addicted to a particular online game
are very resourceful.
Upvotes: 1