1

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

So I use the following list for argtypes:

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)

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?

Serve Laurijssen
  • 9,266
  • 5
  • 45
  • 98

1 Answers1

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))
Serve Laurijssen
  • 9,266
  • 5
  • 45
  • 98