Hey everyone,

So recently my sister got herself her own laptop (okay it's been a year or so). Anyway, she's been getting horrible at staying up super late messing around on it. Well I decided I'd help my parents out and write a program to control her laptop a little.

One of the features I want to do is control when an application can run (such as Skype). So I plan to add a time stamp feature of when an application can run. So if the time passes, the application will be closed. Now I want to find a way to prevent it from being re-opened. I could do a constantly like while loop that is checking ever so often, but I am wondering if there's some better way to do this.

(Also a bonus, timers I know can trigger events, so I was wondering, is there a way to have an event trigger when a certain time is reached? I know I could set up a timer by creating a TimeSpan between the current time and end time, but I worry a problem could arise with this).

Thanks as always

Recommended Answers

All 13 Replies

I think you need just something like this

 while(DateTime.Today.Hour<8){
                    Process[] p = Process.GetProcessesByName("process");
                    foreach(Process r in p) if(r.Responding) r.CloseMainWindow();
                }

Cool, I'll give that a try and get back to you (when I get time to work on this code)

Well that mixed in with another article I found, this appears to be what I am looking for, thanks

You could use this for the monitoring of an application rebooting after being shutdown to intercept and block it / trigger another close down.

The downside to the approach you are taking is that if your sister has any real knowledge she could just kill this program you write off through task manager (running applications or processes) and bypass it. Or make a second user account which it wouldn't be installed on by default.

Yeah she's not to wise. However i think I found a way to hide it from the Application tab, and am going to name the program something technical so it's hard to find in the Process tab (if she ever gets that far).

I have run into another problem. Right she could for instance rename "Skype.exe" to "Skype2.exe" and my program would miss it for how I want to do it (I am trying to see if Win32_Process has a way to prevent this).

Also, don't want her to try changing the system time, so DateTime can't be trusted meaning I need online clocks, but having issues with getting times from pool.ntp.org

Try this

int ProcessID = Convert.ToInt32(((ManagementBaseObject)e.NewEvent.Properties["TargetInstance"].Value)["ProcessID"]);
Process process = Process.GetProcessById(ProcessID);
Console.WriteLine(" Process Description : "+process.MainModule.FileVersionInfo.FileDescription);

I've tested it before and it seems to work fine. Maybe you can find an easier way

What problems are you experiencing with pool.ntp.org?

You could put her in a custom usergroup and disable the ability to edit system time, to resolve that issue.

Else she could easily use offline programs after hours by just shutting off the internet and stopping your programs ability to update its time

@Fenrir()

I am thinking of doing the description, as that would be a lot harder to disable. I'll have to find a way to retrieve it initally for when the user sets up the permissions, but that shouldn't be an issue. As for ProcessID, I won't use that, because process ID numbers aren't constant.

@MikeyIsMe

Yep, I was thinking of that. The thing is, pretty much what I am trying to control on her laptop, all involves internet access (mostly skype and surfing the web or like youtube)

This is probably what you are after then :)

Yeah I saw that page, was going to come back to it (that 2nd solution doesn't work, already tried it)

It doesn't matter what the process ID is in the above mentioned code. seeing as if a process is invoked the description of said process would still be skype and you'll check for that and block it.

I actually just checked that last night.

Description and Name will display the .exe's name. If it's like a shortcut on the desktop and they try to change the .exe's name, it won't effect it. However, if they alter the main .exe in the install location, then the name and description will be effected, except, then the CommandLine will not be empty (it will display the path to the .exe, it will have the name change, but the same path).

My goal is to use these two in unison, if the CommandLine is empty, then fallback to the Name

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.