|
-
August 28th, 2011, 10:04 PM
#1
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|