# limiting acess to programs

This topic is 4854 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I want to write a program to limit how much people can use msn per day.(I have a very sad sister) I think the best way is to make a prog called msn which loads up msn if it has not been used for over a certain number of hours a day. I need however to know how to prevent acess to the original msn programme, without it affecting the program. I also need to kmow how to open a program using code. I hope that makes sence. I would greatly apreciate some ideas.

##### Share on other sites
Well, I don't think you should bother yourself with your sister and her MSN habits, those things are up to your parents. If you think she has an MSN problem, talk to her and your parents, and don't work out a "solution" behind their back. In fact, you probably end up getting suspend (from the computer).

If you are persistant and are going to write the app, the only solution is to write an application that enumerates all running processes every 15 seconds and checks if certain applications are present. When these applications are running, you just terminate them.

Toolmaker

##### Share on other sites
my mum wants me to do something. She is on it for about 8 hours on a school day. 15 on a weekend. every day. She won't listin to me or any one.

That idea is pretty good. Thanks, I will look it up on msdn.

##### Share on other sites
Well, isn't your mom suppose to "enforce" her disissions(Like either taking away the keyboard or the entire computer)?

I'm not sure which Windows version you are using and if you have several user names.

If you're running Windows 2000 or XP, just disable her username OR change her password to something only you know.

Another solution would be(Only works if your file system is NTFS) is to change the permissions on the MSN folder for her user account to Deny(Deny overrules allow). However, this solution isn't waterthight since there are several webversion avaliable for MSN.

A last option I can think of is to install ZoneAlarm and disallow MSN to access the web. The workaround ofcourse is to disable ZoneAlarm.

As a last resort, you could write such an application, but the other solutions are much faster and easier to use. Also, if your sister finds out about your application, she might just disable/kill it. Or, write your own background running port blocker which only blocks the MSN ports(Which are documented somewhere).

Plenty solutions around!

Toolmaker

##### Share on other sites
I only wont to limit her usaage, not completly ban it.

I have tried to research how to get a list of processes but, I can't find any examples.

##### Share on other sites
Easily done in Visual Basic.

##### Share on other sites
Quote:
 Original post by crazy_andyShe is on it for about 8 hours on a school day. 15 on a weekend. every day.

...Sounds like me... (cept i'm a guy, who programs and learns)
[smile]

##### Share on other sites
I spend that much and more on my laptoop programming. But she doesn't know when to stop. I would like to use c++ as I am getting quite good at it know. IF any one knows any helpfull links, please post them.

##### Share on other sites
Just steal the power cord for a couple weeks. You will have to live without the computer but after a couple weeks she wont have the urge to go on it anymore.

##### Share on other sites
Hmmm. Well I don't know how much your sister knows. But for my brother, i setup a transperant squid proxy that had time limits on it. If you have any spare machine laying around, you could probably do this.

As for programming. GL. Sounds like an interesting project.

##### Share on other sites
Might be even easier to set up your firewall to block the msn ports at certain times of the day so it won't connect, but really, your parents should try being actual parents and do something about it. Transparently blocking it is not the way to do it. If they lay down rules saying no computer/internet after x oclock, and enforce those rules it will be better for everyone.

When I was young my dad would take the modem cord from my computer if I was ever on it past when I should have. What ever happened to decent parenting, nowadays the mall and movie theatre are the baby sitters.

##### Share on other sites
GotenRulezU - when we had dial up we banned her from msn for a week(after she was on for about 7 hours 1 day) When we got broadband she was hyper. stealing the power cord, will make her more addicted.

Ace826 - my sister is a retard. but I don't have a spare computer though. "sounds like a good prooject." I agree, always good experiance.

DrEvil - I don't really want to limit the time of day, but I could probably do it. I wish my mum would try harder, but my sister is that sort of age and hates everybody.

Still havn't found anything yet. It can't be that hard o monitor the processes. Loads of progs do it. Ad-aware for one

##### Share on other sites
I found I site that deals with this. www.codeguru.com

I have go a basic prog working in a console application, it uses the system namespace. What I need to do is to get it working without a window.

##### Share on other sites
If would be nice if you showed me some code(On how to get the processlist that is).

Next, make it a Win32 application that runs without a window(Just create the window, but ShowWindow(SW_HIDE); after creating it. This will prevent her from closing since it will not even show up on the taskbar.

Next step is to set up a WM_TIMER event that fires every 5 or 10 seconds. When you receive the WM_TIMER, grab the active process list, check for "msnmsgr.exe" and when found, kill it.

A next step in the process is to add a config file which you store somewhere in the windows directory with the "allow times". For instance, 16:00 to 19:00 is MSN time.

After this, your application is sorta ready for a simple beta test. Install it, add it to the startup folder or add it as a system service.

As a last step, you can add a little GUI to it to edit the times on which MSN is allowed and when not(Or something along those lines). When you decide to do this, make sure you allow application to run only ONCE(In this case, make it a System Service) with a bunch of parameters. When started with block.exe -gui it shows a password box in which you need to enter the password to gain access. And ofcourse:
-start
-restart
-stop
-install
-uninstall

Store the password as an MD5 hash in the file and you got yourself a nice little MSN blocker application. Ofcourse, you could even expand this further and make the list of blocked applications variable.

Toolmaker

##### Share on other sites
Ok here is my code:

// This is the main project file for VC++ application project
// generated using an Application Wizard.

#include "stdafx.h"
#include <windows.h>

#using <mscorlib.dll>

using namespace System;

int _tmain()
{
Diagnostics::Process *p[]=Diagnostics::Process::GetProcessesByName("msnmsgr");
// this gets the process details for msnmsgr.
// to get all processes use
// Diagnostics::Process *p[]=Diagnostics::Process::GetProcesses();

Console::WriteLine("Found: ");
Console::WriteLine(p->get_Length());

for (int i = 0; i<p->get_Length();i++)
{
Console::WriteLine(p->ProcessName);
Console::WriteLine("Terminating...");
HANDLE h = OpenProcess(PROCESS_ALL_ACCESS,true,p->get_Id());
//this gets a handle to the process

if (TerminateProcess(h,1)) // terminates process
{
Console::WriteLine("terminated");
}
else
{
Console::WriteLine("error");
}

}

return 0;
}

This works fine on my laptop, but not on any other pc so far. I think it may be a problem with the system files or something. Everyone else gets a "application error"

##### Share on other sites
No, it's because it's managed C++. That code requires the .NET framework to be installed on the computers. Convert the code to unmanaged C++(Ditch mscoree.dll for instance) and try using the regular Win32 API.

I'll try to have a little peak tomorrow, if I got the time. I'm off to bedski now.

Toolmaker

##### Share on other sites
Yeah, I assumed it might be the .net framework. I am not to sure about the managed/unmanaged part of it. If you could show me roughly how to do it, i wud work it out from there. If I can't do it, I can just install .net framework on the relevant pc. and not make it for anyone else. just for the function i want.

##### Share on other sites
ok got .net framework and it works. What is the differenace between managed and not?
other than garbage collection

##### Share on other sites
Quote:
 Original post by crazy_andyok got .net framework and it works. What is the differenace between managed and not?other than garbage collection

The syntax and the library they use.

##### Share on other sites
I wrote a very simple processlist viewer in normal C++ using the Win32 API. It's easier to understand than the managed code and you can easily turn this into an std::list of std::string's. Iterating though the list will be easy.

This is the code:
#include <windows.h>#include <tlhelp32.h>#include <iostream>#include <conio.h>using namespace std;int main(){    HANDLE hSnapshot;    PROCESSENTRY32 ProcessEntry;    // Get system snapshot before we can walk over all the processes    hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);    if (hSnapshot == INVALID_HANDLE_VALUE)    {        cout << "Invalid snapshot handle!" << endl;        return (0);    }    ZeroMemory(&ProcessEntry, sizeof(PROCESSENTRY32));    ProcessEntry.dwSize = sizeof(PROCESSENTRY32);    // grab the first process    if (!Process32First(hSnapshot, &ProcessEntry))    {        CloseHandle(hSnapshot);        cout << "Failed to get first process" << endl;        return (0);    }    // Display process information    do    {        cout << "Process name: " << ProcessEntry.szExeFile << endl;    } while(Process32Next(hSnapshot, &ProcessEntry));    CloseHandle(hSnapshot);    cout << "Done!" << endl;    getch();    return (0);}

If you need help, you know where to find the PM button.

Toolmaker

##### Share on other sites
cheers, I will look thru the code tonight. and see what I can do