A Program That Locks Your Files

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
10 posts Page 1 of 1
Contributors
User avatar
3aaBrSbeel
Top Poster
Top Poster
Posts: 139
Joined: Fri Jun 01, 2012 9:34 am

A Program That Locks Your Files
3aaBrSbeel
Okay, in this post I will show you something Useful.
It Locks your Files and It Adds a Padlock Icon to know its locked.

Note: I THINK SOMEONE ALREADY POSTED THIS.
My Finished Program.png
Requirements:
* 2 Buttons
* 1 TextBox
* 1 ProgressBar
* 1 FolderBrowserDialog


Name:
* Button1 - Lock
* Button2 - Unlock


Let's start.

First, Create a New Project "Application Form"

Second, Customize it as you like.

Third, After you finished customizing your form.

-- Let's start Coding --

Right click on the form and Press "View Code"
On the Code Tab. Copy and Paste this Above Public Class Form1.
Code: Select all
Imports System.IO
Imports System.Drawing
Imports System.Windows.Forms
After adding the Codes Given Above. Copy and Paste this Below Public Class Form1.
Code: Select all
Public status As String
    Private arr As String() = New String(5) {}
Now, Go back to Form1 Design and Double Click The Form. Clicking the Form will give you Form1_Load. Add this Code.
Code: Select all
status = ""
        arr(0) = ".{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}"
        arr(1) = ".{21EC2020-3AEA-1069-A2DD-08002B30309D}"
        arr(2) = ".{2559a1f4-21d7-11d4-bdaf-00c04f60b9f0}"
        arr(3) = ".{645FF040-5081-101B-9F08-00AA002F954E}"
        arr(4) = ".{2559a1f1-21d7-11d4-bdaf-00c04f60b9f0}"
        arr(5) = ".{7007ACC7-3202-11D1-AAD2-00805FC1270E}"
Go back again to Form1 Design and Double Click the Lock Button (Button1). And Add this Codes.
Code: Select all
status = arr(0)



        If FolderBrowserDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then



            Dim d As DirectoryInfo = New DirectoryInfo(FolderBrowserDialog1.SelectedPath)

            Dim selectedpath As String = d.Parent.FullName + d.Name

            ProgressBar1.Value = 35

            If FolderBrowserDialog1.SelectedPath.LastIndexOf(".{") = -1 Then



                If (Not d.Root.Equals(d.Parent.FullName)) Then

                    d.MoveTo(d.Parent.FullName & "\" & d.Name & status)

                Else

                    d.MoveTo(d.Parent.FullName + d.Name & status)

                End If

                TextBox1.Text = FolderBrowserDialog1.SelectedPath
                ProgressBar1.Value = 70

                ' PictureBox1.Image = Image.FromFile(Application.StartupPath & "\lock.jpg")
                ProgressBar1.Value = 100
            Else

                status = getstatus(status)



                d.MoveTo(FolderBrowserDialog1.SelectedPath.Substring(0, FolderBrowserDialog1.SelectedPath.LastIndexOf(".")))

                TextBox1.Text = FolderBrowserDialog1.SelectedPath.Substring(0, FolderBrowserDialog1.SelectedPath.LastIndexOf("."))

                ' PictureBox1.Image = Image.FromFile(Application.StartupPath & "\unlock.jpg")



            End If

        End If
Go back again to Form1 Design and Double Click the Unlock Button (Button2). And add this Codes.
Code: Select all
status = arr(1)



        If FolderBrowserDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then



            Dim d As DirectoryInfo = New DirectoryInfo(FolderBrowserDialog1.SelectedPath)

            Dim selectedpath As String = d.Parent.FullName + d.Name



            If FolderBrowserDialog1.SelectedPath.LastIndexOf(".{") = -1 Then



                If (Not d.Root.Equals(d.Parent.FullName)) Then

                    d.MoveTo(d.Parent.FullName & "\" & d.Name & status)

                Else

                    d.MoveTo(d.Parent.FullName + d.Name & status)

                End If

                TextBox1.Text = FolderBrowserDialog1.SelectedPath

                'PictureBox1.Image = Image.FromFile(Application.StartupPath & "\lock.jpg")

            Else

                status = getstatus(status)



                d.MoveTo(FolderBrowserDialog1.SelectedPath.Substring(0, FolderBrowserDialog1.SelectedPath.LastIndexOf(".")))

                TextBox1.Text = FolderBrowserDialog1.SelectedPath.Substring(0, FolderBrowserDialog1.SelectedPath.LastIndexOf("."))

                ' PictureBox1.Image = Image.FromFile(Application.StartupPath & "\unlock.jpg")



            End If

        End If
Now, the last code. Add this Between End Sub and End Class.
Code: Select all
Private Function getstatus(ByVal stat As String) As String

        For i As Integer = 0 To 5

            If stat.LastIndexOf(arr(i)) <> -1 Then

                stat = stat.Substring(stat.LastIndexOf("."))

            End If

        Next i

        Return stat

    End Function
Okay, It's done!

Try and Debug it. It should work.

Note: IF YOUR STILL NOT SURE THAT IT'S NOT SAFE. MAKE A FOLDER AND ADD .TXT AND TRY LOCKING AND UNLOCKING IT.

Peace!
You do not have the required permissions to view the files attached to this post.
Code'n'Stuff Signature Of 3aaBrSbeel
®║▌│█│║▌║││█║▌║▌║▌
✔ Verified Official Code'n'Stuff account ᵀᴴᴱ ᴼᴿᴵᴳᴵᴻᴬᴸ
Image
User avatar
KraZy
Top Poster
Top Poster
Posts: 93
Joined: Sat May 26, 2012 8:40 am

Re: A Program That Locks Your Files
KraZy
How can I achieve the same look that you used on the form? Very nice compliment :) clapper;
I'm in the empire business.
User avatar
3aaBrSbeel
Top Poster
Top Poster
Posts: 139
Joined: Fri Jun 01, 2012 9:34 am

KraZy wrote:
How can I achieve the same look that you used on the form? Very nice compliment :) clapper;
viewtopic.php?f=38&t=2000
Code'n'Stuff Signature Of 3aaBrSbeel
®║▌│█│║▌║││█║▌║▌║▌
✔ Verified Official Code'n'Stuff account ᵀᴴᴱ ᴼᴿᴵᴳᴵᴻᴬᴸ
Image
said17
Just Registered
Just Registered
Posts: 2
Joined: Fri Oct 28, 2011 10:02 am

Re: A Program That Locks Your Files
said17
Dam did something with the program and now lost all folders and almost everything hope i can get it back.
omg;
User avatar
3aaBrSbeel
Top Poster
Top Poster
Posts: 139
Joined: Fri Jun 01, 2012 9:34 am

Try and search the Folders in Run.exe or something
Code'n'Stuff Signature Of 3aaBrSbeel
®║▌│█│║▌║││█║▌║▌║▌
✔ Verified Official Code'n'Stuff account ᵀᴴᴱ ᴼᴿᴵᴳᴵᴻᴬᴸ
Image
User avatar
evil mmm
Just Registered
Just Registered
Posts: 7
Joined: Sat Jul 14, 2012 2:45 am

I really like this program but I am in need of your help. The thing is I somehow need to specify the folder using a variable without actually using the file browser. I mean I will have a predefined folder which should get locked/unlocked. I don't want to allow the user to actually chose the file/folder. Like for example I will have a string variable "path" and it will have the value "C:/Windows/file" and I want the program to work solely on this file no other thanks
User avatar
3aaBrSbeel
Top Poster
Top Poster
Posts: 139
Joined: Fri Jun 01, 2012 9:34 am

evil mmm wrote:
I really like this program but I am in need of your help. The thing is I somehow need to specify the folder using a variable without actually using the file browser. I mean I will have a predefined folder which should get locked/unlocked. I don't want to allow the user to actually chose the file/folder. Like for example I will have a string variable "path" and it will have the value "C:/Windows/file" and I want the program to work solely on this file no other thanks
In my time that would take some work because I'm very busy. What are you saying is "Make a folder somewhere and add the codes to automatically lock/unlock that folder by clicking the buttons?"
Code'n'Stuff Signature Of 3aaBrSbeel
®║▌│█│║▌║││█║▌║▌║▌
✔ Verified Official Code'n'Stuff account ᵀᴴᴱ ᴼᴿᴵᴳᴵᴻᴬᴸ
Image
User avatar
evil mmm
Just Registered
Just Registered
Posts: 7
Joined: Sat Jul 14, 2012 2:45 am

3aaBrSbeel wrote:
evil mmm wrote:
I really like this program but I am in need of your help. The thing is I somehow need to specify the folder using a variable without actually using the file browser. I mean I will have a predefined folder which should get locked/unlocked. I don't want to allow the user to actually chose the file/folder. Like for example I will have a string variable "path" and it will have the value "C:/Windows/file" and I want the program to work solely on this file no other thanks
In my time that would take some work because I'm very busy. What are you saying is "Make a folder somewhere and add the codes to automatically lock/unlock that folder by clicking the buttons?"
Exactly! Thank you for replying waiting for the code wahooo;
User avatar
3aaBrSbeel
Top Poster
Top Poster
Posts: 139
Joined: Fri Jun 01, 2012 9:34 am

Ok, I'll PM you when I have it. :P
Code'n'Stuff Signature Of 3aaBrSbeel
®║▌│█│║▌║││█║▌║▌║▌
✔ Verified Official Code'n'Stuff account ᵀᴴᴱ ᴼᴿᴵᴳᴵᴻᴬᴸ
Image
User avatar
evil mmm
Just Registered
Just Registered
Posts: 7
Joined: Sat Jul 14, 2012 2:45 am

3aaBrSbeel wrote:
Ok, I'll PM you when I have it. :P
I found it out myself thanks for trying to help :)
10 posts Page 1 of 1
Return to “Tutorials”