NetShareAdd 的参数类型
which argtypes for NetShareAdd
win32 函数 NetShareDel 采用三个参数,LPCWSTR LPCWSTR 和 DWORD。
所以我使用以下列表作为参数类型:
import ctypes as C
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 的正确参数类型列表是什么?
终于成功了
第一行
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))
win32 函数 NetShareDel 采用三个参数,LPCWSTR LPCWSTR 和 DWORD。
所以我使用以下列表作为参数类型:
import ctypes as C
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 的正确参数类型列表是什么?
终于成功了
第一行
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))