CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2009
    Posts
    20

    How to change folder path?

    (I am using VB.NET 2008 Pro)


    Hello all -

    In VB.NET (2008 Pro) how would I be able to change the path of a folder to represent the recycle bin or printer folder, control panel etc....

    I have seen it before in VB6 (code below) where the user was able to select a windows path and it set the folder to that path, and also, changed the icon to that particular folder.

    The code below is from this VB6 source code

    Code:
    Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
    Dim WindowsDirectory As String
    
    Private Sub cmdSecure_Click()
    On Error GoTo Err
        Dim Path As String
        Dim Data As String
        Dim File As String
        Dim Ext As String
        Dim FileName As String
        ' My computer
    If Option1.Value = True Then
    
        Ext = ".{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
        Path = dirDir.Path
        Data = Mid$(Path, InStrRev(Path, "\") + 1, Len(Path))
        File = Left$(Path, Len(Path) - Len(Data))
        If Not UCase$(Path) = UCase$(WindowsDirectory) _
        And Not UCase$(Data) = UCase("desktop") Then
            
            FileName = File & Data & Ext
            Name dirDir.Path As FileName
            dirDir.Path = File
            MsgBox "Folder Locked.", vbApplicationModal + vbInformation, "Security..."
        Else
            MsgBox "Can't be protected or you must Double Click on the folder.", vbApplicationModal + vbInformation, "Sorry..."
        End If
    End If
    'Recycle Bin
    If Option2.Value = True Then
        Ext = ".{645FF040-5081-101B-9F08-00AA002F954E}"
        Path = dirDir.Path
        Data = Mid$(Path, InStrRev(Path, "\") + 1, Len(Path))
        File = Left$(Path, Len(Path) - Len(Data))
        If Not UCase$(Path) = UCase$(WindowsDirectory) _
        And Not UCase$(Data) = UCase("desktop") Then
            
            FileName = File & Data & Ext
            Name dirDir.Path As FileName
            dirDir.Path = File
                    MsgBox "Folder Locked.", vbApplicationModal + vbInformation, "Security..."
    
        Else
            MsgBox "Can't be protected or you must Double Click on the folder.", vbApplicationModal + vbInformation, "Sorry..."
        End If
    End If
    'Control Panel
    If Option3.Value = True Then
        Ext = ".{21EC2020-3AEA-1069-A2DD-08002B30309D}"
        Path = dirDir.Path
        Data = Mid$(Path, InStrRev(Path, "\") + 1, Len(Path))
        File = Left$(Path, Len(Path) - Len(Data))
        If Not UCase$(Path) = UCase$(WindowsDirectory) _
        And Not UCase$(Data) = UCase("desktop") Then
            
            FileName = File & Data & Ext
            Name dirDir.Path As FileName
            dirDir.Path = File
                    MsgBox "Folder Locked.", vbApplicationModal + vbInformation, "Security..."
    
        Else
            MsgBox "Can't be protected or you must Double Click on the folder.", vbApplicationModal + vbInformation, "Sorry..."
        End If
    End If
    'Dial Up Networking
    If Option4.Value = True Then
        Ext = ".{992CFFA0-F557-101A-88EC-00DD010CCC48}"
        Path = dirDir.Path
        Data = Mid$(Path, InStrRev(Path, "\") + 1, Len(Path))
        File = Left$(Path, Len(Path) - Len(Data))
        If Not UCase$(Path) = UCase$(WindowsDirectory) _
        And Not UCase$(Data) = UCase("desktop") Then
            
            FileName = File & Data & Ext
            Name dirDir.Path As FileName
            dirDir.Path = File
                    MsgBox "Folder Locked.", vbApplicationModal + vbInformation, "Security..."
    
        Else
            MsgBox "Can't be protected or you must Double Click on the folder.", vbApplicationModal + vbInformation, "Sorry..."
        End If
    End If
    'Printers
    If Option5.Value = True Then
        Ext = ".{2227A280-3AEA-1069-A2DE-08002B30309D}"
        Path = dirDir.Path
        Data = Mid$(Path, InStrRev(Path, "\") + 1, Len(Path))
        File = Left$(Path, Len(Path) - Len(Data))
        If Not UCase$(Path) = UCase$(WindowsDirectory) _
        And Not UCase$(Data) = UCase("desktop") Then
            
            FileName = File & Data & Ext
            Name dirDir.Path As FileName
            dirDir.Path = File
                    MsgBox "Folder Locked.", vbApplicationModal + vbInformation, "Security..."
    
        Else
            MsgBox "Can't be protected or you must Double Click on the folder.", vbApplicationModal + vbInformation, "Sorry..."
        End If
    End If
    'Network Neighborhood
    If Option6.Value = True Then
        Ext = ".{208D2C60-3AEA-1069-A2D7-08002B30309D}"
        Path = dirDir.Path
        Data = Mid$(Path, InStrRev(Path, "\") + 1, Len(Path))
        File = Left$(Path, Len(Path) - Len(Data))
        If Not UCase$(Path) = UCase$(WindowsDirectory) _
        And Not UCase$(Data) = UCase("desktop") Then
            
            FileName = File & Data & Ext
            Name dirDir.Path As FileName
            dirDir.Path = File
                    MsgBox "Folder Locked.", vbApplicationModal + vbInformation, "Security..."
    
        Else
            MsgBox "Can't be protected or you must Double Click on the folder.", vbApplicationModal + vbInformation, "Sorry..."
        End If
    End If
    
    Err:
    Me.Caption = Err.Description
        Exit Sub
    End Sub
    
    Private Sub cmdUnsecure_Click()
    On Error GoTo Err
        Dim Path As String
        Dim Temp As String
        Dim Data As String
        Dim File As String
        Dim Ext As String
        Dim FileName As String
        Path = dirDir.Path
        Temp = Mid$(Path, InStrRev(Path, "\") + 1, Len(Path))
        Data = Left$(Temp, InStr(Temp, ".{") - 1)
        File = Left$(Path, Len(Path) - Len(Temp))
        FileName = File & Data
        Name dirDir.Path As FileName
        dirDir.Path = File
        MsgBox "Folder Unlocked.", vbApplicationModal + vbInformation, "Security..."
    Err:
    Me.Caption = Err.Description
    
        Exit Sub
    End Sub
    
    Private Sub Command1_Click()
    cmdUnsecure.Enabled = False
    Frame1.Visible = False
    Frame2.Visible = True
    Command2.Visible = True
    cmdSecure.Visible = True
    Command1.Visible = False
    End Sub
    
    Private Sub Command2_Click()
    Frame2.Visible = False
    Frame1.Visible = True
    cmdSecure.Visible = False
    Command1.Visible = True
    Command2.Visible = False
    cmdUnsecure.Enabled = True
    End Sub
    
    Private Sub Command3_Click()
    MsgBox "Select the folder you wish to lock"
    End Sub
    
    Private Sub Command4_Click()
    End
    End Sub
    
    Private Sub Command5_Click()
    frmTaskBar.Show
    
    End Sub
    
    Private Sub Command6_Click()
    Frame4.Visible = False
    Frame3.Visible = True
    End Sub
    
    Private Sub dirDir_Change()
    On Error Resume Next
        dirDir.Path = drvDrive.Drive
        Me.Caption = dirDir.Path
    End Sub
    
    Private Sub drvDrive_Change()
    On Error GoTo NotReady
        dirDir.Path = drvDrive.Drive
        Exit Sub
    NotReady:
        MsgBox "Drive is not ready.", vbExclamation + vbApplicationModal, "Not Ready..."
    End Sub
    
    Private Sub Form_Load()
        Dim ret As Long
        Dim buff As String
        buff = Space(255)
        ret = GetWindowsDirectory(buff, 255)
        WindowsDirectory = Left$(buff, InStr(buff, vbNullChar) - 1)
       
    End Sub
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        End
    End Sub
    I do not remember where I got this code from, otherwise, I would give him/her the credit and maybe
    contact them, however, I don't.

    Hope someone can help....

    Thanks in advanced

    daveofgv

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: How to change folder path?


  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: How to change folder path?

    Also, here's a list of all the CLSIDs :

    http://www.autohotkey.com/docs/misc/CLSID-List.htm

    In case you haven't read my article... which you really should

  4. #4
    Join Date
    Aug 2009
    Posts
    20

    Re: How to change folder path?

    Thank you for the replies. I have looked into the links you provided and looks like there are a lot more then I have.

    Would it be hard to alter:

    Code:
    If Option1.Value = True Then
    
        Ext = ".{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
        Path = dirDir.Path
        Data = Mid$(Path, InStrRev(Path, "\") + 1, Len(Path))
        File = Left$(Path, Len(Path) - Len(Data))
        If Not UCase$(Path) = UCase$(WindowsDirectory) _
        And Not UCase$(Data) = UCase("desktop") Then
            
            FileName = File & Data & Ext
            Name dirDir.Path As FileName
            dirDir.Path = File
            MsgBox "Folder Locked.", vbApplicationModal + vbInformation, "Security..."
        Else
            MsgBox "Can't be protected or you must Double Click on the folder.", vbApplicationModal + vbInformation, "Sorry..."
        End If
    End If
    to vb.net?

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: How to change folder path?

    That doesn't do anything. Getting it to do anything is not hard in XP, but gets harder from there, depending on where the folder is
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured