Click here to Skip to main content
15,881,380 members
Articles / Programming Languages / C++
Tip/Trick

Windows Permission 1

Rate me:
Please Sign up or sign in to vote.
4.29/5 (4 votes)
15 Dec 2013CPOL6 min read 16.8K   240   8   2
This program protects and locks every window in Windows, and encrypts any files even in large volume without any problem.

Introduction

There are too many security programs that lock, encrypt,... files in different forms, but sometimes working with them is not easy and maybe takes a long time to do this, and also some of them are heavy, slow,... .

I always think that a quick and easy and powerful program needs to do its duty. Therefore I decided to design a program. This program protects and locks every window in Windows, and encrypts any files even in large volume without any problem.

I think it's useful.

Features

  1. Takes little space from RAM and Hard memory
  2. Does quickly just with a few clicks
  3. Doesn't change the file's data
  4. Has good and suitable security
  5. Locks file in every format
  6. Locks every window appears
  7. Includes an explorer with a nice environment
  8. It's like a gadget
  9. Encrypts files with unreturnable algorithm
  10. Can run in XP, Vista and 7 operating systems
  11. Doesn't need external program or library such as .NET Framework
  12. Runs in all users even you will make a user later and it does not exist now, even you install in limited user account
  13. Has a very quick installer

First Main Part - Locking Files

It works a lot quicker because when you lock a file, the program keeps file in open mode and doesn't change the file's data. It's easy and clear. Doesn't allow user open, delete, move, rename, copy and cut the file. Nothing to do, unless you unlock the file. It just works when the program is opened (system loaded). It's not system driver, though user can prefer this, and it's suitable for using. It can be used at home and also at the office.

Second Main Part - Encrypting Files

This program includes two encrypt algorithms, the first one is the common algorithm, the second is the unreturnable algorithm. Even if you're encrypting a large file and cancel it when the program is working, you can decrypt the incomplete file.

Third Main Part - Locking Windows

This part is a very useful and new subject in security and some people need it like myself. Have you ever thought of how you can lock a window. We don't have its execute file? Such as "start menu",  "Action Center", "System Properties", "volume mixer", and important Windows.

Every window you can see it. Too many users worry about it, because it may be a secret and dangerous. So I think it's essential. It's exclusive because it determines the different parts of a program. For example, although there is a difference between "System" and "Windows Update" Windows, they're in a same program ("Explorer.exe") and have the same handle.

But you can manage it and don't worry. I think it's a hot topic, isn't it ?

Source Code

There are three programs in this unit:

  1. Installer program
  2. Main program
  3. Guard program

Installer Program

To run the application, first we need to install essential files or put these files next to program (put to same directory). We do this in the installer .These files are:

"mfc100ud.dll" and "msvcr100d.dll" to "windows\system32" directory<br />"calibri.ttf" to "windows\fonts" directory

Because the installer must be executable, we put these files beside Installer.exe. Then for installing files, we need detect "Windows' Drive". To this, we use the below code and since we need it at the first time, we put this code in OnInitDialog function.
"OnInitDialog" executes every code written in it. So we have:
We define below variables as global.

C++
CString address,pathi,pathw,os,osd;
bool bos=1;
CFile f;
TCHAR tc[260];

BOOL CWindowssPermission1InstalerDlg::OnInitDialog(){
        CDialogEx::OnInitDialog();
    // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE);            // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon

    SetBackgroundColor(RGB(101,158,224));    //Set Background Color
    TCHAR tc[260];GetWindowsDirectory(tc,260);osd=tc;    //Get Windows Directory
    GetCurrentDirectory(260,tc);pathw=tc;    //Get Current Directory

    return TRUE;  // return TRUE  unless you set the focus to a control
}

The next step is determining Operation System, XP or Vista or 7 and push it in "os" and finally in "wu" (windows user folder) file. The main program works with it.

Image 1

For getting a text, we define a class by name "CinputBox" and use it. After that, the program needs a security password to run, to uninstall, and manage the program. We save it to "MicM.dll". And in "MicN.dll", we save "windows user directory" main program uses it. We put these to determine whether the program is installed or not. It's a connection. To have more security, we need to load the program at startup therefore we create a ".reg" file with settings.

Main Program

The cryptography, locking and base application is written in this part. There are multi sections at it. "Explorer" ,"Icon Tray" ,"Lock",.... We have these global variables:

C++
const int filecount=10000,windowcount=10000;
CRect rc[29],r1/*Rect of Window*/,r2/*Rect of Operation System*/;
CPoint p1,pc/*Point of Cursor*/;
CString pathw/*Path of Window*/,pathe/*Path of Explorer*/,
tic/*Type of Central Item*/,til/*Type of Left Item*/
    ,nic/*Name of Center Item*/,nir/*Name of Right Item*/,
    nil/*Name of Left Item*/,tir/*Type of Right Item*/
    ,plf[filecount]/*Passwords of Files*/,
    pplf[filecount]/*Paths of Files*/,wl[windowcount][2]/*Window Lock*/
    ,pfc/*Path of File Copy/Cut*/,os;
int cc=0/*Stop OnPaint*/,c/*List Count*/,b=-1/*Button Press*/,
w=112/*Window Width*/,h=211/*Window Height*/,ow=150/*Opacity Window Timer*/
    ,dx1=-8,dy1=-93,xw=0,yw=0,ifc=0/*Index of Center Item*/,
    tf[filecount][2],tw[windowcount]/*ask for passwoord*/,lcfu=0,ccf=0/*Copy=0,Cut=1*/
    ,locktime=0;
bool s1=1/*Start Opacity*/,s2=0/*Status of Window*/,active=1;
CImage i1/*Back Ground 1*/,il/*Left Item*/,ic/*Central Item*/,ir/*Right Item*/;
COLORREF cl=RGB(0,162,232);
CFile lf[filecount]/*Lock Files*/,fq,fz;
HWND hd=0;

Image 2

Some tasks are checking in OnInitDialog function such as:

  1. Is the program loaded? Then exit.
  2. Is the program uninstalled or damaged? Then exit.
  3. Load program's directory.
  4. Load program's coordinates from xw and yw included X and Y of application in screen.
  5. Load Windows Passwords and their names from qw file.
  6. Load files Passwords and their names from zw file.
  7. Load automatically Lock Time from tw file.
  8. Load windows user directory from wu file.
  9. Start Guard program.
  10. Load icon tray.

And in the OnTrayNotify, we manage icon tray and menu.

Image 3

We design and load background and explorer appearance in the Onpaint. Operation system calls this function when the application needs to redraw .

OnTimer is the most important function. The locking and cryptographing and moving window ,... written in here. Operation system calls "OnTimer" automatically with specific interval . By the way, I didn't use any buttons in dialog. I think this method is better because it has more quality and less space in RAM. Of course, today it doesn't matter. And also, we can design everything in our mind. Well, I defined rectangles for every button.

IsNear is a function checks that is a point in a rectangle or not. In the OnMouseMove if cursor in one of the rectangles, we put a relation number in a global variable, then in the OnLButtonDown runs relation code.

C++
GetCursorPos(&pc);//get current coordinates of cursor and put in "pc"(pointer cusrsor)
if(IsNear(pc.x,pc.y,r1,50)){
    int x=0,y=0;x=pc.x-r1.left-dx1;y=pc.y-r1.top-dy1;
    if(ow<255&&s1){SetTimer(3,10,0);s1=0;}        //Start Opacity Window 255
    if(IsNearX(x,y,rc[0],1))b=0;            //Computer
    else if(IsNearX(x,y,rc[1],1))b=1;        //Desktop
    else if(IsNearX(x,y,rc[2],1))b=2;        //My Documents
    else if(IsNearX(x,y,rc[3],1))b=3;        //My Videos
    else if(IsNearX(x,y,rc[4],1))b=4;        //My Music
    else if(IsNearX(x,y,rc[5],1))b=5;        //My Pictures
    else if(IsNearX(x,y,rc[6],1))b=6;        //My Favorites
    else if(IsNearX(x,y,rc[7],1))b=7;        //Links
    else if(IsNearX(x,y,rc[8],1))b=8;        //microsoft.com
    else if(IsNearX(x,y,rc[9],1))b=9;        //linux.com
    else if(IsNearX(x,y,rc[10],1))b=10;        //google.com
    else if(IsNearX(x,y,rc[11],1))b=11;        //Close
    else if(IsNearX(x,y,rc[12],1))b=12;        //Minimize
    else if(IsNearX(x,y,rc[16],1))b=16;        //Make Folder
    else if(IsNearX(x,y,rc[17],1))b=17;        //Lock
    else if(IsNearX(x,y,rc[18],1))b=18;        //UnLock
    else if(IsNearX(x,y,rc[19],1))b=19;        //Copy
    else if(IsNearX(x,y,rc[20],1))b=20;        //Cut
    else if(IsNearX(x,y,rc[21],1))b=21;        //Past
    else if(IsNearX(x,y,rc[22],1))b=22;        //Delete
    else if(IsNearX(x,y,rc[23],1))b=23;        //Rename
    else if(IsNearX(x,y,rc[25],1))b=25;        //Back
    else if(IsNearX(x,y,rc[26],1)&&!s2)b=26;    //UnLock Out
    else if(IsNearX(x,y,rc[27],1)&&!s2)b=27;    //Lock Out
    else if(IsNearX(x,y,rc[28],1))b=28;        //Option
    else {b=-1;}

Image 4

LoadToTray function sets the icon on the taskbar to use menu. Encrypt and decrypt codes are here:

C++
inline CString encrypt(CString str){
CString s1(_T(""));USES_CONVERSION;unsigned char c1=0;char *c=0;
for(register int i=str.GetLength()-1;i>=0;i--){
    c1=0;c=0;c=T2A(str.Mid(i,1).GetBuffer());
    c1=*c;unsigned char i1=((int)c1),i2,i3,i4;int i5;i2=i3=i4=i5=i1;
    i2*=2;i2/=128;i2=!i2;i2*=64;/*7th bit*/i3/=128;
    i3*=128;/*8th bit*/i4*=4;i4/=4;/*(1-6)th bit*/
    i5=255-(i2+i3+i4)+1;s1+=((char)i5);
}
return s1;
}

Cryptography

The encrypt text i applied is :

C++
inline CString encrypt(CString str){
CString s1(_T(""));USES_CONVERSION;unsigned char c1=0;char *c=0;
for(register int i=str.GetLength()-1;i>=0;i--){
    c1=0;c=0;c=T2A(str.Mid(i,1).GetBuffer());c1=*c;
    unsigned char i1=((int)c1),i2,i3,i4;int i5;i2=i3=i4=i5=i1;
    i2*=2;i2/=128;i2=!i2;i2*=64;/*7th bit*/i3/=128;
    i3*=128;/*8th bit*/i4*=4;i4/=4;/*(1-6)th bit*/
    i5=255-(i2+i3+i4)+1;s1+=((char)i5);
}
return s1;
}

And decrypt:

C++
CString dec(CString str){
CString s1(_T(""));USES_CONVERSION;unsigned char c1=0;char *c=0;
for(register int i=str.GetLength()-1;i>=0;i--){
    c1=0;c=0;c=T2A(str.Mid(i,1).GetBuffer());c1=*c;
    unsigned char i1=255-((int)c1)+1,i2,i3,i4,i5;i2=i3=i4=i5=i1;
    i2*=2;i2/=128;i2=!i2;i2*=64;i3/=128;i3*=128;i4*=4;i4/=4;
    i5=i2+i3+i4;s1+=i5;
}
return s1;
}

Guard Program

This part just has one duty; if the main program closed opens it. Find function finds the maint program' handle and by "IsWindow" we check it is or not. In the below code:

C++
if(!Find()){
    ShellExecute(0,0,pathw+_T("\\Windows's Permission 1.exe"),0,0,1);
}

Techniques

About the security, I should say that I used a technique like Nod32. The program is made up of two programs. First main program, second guard program. They care about each other. If one of the programs will be closed, the other one executes that. It keeps files in read mode and doesn't close them to lock them. When you unlocked a file or window and forgot it (lock that), the Automatically Locking will be activated and locks that or after you close them.

C++
//Load automatically Lock Time
if(fd.Open(pathw+_T("\\Data\\tw"),CFile::modeRead)){
    fd.Read(&gf[0],fd.GetLength());
    locktime=atoi(gf);    //set lock time automatically
    for(ie=0;ie<1000000;ie++)
        gf[ie]=0;
    fd.Close();
}
//Load os
if(fd.Open(pathw+_T("\\Data\\wu"),CFile::modeRead)){
    fd.Read(&gf[0],fd.GetLength());
    os=gf;
    for(ie=0;ie<1000000;ie++)
        gf[ie]=0;
    fd.Close();
}

Image 5

Limitation

Unfortunately, this program and algorithm have a defect. Of course, avowal is good.

  • It's not system driver. It means if you turn off the system or remove hard disk the files and windows will be opened and be released. It's suitable for laptops, home PCs, every computer always is on such as telecommunication' computers, and even coffee nets.
  • And this cryptography algorithm isn't powerful.

Explaining Code

It can help some of people who want to lock/unlock very quickly or deny access to special window, of course not in High security like a big company, but we can improve it. By the way when you want to install the program, you must register a security password to uninstall and disable program and also to open "Windows Task Manager". I didn't explain codes in this page completely but I did it in code. They're easy to understand. I hope it will be useful for using.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Iran (Islamic Republic of) Iran (Islamic Republic of)
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 1 Pin
Yaroslav Lobachevski14-Dec-13 14:29
Yaroslav Lobachevski14-Dec-13 14:29 
QuestionHow to unlock a file.... Pin
DaveAuld12-Dec-13 20:38
professionalDaveAuld12-Dec-13 20:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.