Searching...
Senin, 21 Februari 2011

Membuat program sharing files dan folder dengan Visual Basic

Pada postingan ekarang saya akan memberikan contoh pembuatan program dengan Visual Basic, untuk artikel ini judulnya cara membuat program sharing files dan folder dengan Visual Basic yang dimana sourcenya saya dapat dari VBBEGO.COM.
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.

Setelah itu pada bagian sourcenya tinggal sobat 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
Setelah selesai maka


Jika gagal melakukan share maka pesannya adalah :


Jika berhasil maka memunculkan pesan :



Dengan program sharing ini diharapkan sobat dapat lebih cepat membuat sharing folder-folder di komputer  sobat .

Refensi :
Source Code Share Demo dari situs http://vbbego.com

0 comments:

Posting Komentar

Like & Share :


Mari budayakan berkomentar baik berupa Kritik, Saran, maupun Pertanyaan untuk menjadikan blog ini lebih baik ke depannya. Copy-Paste di ijinkan, tapi URL sumbernya disertakan.
Terima Kasih.

 
Back to top!