Saturday, 26 November 2011

Program sharing files dan folder

Membuat program sharing files dan folder
dengan Visual Basic


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
Caption
Form1
Test sharing
TextBox Name
Text
Name
Text
Name
Text
Name
Text
Name
Text
Text1
Dikosongkan
Text2
Dikosongkan
Text3
Dikosongkan
Text4
Dikosongkan
Text5
dikosongkan
Label Name
Caption
Name
Caption
Name
Label1
Nama Server
Label2
Path Share
Label3
25
Caption
Name
Caption
Name
Caption
Nama Share
Label4
Keterangan
Label5
Password
CommandButton Name
Caption
Command1
&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()
26
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 ada;lah :

Jika berhasil maka memunculkan pesan :

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

sumber : XCode-Magazine #2

No comments:

Post a Comment

 

Blogger news

Blogroll

About