FellowEquality.com
readbud - get paid to read and rate articles

Sabtu, 15 Mei 2010

Membuat program sharing files dan folder


Artikel ini judulnya cara membuat program sharing files dan folder dengan Visual Basic yang dimana sourcenya penulis dapat dari SINI yang telah lama bekerja sama dengan Komunitas HACKER. Pertama-tama jalankan program Visual Basic seperti biasa, lalu buat 5 Text Box dan 5 Label untuk informasi tentang Text Box tersebut serta CommandButton jangan lupa disertakan.


Komponen Properti Nilai

Form Name Form1
Caption Test sharing

TextBox Name Text1
Text Dikosongkan
Name Text2
Text Dikosongkan
Name Text3
Text Dikosongkan
Name Text4
Text Dikosongkan
Name Text5
Text Dikosongkan

Label Name Label1
Caption Nama Server
Name Label2
Caption Path Share
Name Label3
Caption Nama Share
Name Label4
Caption Keterangan
Name Label5
Caption Password

CommandButton Name Command1
Caption &Buat Share

Setelah itu pada bagian sourcenya tinggal anda paste source dibawah ini :

Option Explicit
Private Const NERR_SUCCESS As Long = 0&
Private Const STYPE_DISKTREE As Long = 0
'permissions
Private Const ACCESS_READ As Long = &H1
Private Const ACCESS_WRITE As Long = &H2
Private Const ACCESS_CREATE As Long = &H4
Private Const ACCESS_EXEC As Long = &H8
Private Const ACCESS_DELETE As Long = &H10
Private Const ACCESS_ATRIB As Long = &H20
Private Const ACCESS_PERM As Long = &H40
Private Const ACCESS_ALL As Long = ACCESS_READ Or _
ACCESS_WRITE Or _
ACCESS_CREATE Or _
ACCESS_EXEC Or _
ACCESS_DELETE Or _
ACCESS_ATRIB Or _
ACCESS_PERM
Private Type SHARE_INFO_2
shi2_netname As Long
shi2_type As Long
shi2_remark As Long
shi2_permissions As Long
shi2_max_uses As Long
shi2_current_uses As Long
shi2_path As Long
shi2_passwd As Long
End Type
Private Declare Function ShareJaringan Lib "netapi32" _
Alias "NetShareAdd" (ByVal NamaServer As Long, _
ByVal Level As Long, _
buf As Any, _
ErrHand As Long) As Long
Private Sub Form_Load()
Text1.Text = "\\" & Environ$("COMPUTERNAME")
Text2.Text = "c:\vbbego"
Text3.Text = "vbBego"
Text4.Text = "vbBego Share Demo"
Text5.Text = ""
End Sub
Private Sub Command1_Click()
Dim success As Long
success = BuatShare(Text1.Text, _
Text2.Text, _
Text3.Text, _
Text4.Text, _
Text5.Text)
Select Case success
Case 0: MsgBox "Membuat share folder berhasil"
Case 2118: MsgBox "Nama share sudah ada, ganti dng nama lain"
Case Else: MsgBox "Tidak dapat membuat share..." & success
End Select
End Sub
Private Function BuatShare(NamaServer As String, _
PathShare As String, _
NamaShare As String, _
TandaShare As String, _
SharePwd As String) As Long
Dim dwServer As Long
Dim dwNetname As Long
Dim dwPath As Long
Dim dwRemark As Long
Dim dwPw As Long
Dim Parmerr As Long
Dim si2 As SHARE_INFO_2
dwServer = StrPtr(NamaServer)
dwNetname = StrPtr(NamaShare)
dwPath = StrPtr(PathShare)
'Jika tanda ata password lebih spesifik maka gunakan StrPTR
If Len(TandaShare) > 0 Then
dwRemark = StrPtr(TandaShare)
End If
If Len(SharePwd) > 0 Then
dwPw = StrPtr(SharePwd)
End If
'Mempersiapkan informasi pada struktur SHARE_INFO_2
With si2
.shi2_netname = dwNetname
.shi2_path = dwPath
.shi2_remark = dwRemark
.shi2_type = STYPE_DISKTREE
.shi2_permissions = ACCESS_ALL
.shi2_max_uses = -1
.shi2_passwd = dwPw
End With
'Gunakan fungsi beserta mengirim parameter
BuatShare = ShareJaringan(dwServer, 2, si2, Parmerr)
End Function
Selesai deh projectnya
Dengan program sharing ini diharapkan anda dapat lebih cepat membuat
sharing folder-folder di komputer anda.

Referensi

Tidak ada komentar:

Posting Komentar