哪些argtypes为NetShareAdd

时间:2016-06-30 11:11:30

标签: python ironpython pywin32

win32函数NetShareDel有三个参数,LPCWSTR LPCWSTR和DWORD。

所以我使用以下argtypes列表:

C.windll.Netapi32.NetShareDel.argtypes = [LPCWSTR, LPCWSTR, c_int]
C.windll.Netapi32.NetShareDel.restype = c_int

C.windll.Netapi32.NetShareDel(server, shareName, 0)

工作正常,但我无法弄清楚NetShareAdd的用途,特别是NET_SHARE_INFO结构的字节数组和最后一个byref(c_int)参数。

以下是代码:

def Share(server, shareName, dir):    
    info = SHARE_INFO_2()

    STYPE_DISKTREE = 0

    info.shi2_netname = shareName
    info.shi2_path = dir
    info.shi2_type = STYPE_DISKTREE
    info.shi2_remark = "Shared: " + time.strftime("%Y%m%d-%H:%M")
    info.shi2_max_uses = -1
    info.shi2_passwd = ""
    info.shi2_current_uses = 0
    info.shi2_permissions = 0xFFFFFFFF

    i = c_int()

    bytearray = buffer(info)[:]

    windll.Netapi32.NetShareAdd.argtypes = [LPCWSTR, c_int, ????, ????]

    windll.Netapi32.NetShareAdd(server, 2, bytearray, C.byref(i))

NetShareAdd的正确argtypes列表是什么?

1 个答案:

答案 0 :(得分:1)

终于有了工作

首先是

bytearray = buffer(info)[:]

被更改为字节指针类型

byteptr = C.POINTER(C.wintypes.BYTE)(info)  

然后argtypes和call也将成为POINTER(BYTE):

C.windll.Netapi32.NetShareAdd.argtypes = [LPCWSTR, c_int, C.POINTER(C.wintypes.BYTE), C.POINTER(c_int)]
C.windll.Netapi32.NetShareAdd.restype = c_int

windll.Netapi32.NetShareAdd(server, 2, byteptr, C.byref(i))