I made this project because my friends wanted creepy software like this one. In this project I have created not a file locker but a user friendly file attributes changer. I have used two cmd commands.
Command 1 : To hide or unhide
ATTRIB [+A | -A ] [+S | -S] [+H | -H] [[drive:] [path] filename] [/S [/D]]
+ |
Sets an attribute. |
- |
Clears an attribute. |
R |
Read-only file attribute. |
A |
Archive file attribute. |
S |
System file attribute. |
H |
Hidden file attribute. |
/S |
Processes files in all directories in the specified path. |
/D |
Process folders as well. |
Command 2 : To change the security access
ICACLS (don't know the full-form)
Code icacls "path/file.ext" /t /deny or grant username : (f)
/T Traverse all subfolders to match files/directories
(f) full control
/deny the user particular rights
Name = demo
Password = pass
Always run as administrator and it always will be.
Caution Warning
- I cannot guarantee a robust application but I have tried and tested it many time in Windows 7.
- Recovery key is the file version 51350.73.4970.938 with dash 51350-73-4970-938
- Last but not the least I cannot be held responsible for any loss of data/monetary.
- The best way is for you try it first on a demo file.
- If you trust it then try it on main stuff.
- I trust your intellectual capabilities and because of that you can overcome any problem.
Troubleshooting
- If anything went wrong run these code in run window
- Including double quotes and *.* for all file and folder
- Attrib /s /d -h -s "C:/path/*.*"
- icacls "C:/path/*.*" /t /grant everyone:f
- Access denied means you don't have rights to change the attributes; first unblock it.
- Drawbacks are that you can enter only one file name in the file name box.
Example : my.mp3 (correct)
Example : my.mp3,you.mp3,all.docx (wrong)
Read The Read me file properly
Ok that was the basic info needed to start. We will require three forms.
Application flow diagram
Login->username & pass or recovery->Main page->if recovery was used->recovery window.
Main page
browsertextbox = readonly
filenametxtbox = nochanges
richtextbox=readonly
filebrowersdialog
statustrip=nochanges
4 buttons = nochanges
Code()
using System.IO;
namespace Locker
{
public partial class mainpg : Form
{
public mainpg()
{
InitializeComponent();
}
//some variable we will need path and file
string path, file;
// the variable which will tell that the recovery is used
Login l1 = new Login();
//the imp method which will do all the work
//parameter command and diretor (used for directory list just to diffrentiate the commands)
//1 for directory list and 0 for other methods
public void cmdproc(string cmd, int dir)
{
//which process tho start with which command
Process.Start("CMD.exe", cmd);
//just to hide the black window and get any errors from the cmd.exe
Process proc = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.RedirectStandardOutput = true;
info.CreateNoWindow = true;
info.UseShellExecute = false;
info.FileName = "cmd.exe";
info.Arguments = cmd;
proc.StartInfo = info;
//now the process starts
proc.Start();
//dir is used to diffrentiate the message which is going to be displayed
if (dir == 1)
{
//this will read the output from start to end
string res = proc.StandardOutput.ReadToEnd();
richTextBox1.Text = res;
}
//any other case
else if (dir == 0)
{
//this will read only the first line of the output
//basically display any error or info of procesing
string result = proc.StandardOutput.ReadLine();
//if the output contains an error or info
if (result != null)
{
//if the string the word denied than the string also contain trouble shooting it
if (result.Contains("denied"))
{
result += " First Unblock It";
}
//finally display it
too1.Text = result;
}
//if there is no error then simply show done
else
{
too1.Text = "Done";
}
}
}
private void button1_Click(object sender, EventArgs e)
{
//browse
if (flbrowse.ShowDialog() == DialogResult.OK)
{
//assign the path
path = flbrowse.SelectedPath;
pat.Text = path;
//create comand to display the file in the path
//simple dir command of cmd
// /c dir "C:/bla/bla/bla" /a /b"
// /a will display all the hidden files
// /b display only the name
// 1 will change the outputshowed
cmdproc("/c dir " + "\"" + path + "\"" + " /a /b", 1);
}
}
private void button2_Click(object sender, EventArgs e)
{
//if all the inputs are provided
if (valid() == true)
{
//attrib command to change the visibilty of the file
// /c will tell the cmd to exit as soon as the command is exicuted
// -s remove system file property
// -h remove the hidden attribute
// /s /d will include all the file and folder if *.* is selected
cmdproc("/c attrib /s /d -s -h \"" + path + "\\" + file + "\"", 0);
}
}
private void button3_Click(object sender, EventArgs e)
{
//if all the inputs are provided
if (valid() == true)
{
//attrib command to change the visibilty of the file
// /c will tell the cmd to exit as soon as the command is exicuted
// +s add system file property
// +h add the hidden attribute
// /s /d will include all the file and folder if *.* is selected
cmdproc("/c attrib /s /d +s +h \"" + path + "\\" + file + "\"", 0);
}
}
private void button4_Click(object sender, EventArgs e)
{
//if all the inputs are provided
if (valid() == true)
{
//icacls command to change the security of the file
// /t means all the file and folder inside the folder
// /deny everyone:(f) deny everyone (f) fullcontrol of the file
cmdproc("/c icacls \"" + path + "\\" + file + "\"" + " /t /deny everyone:(f)", 0);
}
}
private void button5_Click(object sender, EventArgs e)
{
//if all the inputs are provided
if (valid() == true)
{
//icacls command to change the security of the file
// /t means all the file and folder inside the folder
// /grant everyone:(f) grant everyone (f) fullcontrol of the file
cmdproc("/c icacls \"" + path + "\\" + file + "\"" + " /t /grant everyone:(f)", 0);
}
}
public bool valid()
{
//clear any error
errors.Clear();
bool valid = false;
//path and file name is provided or not
if (flbrowse.SelectedPath != "" && filena.Text != "")
{
valid = true;
file = filena.Text;
}
//re assigning the values of file
if (filena.Text == "")
{
errors.SetError(filena, "Provide Input");
file = "";
}
//re assigning the values of path
if (flbrowse.SelectedPath == "")
{
errors.SetError(pat, "Provide Input");
path = "";
}
return valid;
}
private void toolStripStatusLabel1_Click(object sender, EventArgs e)
{
//show recovery window when pass and nam is clicked
Recovery r1 = new Recovery();
r1.ShowDialog();
}
private void Form1_Load(object sender, EventArgs e)
{
l1.ShowDialog();
//check if recovery was used
//than the show name and pass should be visible
if (l1.rec == 1)
{
namnpass.Visible = true;
}
}
private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
{
//userfriendly ness copy n paste
richTextBox1.Copy();
//clear the field before pasting
//limitation only one name at a time
filena.Text = "";
filena.Paste();
}
}
Login (optional)
namespace Locker
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
//number of retries
int count = 0;
public int rec;
// mainpg f1 = new mainpg();
private void button1_Click(object sender, EventArgs e)
{
logic();
}
//user name and password validator method
public void logic()
{
//if valid is true
if (valid())
{
//maximum retry is 6
if (count < 6)
{
//username and password checking
if (textBox1.Text == "demo" && textBox2.Text == "pass")
{
this.Hide();
//this.Close();
}
//if the recovery key is not empty
else if (textBox3.Text != "")
{
//checks the key
if (textBox3.Text == "51350-73-4970-938")
{
//rec variable is 1 because this is tell the app that the recovery is used
rec = 1;
//trying to store the value of rec in other form which will really use it
//hide this form and show the main form
//f1.Show();
this.Hide();
//this.Close();
}
else
{
//error if the key does not match
errorProvider1.Clear();
errorProvider1.SetError(textBox3, "Input in this format 00000-00-0000-000");
MessageBox.Show("Attempts Left " + (6 - count), "Access Denied", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
}
else
{
//message if the name and pass does not match
MessageBox.Show("Attempts Left " + (6 - count), "Access Denied", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
}
else
{
//if the retry is over
MessageBox.Show("This Was Your Last Attempt Bye Bye", "Access Denied", MessageBoxButtons.OK, MessageBoxIcon.Stop);
Application.Exit();
}
//increment retry
count++;
}
}
//checks if any required field is empty??
public bool valid()
{
errorProvider1.Clear();
bool val = true;
if (textBox1.Text == "")
{
errorProvider1.SetError(textBox1, "Provide Input");
val = false;
}
if (textBox2.Text == "")
{
errorProvider1.SetError(textBox2, "Provide Input");
val = false;
}
if (textBox3.Text != "")
{
val = true;
}
return val;
}
//just to avoid use of mouse enter key to login
private void Login_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
logic();
}
}
private void Login_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
}
}
Recovery (optional)
Timer=1000 interval
A Dialogue box of the main page is available when the user has entered the recovery key during login.
A valid recovery key will show the name and password.
Code()
namespace Locker
{
public partial class Recovery : Form
{
public Recovery()
{
InitializeComponent();
}
int i = 1;
private void button1_Click(object sender, EventArgs e)
{
if (textBox3.Text == "51350-73-4970-938")
{
label1.Visible = label2.Visible = true;
timer1.Enabled = true;
}
else
{
MessageBox.Show("Key Does not Match");
}
}
private void timer1_Tick(object sender, EventArgs e)
{
i++;
if (i == 10)
{
textBox3.Text = "";
label1.Visible = label2.Visible = false;
}
}
}
}