首页 > 开发 > 综合 > 正文

目录共享

2024-07-21 02:23:16
字体:
来源:转载
供稿:网友
  • 网站运营seo文章大全
  • 提供全面的站长运营经验及seo技术!
  • option explicit

    'netshareadd在win9x下是放在srvapi.dll中,而在nt下则入在netapi32.dll中。
    '
    '在win98下应使用结构share_info_50
    '在nt下应使用结构share_info_2 和share_info_502

    private declare function netshareadd lib "srvapi.dll" (byval servername as long, byval level as long, buf as any, parmerr as long) as long
    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

    const stype_all = -1
    const stype_disktree = 0
    const stype_printq = 1
    const stype_device = 2
    const stype_ipc = 3
    const stype_special = &h80000000

    const access_read = &h1
    const access_write = &h2
    const access_create = &h4
    const access_exec = &h8
    const access_delete = &h10
    const access_atrib = &h20
    const access_perm = &h40
    const access_all = access_read or access_write or access_create or access_exec or access_delete or access_atrib or access_perm

    '为指定的计算机添加共享
    'server 为计算机名
    'sharepath 为共享路径
    'sharename 为共享名
    'shareremark 为备注
    'sharepw 为密码
    function addshare(server as string, sharepath as string, sharename as string, shareremark as string, sharepw as string) as boolean
    dim lngserver as long
    dim lngnetname as long
    dim lngpath as long
    dim lngremark as long
    dim lngpw as long
    dim parmerr as long
    dim si2 as share_info_2

    lngserver = strptr(server)
    lngnetname = strptr(sharename)
    lngpath = strptr(sharepath)

    if len(shareremark) > 0 then
    lngremark = strptr(shareremark)
    end if

    if len(sharepw) > 0 then
    lngpw = strptr(sharepw)
    end if

    with si2
    .shi2_netname = lngnetname
    .shi2_path = lngpath
    .shi2_remark = lngremark
    .shi2_type = stype_disktree
    .shi2_permissions = access_all
    .shi2_max_uses = -1
    .shi2_passwd = lngpw
    end with

    if netshareadd(lngserver, 2, si2, parmerr) = 0 then
    addshare = true
    else
    addshare = false
    end if
    end function

    private sub command1_click()
    ' mkdir "d:/123"
    addshare "server", "d:/123", "123", "例子", ""
    end sub

    发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表