我已经开始制作一个锁定和解锁文件夹和文件的应用程序 我的问题是锁定或解锁硬盘驱动器设置为只读的任何方法?在vb.net
我有文件和文件夹的所有代码工作,但我试着谷歌它,我找不到它的任何一个例子,任何帮助是很好的。
锁定文件夹这是我的代码我怎么能为硬盘做同样的事情? 这是我的代码
Imports System.Security.AccessControl
Imports System.IO
Public Class mainForm
Private Sub btnBrowse_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
With FolderBrowserDialog1
If .ShowDialog() = Windows.Forms.DialogResult.OK Then
txtLokasiDirektori.Text = .SelectedPath
End If
End With
End Sub
Private Sub btnKunci_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKunci.Click
If txtLokasiDirektori.Text <> "" Then
Dim SatpamFile As FileSystemSecurity = File.GetAccessControl(txtLokasiDirektori.Text)
SatpamFile.AddAccessRule(New FileSystemAccessRule(Environment.UserName, FileSystemRights.FullControl, AccessControlType.Deny))
File.SetAccessControl(txtLokasiDirektori.Text, SatpamFile)
MsgBox("" & txtLokasiDirektori.Text & " Folder has been locked!")
Else
MsgBox("Please choose the folder!", MsgBoxStyle.Information)
End If
End Sub
Private Sub btnBuka_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuka.Click
If txtLokasiDirektori.Text <> "" Then
Dim SatpamFile As FileSystemSecurity = File.GetAccessControl(txtLokasiDirektori.Text)
SatpamFile.RemoveAccessRule(New FileSystemAccessRule(Environment.UserName, FileSystemRights.FullControl, AccessControlType.Deny))
File.SetAccessControl(txtLokasiDirektori.Text, SatpamFile)
MsgBox("" & txtLokasiDirektori.Text & " Folder has been opened!")
Else
MsgBox("Please choose the folder!", MsgBoxStyle.Information)
End If
End Sub
Private Sub btnTutup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTutup.Click
Dim pesan As MsgBoxResult
pesan = MsgBox("Do you want exit?", MsgBoxStyle.YesNo, "Exit")
If pesan = MsgBoxResult.Yes Then
End
End If
End Sub
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
changeForm.Show()
Me.Hide()
End Sub
Private Sub LinkLabel2_LinkClicked(sender As Object, e As Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel2.LinkClicked
Form1.Show()
End Sub
Private Sub mainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class~
最后可能会找到一些例子
Public Function GetDriveSerial() ' (xDrive As String) As String
Dim FSO As New FileSystemObject
Dim Flg As Boolean
Dim xDr As String
On Error GoTo SKIPIT
Flg = False
For Each dr In FSO.Drives
xDr = Left(dr, 1)
If FSO.GetDrive(xDr).IsReady = True Then
GetDriveSerial = FSO.GetDrive(xDr).SerialNumber
MsgBox(GetDriveSerial) ' Check details below...
If GetDriveSerial = "203462167" Then
Flg = True : Exit For
End If
End If
Next
If Flg = True Then
MsgBox("Welcome the world of Media Ads ...")
Else
MsgBox("LOCK NOT FOUND...!")
End If
SKIPIT:
Exit Function
End Function
我已经尝试了,但是我在FSO.Drives博士的每个博士都没有宣布错误