which argtypes for NetShareAdd

让人想犯罪 __ 提交于 2019-12-23 04:09:09

问题


The win32 function NetShareDel takes three arguments, LPCWSTR LPCWSTR and DWORD.

So I use the following list for argtypes:

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

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

That works fine, but I can't figure out what to use for NetShareAdd, especialle the byte array for NET_SHARE_INFO struct and the last byref(c_int) argument.

Here's the code:

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))

What would be the correct argtypes list for NetShareAdd?


回答1:


Got it working finally

First the line

bytearray = buffer(info)[:]

was changed into byte pointer type

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

and then the argtypes and call will become POINTER(BYTE) too of course:

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))


来源:https://stackoverflow.com/questions/38121435/which-argtypes-for-netshareadd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!