我正在尝试创建一个程序,我可以保存自己的文件,并在打开程序时输入密码。一旦我输入密码,我就可以访问,进行更改,并打开我选择放入的文件。关于我如何做到这一点的任何想法或链接?任何帮助是极大的赞赏。我试过这个,但是我得到了UnauthorizedAccessException。当它到达时我得到它: 对于每个mDirectory As IO.DirectoryInfo in TreeView1_BeforeExpand中的mNodeDirectory.GetDirectories
Private mRootPath As String = "C:\Users"
Property RootPath As String
Get
Return mRootPath
End Get
Set(ByVal value As String)
mRootPath = value
End Set
End Property
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim mRootNode As New TreeNode
mRootNode.Text = RootPath
mRootNode.Tag = RootPath
mRootNode.Nodes.Add("*DUMMY*")
TreeView1.Nodes.Add(mRootNode)
End Sub
Private Sub TreeView1_BeforeCollapse(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView1.BeforeCollapse
' clear the node that is being collapsed
e.Node.Nodes.Clear()
' add a dummy TreeNode to the node being collapsed so it is expandable
e.Node.Nodes.Add("*DUMMY*")
End Sub
Private Sub TreeView1_BeforeExpand(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView1.BeforeExpand
' clear the expanding node so we can re-populate it, or else we end up with duplicate nodes
e.Node.Nodes.Clear()
' get the directory representing this node
Dim mNodeDirectory As IO.DirectoryInfo
mNodeDirectory = New System.IO.DirectoryInfo(e.Node.Tag.ToString)
' add each subdirectory from the file system to the expanding node as a child node
For Each mDirectory As IO.DirectoryInfo In mNodeDirectory.GetDirectories
' declare a child TreeNode for the next subdirectory
Dim mDirectoryNode As New TreeNode
' store the full path to this directory in the child TreeNode's Tag property
mDirectoryNode.Tag = mDirectory.FullName
' set the child TreeNodes's display text
mDirectoryNode.Text = mDirectory.Name
' add a dummy TreeNode to this child TreeNode to make it expandable
mDirectoryNode.Nodes.Add("*DUMMY*")
' add this child TreeNode to the expanding TreeNode
e.Node.Nodes.Add(mDirectoryNode)
Next
End Sub
结束班
顺便说一下,我没有写上面的代码,我尝试了一下我找到的链接答案 0 :(得分:1)
您是否可能没有管理权限?
也许您应该尝试不同的mRootPath
将文件夹添加到c:\ Users需要管理员权限。
答案 1 :(得分:0)
要授予您的应用程序管理员权限,请先进入项目的属性,然后单击View Windows Settings
选项卡中的Application
按钮。将现有requestedExecutionLevel
代码替换为<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
。