' サーバー名を設定(空文字の場合はローカルコンピュータ)
'*ppConvUnicode はunicodeを返す関数です
strServerName = ppConvUnicode("")
' 共有情報を設定
With udtShareInfo2
' 共有名
gchNetName = GCHandle.Alloc("ShareTest", GCHandleType.Pinned)
.shi2_netname = gchNetName.AddrOfPinnedObject().ToInt32()
' 共有タイプ
.shi2_type = STYPE_DISKTREE
' コメント
gchRemark = GCHandle.Alloc("test", GCHandleType.Pinned)
.shi2_remark = gchRemark.AddrOfPinnedObject().ToInt32()
' 最大ユーザー数
.shi2_max_uses = 1
' 共有フォルダ
gchPath = GCHandle.Alloc("c:\tmp", GCHandleType.Pinned)
.shi2_path = gchPath.AddrOfPinnedObject().ToInt32()
' パスワード
gchPassword = GCHandle.Alloc("hoge", GCHandleType.Pinned)
.shi2_passwd = gchPassword.AddrOfPinnedObject().ToInt32()
End With
' 指定したフォルダを共有
lngWin32apiResultCode = NetShareAdd(strServerName, 2, udtShareInfo2, lngParmErr)
' フォルダの共有に成功したときは
If lngWin32apiResultCode = NERR_Success Then
MsgBox(strNetName & "の共有を追加しました", MsgBoxStyle.Information)
Else
MsgBox(strNetName & "の共有に失敗しました", MsgBoxStyle.Exclamation)
End If
gchNetName.Free()
gchRemark.Free()
gchPath.Free()
gchPassword.Free()
|