473,782 Members | 2,487 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 3163
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
28432
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
3133
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
1508
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
7269
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
1099
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
2577
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
1923
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
2453
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
10311
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
10146
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...
1
10080
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9942
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8967
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...
0
6733
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
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3639
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2874
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.