TMan
TMan

Reputation: 4122

How to create my own windows explorer

I'm trying to create a program where I can hold my own files and be able to put a password upon opening the program. Once I put the password in, I'd then be able to access, make changes, and open my files that I choose to put in there. Any ideas or links on how I can do this? Any help is greatly appreciated. I did try this, but I get UnauthorizedAccessException. I get it when it reaches: For Each mDirectory As IO.DirectoryInfo In mNodeDirectory.GetDirectories in TreeView1_BeforeExpand

                  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

End Class

BTW, I did not write the above code, I tried it off a link I found

Upvotes: 0

Views: 1149

Answers (2)

Timiz0r
Timiz0r

Reputation: 1324

To give your application administrator privileges, first go into your project's properties and click the View Windows Settings button in the Application tab. Replace the existing requestedExecutionLevel tag with <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />.

Upvotes: 0

Jordan
Jordan

Reputation: 2758

Is it possible you don't have administrative privileges?

Perhaps you should try a different mRootPath Adding folders to the c:\Users requires admin privileges.

Upvotes: 1

Related Questions