O'Reilly logo

Python Programming On Win32 by Mark Hammond, Andy Robinson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Querying Information About Servers

Server information is provided by the PySERVER_INFO_* structures, as defined in Appendix B. PySERVER_INFO_100 provides the lowest level of detail, so let’s see what this includes.

First import the necessary modules and read the data for the server. Then print the dictionary:

>>> import win32net, win32netcon
>>> data=win32net.NetServerGetInfo(None, 100)
>>> data
{'name': L'BOBCAT', 'platform_id': 500}

Notice the platform_id is 500. Windows defines only two platform IDs, one for Windows NT and one for OS/2:

>>> win32netcon.SV_PLATFORM_ID_NT
500
>>>

My workstation is indeed an NT machine: what a relief!

You can also obtain a list of the Windows servers on your network with the win32net.NetServerEnum() function.

entries, total, resume = win32net.NetServerEnum(server, level, serverTypes=
win32netcon.SV_TYPE_ALL, resume = 0, len=4096)
server

The name of the server to execute on or None for the current machine.

level

An integer specifying the level of information requested.

serverTypes

A bitmask of flags indicating the types of servers to list. Appendix B lists common values for this flag.

We don’t discuss the resume or len parameters, or the result. Check the previous example for win32net.NetUserEnum() to see how to use these enumerators.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required