473,692 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calling NetShareEnum win32api with ctypes

I want to call NetShareEnum, a function from netapi32.dll
NetShareEnum has this definition:

NET_API_STATUS NetShareEnum(
__in LPWSTR servername,
__in DWORD level,
__out LPBYTE *bufptr,
__in DWORD prefmaxlen,
__out LPDWORD entriesread,
__out LPDWORD totalentries,
__inout LPDWORD resume_handle
);

I wrote this code in python 2.5:

from ctypes import *

cname=c_wchar_p ('a-computer-name')
level=c_int(1)
bufptr=create_s tring_buffer('\ 00', 10000)
prefmaxlen=c_in t(9999)
entriesread=c_l ong(0)
totalentries=c_ long(0)
resume=c_long(0 )

netapi32=cdll.L oadLibrary('net api32.dll')
netapi32.NetSha reEnum(cname, level, byref(bufptr), prefmaxlen,
byref(entriesre ad), byref(totalentr ies), byref(resume))

but I get this error:
Traceback (most recent call last):
File "<pyshell#1 2>", line 1, in <module>
s.NetShareEnum( name, level, byref(bufptr), prefmaxlen,
entriesread, totalentries, resume)
ValueError: Procedure called with not enough arguments (28 bytes
missing) or wrong calling convention

entriesread and totalentries has valid values after call but bufptr is
not.
I pass bufptr to function instead of byref(bufptr) but the error was
same.
Aug 28 '08 #1
4 3152
On Aug 28, 12:01*am, taghi <eghli...@gmail .comwrote:
I want to call NetShareEnum, a function from netapi32.dll
NetShareEnum has this definition:

NET_API_STATUS NetShareEnum(
* __in * * LPWSTR servername,
* __in * * DWORD level,
* __out * *LPBYTE *bufptr,
* __in * * DWORD prefmaxlen,
* __out * *LPDWORD entriesread,
* __out * *LPDWORD totalentries,
* __inout *LPDWORD resume_handle
);

I wrote this code in python 2.5:

from ctypes import *

cname=c_wchar_p ('a-computer-name')
level=c_int(1)
bufptr=create_s tring_buffer('\ 00', 10000)
prefmaxlen=c_in t(9999)
entriesread=c_l ong(0)
totalentries=c_ long(0)
resume=c_long(0 )

netapi32=cdll.L oadLibrary('net api32.dll')
netapi32.NetSha reEnum(cname, level, byref(bufptr), prefmaxlen,
byref(entriesre ad), byref(totalentr ies), byref(resume))

but I get this error:
Traceback (most recent call last):
* File "<pyshell#1 2>", line 1, in <module>
* * s.NetShareEnum( name, level, byref(bufptr), prefmaxlen,
entriesread, totalentries, resume)
ValueError: Procedure called with not enough arguments (28 bytes
missing) or wrong calling convention

entriesread and totalentries has valid values after call but bufptr is
not.
I pass bufptr to function instead of byref(bufptr) but the error was
same.
Taghi,

I just learned how to do this myself. I tested this revision on WinXP
Python 2.5.

from ctypes import *
netapi32= cdll.LoadLibrar y( 'netapi32.dll' )

cname=c_wchar_p ('[mycompname]')
level=c_int(1)
#bufptr=create_ string_buffer(' \00', 10000)
bufptr=c_void_p (0)
prefmaxlen=c_in t(9999)
entriesread=c_l ong(0)
totalentries=c_ long(0)
resume=c_long(0 )

prototype= WINFUNCTYPE( c_int,
c_wchar_p,
c_int,
POINTER( c_void_p ),
c_int,
POINTER( c_long ),
POINTER( c_long ),
POINTER( c_long )
)
NetShareEnum= prototype( ( "NetShareEn um", netapi32 ) )

result= NetShareEnum(cn ame,
level,
pointer(bufptr) ,
prefmaxlen,
byref(entriesre ad),
byref(totalentr ies),
byref(resume)
)

print result
print cname, level, bufptr, prefmaxlen, entriesread, totalentries,
resume
The 'bufptr' parameter receives a pointer to a buffer on return, which
you then have to free using NetApiBufferFre e. Here is my output:

0
c_wchar_p(u'[mycompname]') c_long(1) c_void_p(238250 4) c_long(9999)
c_long(2) c_l
ong(2) c_long(0)

'bufptr' now points to an array of SHARE_INFO_1 structures, which you
will have to define too. It copied 2/2 entries, or 'entriesread' /
'totalentries'. Return 0 indicates success.
Aug 28 '08 #2
taghi wrote:
I wrote this code in python 2.5:

from ctypes import *

.... snip ...

netapi32=cdll.L oadLibrary('net api32.dll')

This is your problem: netapi32 is a windows
DLL and needs to be attached as such:

netapi32 = windll.LoadLibr ary ("netapi32.dll" )

or, more simply:

netapi32 = windll.net32api

But see my other post re this function in pywin32

TJG
Aug 28 '08 #3
taghi wrote:
I wrote this code in python 2.5:

from ctypes import *

.... snip ...

netapi32=cdll.L oadLibrary('net api32.dll')

This is your problem: netapi32 is a windows
DLL and needs to be attached as such:

netapi32 = windll.LoadLibr ary ("netapi32.dll" )

or, more simply:

netapi32 = windll.netapi32

But see my other post re this function in pywin32

TJG
Aug 28 '08 #4
En Thu, 28 Aug 2008 02:01:23 -0300, taghi <eg******@gmail .comescribi�:
I want to call NetShareEnum, a function from netapi32.dll
NetShareEnum has this definition:
[...]
netapi32=cdll.L oadLibrary('net api32.dll')
netapi32.NetSha reEnum(cname, level, byref(bufptr), prefmaxlen,
byref(entriesre ad), byref(totalentr ies), byref(resume))

but I get this error:
Traceback (most recent call last):
File "<pyshell#1 2>", line 1, in <module>
s.NetShareEnum( name, level, byref(bufptr), prefmaxlen,
entriesread, totalentries, resume)
ValueError: Procedure called with not enough arguments (28 bytes
missing) or wrong calling convention
Try with netapi32=windll .netapi32 instead

--
Gabriel Genellina

Aug 28 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
28427
by: Georgy Pruss | last post by:
Hi all, How can I call a function which is in a Windows DLL? For example, import win32api lib_hnd = win32api.LoadLibrary( "user32.dll" ) if lib_hnd: fn_addr = win32api.GetProcAddress( lib_hnd, "MessageBeep" ) # returns int(2010532466) if fn_addr: # Here I'd like to call fn_addr. In C it would be plain fn_addr()
5
3125
by: Frank Borell | last post by:
I'm having a problem retrieving the ShortName from a file that was written by a MAC and only from a Windows 2003 server. I realize the file has a space after it, but I can retrieve the short name from Windows XP and 2000; >>>print win32api.FindFiles(process_source_dir + "*") Excluding the results from "." and "..", it returns: (32, <PyTime:10/13/2005 8:12:12 PM>, <PyTime:10/13/2005 8:41:40 PM>,
0
1504
by: siddharth_jain_1 | last post by:
Hello I am using NetShareEnum to enumerate all the shared folders of a server. If there is password set on the server, I get system error code 5 (access denied) as the return value of NetShareEnum, as expected. However, if I know the password required to access the shares on the server, how do I specify that in my code?
1
7262
by: Siddharth Jain | last post by:
hello I am trying to enumerate the shared folders on a server using the NetShareEnum function. Now, when the server has a password set to access the shared folders, the function returns system error code 5 (access denied). However, if I know the password to access the shares, how can I specify that in my program?
0
1095
by: Siddharth Jain | last post by:
hello I am trying to enumerate the shared folders on a server using the NetShareEnum function. Now, when the server has a password set to access the shared folders, the function returns system error code 5 (access denied). However, if I know the password to access the shares, how can I specify that in my program?
1
2570
by: Siddharth Jain | last post by:
hello I am trying to enumerate the shared folders on a server using the NetShareEnum function. Now, when the server has a password set to access the shared folders, the function returns system error code 5 (access denied). However, if I know the password to access the shares, how can I specify that in my program?
1
1918
by: Gerald Klix | last post by:
I read the whol email thread carefully and could not find any sentence by Guido, which states that he does not accept ctypes for the standard library. He just declined to rewrite winreg. Did I miss something? Cya, Gerald -----Ursprüngliche Nachricht----- Von: python-list-bounces+gerald.klix=klix.ch@python.org Im Auftrag von
1
2445
by: moreati | last post by:
Recently I discovered the re module doesn't support POSIX character classes: Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42) on linux2 Type "help", "copyright", "credits" or "license" for more information. None So I thought I'd try out pcre through ctypes, to recreate pcredemo.c in python. The c code is at:
1
168
by: taghi | last post by:
I want to call NetShareEnum, a function from netapi32.dll NetShareEnum has this definition: NET_API_STATUS NetShareEnum( __in LPWSTR servername, __in DWORD level, __out LPBYTE *bufptr, __in DWORD prefmaxlen, __out LPDWORD entriesread, __out LPDWORD totalentries,
0
8548
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9090
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8970
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7641
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6462
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5823
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4564
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2989
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.