폴더 잠금,풀기 프로그램 만들기
*
Imports System.IO
Imports System.Drawing
Imports System.Windows.Forms

Public Class Form1
Public status As String
Private arr As String() = New String(5) {}

Private Sub Folder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
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}"
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
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 = 40

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 = 75
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("."))

End If
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
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

ProgressBar1.Value = 40
ProgressBar1.Value = 100

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

TextBox2.Text = FolderBrowserDialog1.SelectedPath
ProgressBar1.Value = 100
ProgressBar1.Value = 100
Else
status = getstatus(status)
d.MoveTo(FolderBrowserDialog1.SelectedPath.Substring(0, FolderBrowserDialog1.SelectedPath.LastIndexOf(".")))
TextBox2.Text = FolderBrowserDialog1.SelectedPath.Substring(0, FolderBrowserDialog1.SelectedPath.LastIndexOf("."))
End If
End If
End Sub

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

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
End Class



* 폴더를 잠그고 풀수 있는 프로그램 코드 이다

* 폴더 잠금 원리를 찾아 보자


1.png


이 게시물을

댓글'2'

이 댓글을

V닉맨 (작성자)
  • 2014.08.12
  • 수정: 2014.08.12 23:09:20
Imports System.Security.AccessControl
Imports System.IO

Public Class Form1
    Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click

        With FolderBrowserDialog1

            If .ShowDialog() = DialogResult.OK Then

                txtbxBrowseFolderName.Text = .SelectedPath

            End If

        End With

    End Sub

    Private Sub btnLock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLock.Click

        Dim fs As FileSystemSecurity = File.GetAccessControl(txtbxBrowseFolderName.Text)

        fs.AddAccessRule(New FileSystemAccessRule(Environment.UserName, FileSystemRights.FullControl, AccessControlType.Deny))

        File.SetAccessControl(txtbxBrowseFolderName.Text, fs)

    End Sub

    Private Sub btnUnlock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUnlock.Click

        Dim fs As FileSystemSecurity = File.GetAccessControl(txtbxBrowseFolderName.Text)

        fs.RemoveAccessRule(New FileSystemAccessRule(Environment.UserName, FileSystemRights.FullControl, AccessControlType.Deny))

        File.SetAccessControl(txtbxBrowseFolderName.Text, fs)

    End Sub
End Class

* 윈도우의 보안 기능을 이용한 방법이다

1.png

이 댓글을

공유하기

SEARCH

MENU NAVIGATION