Hai teman-teman nih saya bagikan lagi sebuah kode program yang cukup berguna, yaitu untuk Mengetahui Lokasi Folder Sistem Windows dengan menggunakan VB 6.0 (Visual Basic 6.0) seperti lokasi folder Program Files, System32 dan folder Windows.
Berikut contoh pembuatannya:
- Buat Project VB 6.0 baru.
- Tambahkan dan atur 3 Commandbutton ke dalam Form seperti gambar di bawah ini.
- Tambahkan 1 Module dengan cara pilih menu Project --> Add Module dan copy paste kode di bawah ini ke dalamnya.
- Copy paste kode di bawah ini ke dalam Form.
Private Declare Function SHGetSpecialFolderLocation Lib "shell32" (ByVal hwnd As Long, ByVal nFolder As Long, Pidl As Long) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal Pidl As Long, ByVal FolderPath As String) As Long
Enum SpecialFolderConst
sfAppData = 26
sfCDBurning = 59
sfCookies = 33
sfDesktop = 0
sfFavorites = 6
sfFonts = 20
sfHistory = 34
sfLocalAppData = 28
sfMyDocuments = 5
sfMyMusic = 13
sfMyPictures = 39
sfMyVideo = 14
sfNetHood = 19
sfPrintHood = 27
sfProfile = 40
sfProgramFiles = 38
sfRecent = 8
sfSendTo = 9
sfStartMenu = 11
sfStartMenuPrograms = 2
sfStartUp = 7
sfSystem = 37
sfTempInternet = 32
sfTemplates = 21
sfWindows = 36
End Enum
Public Function SpecialFolder(ByVal SFConst As SpecialFolderConst) As String
Dim Pidl As Long
Dim s As String * 260
Dim l As Long
l = SHGetSpecialFolderLocation(0, SFConst, Pidl)
If l = 0 Then
l = SHGetPathFromIDList(Pidl, s)
If l = 1 Then
s = Left(Trim(s), InStr(s, Chr(0)) - 1)
SpecialFolder = Trim(s)
End If
End If
End Function
Private Sub cmdPF_Click()
'mengetahui Lokasi Folder Program Files
Me.Text2.Text = SpecialFolder(sfProgramFiles)
End Sub
Private Sub cmdW_Click()
'mengetahui Lokasi Folder Windows
Me.Text2.Text = SpecialFolder(sfWindows)
End Sub
Private Sub cmdS_Click()
'mengetahui Lokasi Folder System
Me.Text2.Text = SpecialFolder(sfSystem)
End Sub