Documenting the entire Windows SDK would require a number of books this size. Therefore, we limit ourselves to a brief reference to the SDK functions and objects presented in this book.
For further information, you may wish to consult the reference guides distributed with the Python for Windows Extensions, the Microsoft SDK documentation, or any other good Windows programming text.
A PyHANDLE object represents a Win32 handle. When a PyHANDLE object is no longer referenced, the Win32 handle is automatically closed. Thus, it isn't strictly necessary (although still considered good style) to explicitly close these handles.
There are a number of variations on a PyHANDLE object, such as the PyHKEY object. These handle objects are identical in operation to a standard PyHANDLE object, but the underlying implementation uses different Win32 functions to close the handle automatically. From the Python programmers point of view, these handles all share the same interface.
Handles are obtained from a number of Win32 functions, such as functions that open or create files or registry keys. When a function requires a PyHANDLE object, it usually also accepts an integer, which is expected to be the raw Win32 handle value.
__int__()
Returns the raw Win32 handle value for this object. Thus, you can use the code int (myHandle) to obtain the Win32 handle value.
Close()
Manually closes the Win32 handle.
Detach()-
Returns the raw Win32 handle and detaches the handle from the PyHANDLE object. After making this call, the Win32 handle isn't closed automatically, and the PyHANDLE object has a Win32 handle value of zero (i.e., an invalid handle value).
handle
The raw Win32 handle as an integer. Thus, myhandle.handle == int(myhandle).
A PyIID object is used whenever a COM GUID is used. PyIID objects can be created using the pywintypes.IID() function, although all functions that accept a GUID also accept a string in the standard GUID format.
__str__
Obtains the string representation of a GUID. Thus, str(myiid) returns this string value.
__cmp__
Used when PyIID objects are compared. This ignores any case differences in the string representation.
There are no attributes.
A PySTARTUPINFO represents a Win32 STARTUPINFO structure. It's created by the function win32process.STARTUPINFO(). Once created, you can assign values to the attributes, then pass the object to win32process.CreateProcess().
There are no methods.
dwFlags
A bit field that determines whether certain PySTARTUPINFO attributes are used when the process creates a window. To use many of the additional attributes, you set the appropriate mask in this attribute and also set the attributes themselves.
Any combination of the following values can be specified:
win32process.STARTF_FORCEONFEEDBACK
Indicates that the cursor is in feedback mode for two seconds after CreateProcess() is called. If during those two seconds the process makes the first GUI call, the system gives five more seconds to the process. If during those five seconds the process shows a window, the system gives five more seconds to the process to finish drawing the window.
win32process.STARTF_FORCEOFFFEEDBACK
Indicates that the feedback cursor is forced off while the process is starting. The normal cursor is displayed.
win32process.STARTF_RUNFULLSCREEN
Indicates that the process should be run in full-screen mode, rather than in windowed mode. This flag is valid only for console applications running on an x86 computer.
win32process.STARTF_USECOUNTCHARS
If not specified, the dwXCountChars and dwYCountChars attributes are ignored.
win32process.STARTF_USEFILLATTRIBUTE
If not specified, the dwFillAttribute attribute is ignored.
win32process.STARTF_USEPOSITION
If not specified, the dwX and dwY attributes are ignored.
win32process.STARTF_USESHOWWINDOW
If this value isn't specified, the wShowWindow attribute is ignored.
win32process.STARTF_USESIZE
If not specified, the dwXSize and dwYSize attributes are ignored.
win32process.STARTF_USESTDHANDLES
Sets the standard input, standard output, and standard error handles for the process to the handles specified in the hStdInput, hStdOutput, and hStdError attributes. The CreateProcess() function's fInherit-Handles parameter must be set to true for this to work properly.
If this value isn't specified, the hStdInput, hStdOutput, and hStdError attributes are ignored.
dwX
An integer that specifies the x offset, in pixels, of the upper-left corner of a window if a new window is created. The offset is from the upper-left corner of the screen.
dwY
An integer that specifies the y offset, in pixels, of the upper-left corner of a window if a new window is created. The offset is from the upper-left corner of the screen.
dwXSize
An integer that specifies the width, in pixels, of the window if a new window is created.
dwYSize
An integer that specifies the height, in pixels, of the window if a new window is created.
dwXCountChars
For console processes, if a new console window is created, an integer that specifies the screen buffer width in character columns. This value is ignored in a GUI process.
dwYCountChars
For console processes, if a new console window is created, an integer that specifies the screen buffer height in character rows.
dwFillAttribute
An integer that specifies the initial text and background colors if a new console window is created in a console application. These values are ignored in GUI applications
hStdInput
A PyHANDLE object that is used as the standard input handle to the process.
hStdOutput
A PyHANDLE object that is used as the standard output handle to the process.
hStdError
A PyHANDLE object that is used as the standard error handle to the process.
lpDesktop
May be None, or on Windows NT/2000, a string containing either the name of the desktop only or the name of both the desktop and window station for this process.
lpTitle
For console processes, a string that contains the title displayed in the titlebar if a new console window is created. If None, the name of the executable file is
used as the window title instead. This parameter must be None for GUI or console processes that don't create a new console window.
wShowWindow Can be any of the SW_ constants defined in win32con. For GUI processes, this specifies the default value the first time ShowWindow() is called. |
The pythoncom module provides the low-level interface between COM and Python.
Creates the specified COM object and returns the requested interface.
interface = CoCreateInstance (clsid, unkOuter , clsctx , iid)
clsid
A string or PyIID object containing the class ID for the new object.
unkOuter
Typically None, or may be a Python interface object if the object is used as part of an aggregate.
clsctx
Defines the context in which the code that manages the newly created object runs. May be a combination of the following constants:
pythoncom.CLSCTX_INPROC_SERVER
The code that creates and manages objects of this class runs in the same process as the caller of the function specifying the class context.
pythoncom.CLSCTX_INPROC_HANDLER
The code that manages objects of this class is an in-process handler. This is a DLL that runs in the client process and implements client-side structures of this class when instances of the class are accessed remotely.
pythoncom.CLSCTX_LOCAL_SERVER
The EXE code that creates and manages objects of this class is loaded in a separate process space (runs on same machine but in a different process).
pythoncom.CLSCTX_REMOTE_SERVER
A remote machine context. The LocalServer32 or LocalService code that creates and manages objects of this class is run on a different machine.
pythoncom.CLSCTX_ALL
Indicates all class contexts.
pythoncom.CLSCTX_INPROC
Indicates all in-process contexts.
pythoncom.CLSCTX_SERVER
Indicates server code, whether in-process, local, or remote.
iid
A string or PyIID object that defines the interface ID requested from the new object.
The result is a Python interface object, the exact type of which is determined by the iid parameter.
This function is for advanced use only; in most cases, you create COM objects using the win32com.client.Dispatch() function.
Initializes COM for apartment model threading.
CoInitialize()
No parameters.
Equivalent to CoInitializeEx (pythoncom.COINIT_APARTMENTTHREADED). See CoInitializeEx() for more details.
Initializes COM for the calling thread.
CoIntializeEx (flags)
flags
An integer defining the initialization options. May include:
pythoncom.COINIT_APARTMENTTHREADED
Initializes the thread for apartment-threaded object concurrency.
pythoncom.COINIT_MULTITHREADED
Initializes the thread for
multithreaded object concurrency.
pythoncom.COINIT_DISABLE_OLE1DDE
Disables DDE for OLE1 support.
pythoncom.COINIT_SPEED_OVER_MEMORY
Trades memory for speed.
There's no need to call this function for the Python thread that first imports the pythoncom module. Please see Appendix D, Threads, for a detailed description of COM threading models.
Closes the COM library on the current thread, unloads all COM DLLs loaded by the thread, and forces all COM RPC connections on the thread to close.
CoUninitialize()
As described in Appendix D, this function is currently never called by the COM framework.
Marshals a Python COM interface object from one thread to another thread in the same process.
stream = CoMarshalInterThreadInterfaceInStream (iid, interface)
iid
A string or PyIID object that identifies the interface to be marshaled into the new stream.
interface
A Python COM interface object or win32com.client.Dispatch() instance to be marshaled.
The result is a PyIStream object; that is, a Python wrapper around a COM IStream interface. This stream is typically passed to CoGetInterface-AndReleaseStream() to obtain the marshaled object in the new thread.
When paired with CoGetInterfaceAndReleaseStream(), programs can easily and reliably marshal a COM interface object to another thread in the same process. See Appendix D for further details.
Unmarshals a Python interface object from a stream and releases the stream.
interface = CoGetInterfaceAndReleaseStream(stream, iid)
stream
A PyIstream object to which the object was previously marshaled.
iid
A string or PyIID object that defines the interface to be unmarshaled from the stream.
The result is a Python COM interface object, the exact type of which is determined by the iid parameter.
When paired with CoMarsha1InterThreadInterfaceInStream(), programs can easily and reliably marshal a COM interface object to another thread in the same process. See Appendix D for further details.
The win32api module contains a mixed bag of useful Win32 API functions. This module contains general-purpose routines often required by programs with fairly light Windows-specific requirements. Other Python modules provide more complete coverage of specific Win32 API sets.
Performs an operation on the specified file
ShellExecute(Hwnd, Operation, File, Parameters, InitialDirectory, bShow)
Hwnd
A handle to the window that is to be the parent window for the new process. This is primarily used for message boxes the new application may display. It's
expressed as a Python integer, and 0 (zero) may be passed if no parent is required.
Operation
A string representing the operation to perform on the file. Typically this is open. The value it takes depends on the process being executed. For example, if you execute a Python file, supported operations are open and edit. If you execute a Microsoft Word document, supported operations include open and print.
File
The name of the file to execute. Most commonly, this is a document, but a program can also be specified.
Parameter
If the File parameter contains the name of a document file, this should be None. If a program is specified, it should be a string containing the name of the document file.
InitialDirectory
The directory in which to open the document. This directory becomes the current directory for the application
bShow
An integer specifying if the main window for the application is to be shown. This is typically 1.
Runs the specified application.
WinExec(CommandLine, WindowShowState)
CommandLine
The command to execute. This string can contain simply the program name in which case the Windows path is searched, or it may contain the full path to the program. Parameters to the program can also be specified here, and these parameters should contain embedded quotation marks if necessary.
WindowShowState
An optional integer that defines how the main window for the program is created. If this parameter isn't specified, win32con.SW_SHOWNORMAL is used. Common values for this flag are listed here, but for a full list, please see the Microsoft documentation for the WinExec function.
win32con.SW_SHOWNORMAL
The window is created using its default. Typically, this means the window is created in a restored or overlapped state.
win32con.SW_SHOWMAXIMIZED
The window is created maximized.
win32con.SW_SHOWMINIMIZED
The window is created minimized.
win32con.SW_HIDE
The window is created hidden.
Retrieves a handle to an existing process
handle = OpenProcess (reqdAccess, bInherit, processId)
reqdAccess
An integer defining the access level requested on the handle. Common values are listed here, but for a full description please see the Win32 documentation for the OpenProcess() function.
win32con.PROCESS_ALL_ACCESS
Specifies all possible access flags for the process object
win32con.PROCESS_QUERY_INFORMATION
Enables using the process handle in the GetExitCodeProcess() and GetPriqrityClass() functions to read information from the process object.
win32con.PROCESS_TERMINATE
Enables using the process handle in the TerminateProcess() function to terminate the process.
bInherit
Specifies whether the returned handle can he inherited by a new process created by the current process. If true. the handle is inheritable.
processId
An integer specifying the process identifier of the process to open.
The result is a PyHANDLE object containing the handle to the process.
Retrieves information, in pixels, about various display elements and system configuration settings.
result = GetSystemMetrics (metricType)
metricType
Specifies the information to retrieve. There are over 80 valid values for this function, which can be identified by constants in the win32con module that begin with SM_, such as SM_CXSCREEN. Please see the Win32 documentation for further details.
An integer with the requested system metric.
Retrieves the name of the domain to which the current computer belongs.
name = GetDomainName()
No parameters.
The result is a string with the current domain name.
Retrieves the username for the current thread.
name = GetUserName()
No parameters.
The result is a string with the current username. No domain information is returned, just the username.
Retrieves the NetBIOS name of the local computer, as defined in the control panel and read at system bootup.
name = GetComputerName()
No parameters.
The result is a string with the computer name.
Intiates a shutdown and optional restart of the specified computer.
InitiateSystemShutdown(machineName, message, timeout, bForceAppsClosed, bReboot)
machineName
The network name of the machine to shut down or None for the current machine.
message
A string that specifies a message to be displayed in the shut-down dialog box or None for no message.
timeout
An integer that specifies the time in milliseconds to display the dialog. During this period, the shutdown can be aborted by calling AbortSystem-Shutdown(). If this value is zero, no dialog is shown, and the shutdown begins immediately.
bForceAppsClosed
An integer that specifies if applications should be forced closed. If true, users aren't given an opportunity to save their work.
bReboot
An integer that specifies if the machine should be restarted after shutdown or left in a state safe to power off the computer.
To shut down the local computer, the calling process must have the SE_SHUTDOWN_NAME privilege. To shut down a remote computer, the calling process must have the SE_REMOTE_SHUTDOWN_NAME privilege on the remote computer.
Stops the system shutdown of a specified computer.
AbortSystemShutdown(machineName)
machineName
A string that specifies the name of the computer on which to abort the shutdown or None for the local computer.
This function can programmatically abort a system shutdown initiated by InitiateSystemShutdown() during the specified timeout interval.
To stop the local computer from shutting down, the calling process must have the SE_SHUTDOWN_NAME privilege. To stop a remote computer from shutting down, the calling process must have the SE_REMOTE_SHUTDOWN_NAME privilege on the remote computer.
Returns the thread identifier for the current thread.
threadId = GetCurrentThreadId()
The result is an integer containing the Win32 thread ID. Until the thread terminates, this ID uniquely identifies the thread to the system.
Returns the process identifier for the current process.
processId = GetCurrentProcessId()
The result is an integer containing the Win32 process ID. Until the process terminates, this ID uniquely identifies the process to the system.
The win32event module contains functions that interface to the various synchronization functions available in the Win32 SDK.
Waits for either the specified object to become signaled or a timeout to occur.
result = WaitForSingleObject(handle, timeout)
handle
A PyHANDLE object or integer that specifies the object to wait for. This may be a handle to one of the following objects:
Change notification
Console input
Event
Job
Mutex
Process
Semaphore
Thread
Waitable timer
timeout
An integer that specifies the timeout period in milliseconds or win32event. INFINITE for no timeout.
The result is an integer that may be one of the following values:
win32event.WAIT_OBJECT_0
The state of the specified object is signaled.
win32event.WAIT_TIMEOUT
The time-out interval has elapsed, and the object's state is nonsignaled.
win32event.WAIT_ABANDONED
The specified object is a mutex object that wasn't released by the thread that owned the mutex object before the owning thread terminated.
Waits for either one or all of the specified objects to become signaled or a timeout to occur.
result = WaitForMultipleObjects(handles, bWaitAll, timeout)
handles
A sequence (e.g., list or tuple) of PyHANDLE or integer objects. The supported handle types are the same as for the win32api.WaitForSingleObject() function.
bWaitAll
An integer indicating if the function should return when all the objects have become signaled (true) or when any one of the objects becomes signaled (false).
timeout
An integer that specifies the timeout period in milliseconds or win32event. INFINITE for no timeout.
The result is an integer that may be one of the following values:
win32event.WAIT_OBJECT_0 to
win32event.WAIT_OBJECT_0+len(handles)-1
If bWaitAll is true, indicates that all of the objects have become signaled. If bWaitAll is false, indicates which of the objects has become signaled.
win32event.WAIT_TIMEOUT
The timeout interval elapsed and the object's state is nonsignaled.
win32event.WAIT_0 to
win32event.WAIT_ABANDONED_0+len(handles)-1
If bWaitAll is true, the return value indicates that the state of all specified objects is signaled and at least one of the objects is an abandoned mutex object. If bWaitAll is false, the return value minus WAIT_ABANDONED_0 indicates the sequence index of an abandoned mutex object that satisfied the wait.
Waits for either one or all the specified objects to become signaled or a timeout to occur. The specified objects can include input event objects, which are specified using the wakeMask parameter.
result = MsgWaitForMultipleObjects(handles, bWaitAll, timeout, wakeMask)
handles
A sequence (e.g., list or tuple) of PyHANDLE or integer objects. The supported handle types are the same as for the win32api.WaitForSingleObject() function.
bWaitAll
An integer indicating if the function should return when all the objects have become signaled (true) or when any one of the objects becomes signaled (false).
timeout
An integer that specifies the timeout period in milliseconds or win32event. INFINITE for no timeout.
wakeMask
An integer that specifies input types for which an input event object handleis added to the sequence object handles. This parameter can be any combination of the following values:
win32event.QS_ALLEVENTS
An input, WM_TIMER, WM_PAINT, WM_HOTKEY or posted message is in the queue.
win32event.QS_ALLINPUT
Any message is in the queue.
win32event.QS_ALLPOSTMESSAGE
A posted message (other than those listed here) is in the queue.
win32event.QS_HOTKEY
AWM_HOTKEY message is in the queue.
win32event.QS_INPUT
An input message is in the queue.
win32event.QS_KEY
A WM_KEYUP, WM_KEYDOWN, WM_SYSKEYUP, or WM_SYSKEYDOWN message is in the queue.
win32event.QS_MOUSE
A WM_MOUSEMOVE message or mouse-button message WM_LBUTTONUP, WM_RBUTTONDOWN, and so on) is in the queue.
win32event.QS_MOUSEMOVE
A WM_MOUSEMOVE message is in the queue.
win32event.QS_PAINT
A WM_PAINT message is in the queue.
win32event.QS_POSTMESSAGE
A posted message (other than those just listed) is in the queue.
win32event.QS_SENDMESSAGE
A message sent by another thread or application is in the queue.
win32event.QS_TIMER
A WM_TIMER message is in the queue.
The result is an integer that may be one of the following values:
win32event.WAIT_OBJECT_0 to
win32event.WAIT_OBJECT_0+len(handles)-1
If bWaitAll is true, indicates that all the objects have become signaled. If bWaitAll is false, indicates which of the objects has become signaled.
WAIT_OBJECT_0 + len (handles)
New input of the type specified in the wakeMask parameter is available in the thread's input queue.
win32event.WAIT_TIMEOUT
The timeout interval elapsed, and the object's state is nonsignaled.
win32event.WAIT_ABANDONED_0 to
win32event.WAIT_ABANDONED_0+len(handles)-1
If bWaitAll is true, the return value indicates the state of all specified objects is signaled and at least one of the objects is an abandoned mutex object. If bWaitAll is false, the return value minus WAIT_ABANDONED_0 indicates the sequence index of an abandoned mutex object that satisfied the wait.
Creates or opens a named or unnamed event object.
handle = CreateEvent (securityAttributes, bManualReset, bInitialState, name)
securityAttributes
A PySECURITYATTRIBUTES object that determines whether the returned handle can be inherited by child processes. If None, the returned handle can't be inherited.
bManualReset
An integer that specifies whether an auto or manual reset object is created. If true, you must use the ResetEvent () function to manually reset the event state to nonsignaled. If false, the system automatically resets the state after a waiting thread has been released.
bInitialState
An integer that specifies if the object is to created in the signaled state. If true, the object is created signaled; otherwise it's nonsignaled.
name
A string that specifies the name of the event object or None if an unnamed object is to be created. If this name matches an existing event object, this function requests EVENT_ALL_ACCESS on the existing object. In this case, the bManualReset and bInitialState parameters are ignored as they have already been specified when the object was initially created.
The result is a PyHANDLE object referencing the requested object.
Sets the state of the specified event object to signaled.
SetEvent (handle)
handle
The handle to the object to signal.
Sets the state of the specified event object to nonsignaled.
ResetEvent(handle)
handle
The handle to the object to reset.
The win32evtlog module interfaces to the Win32 SDK functions that deal with the Windows NT Event Log. This module also contains generic message resources suitable for reference in Event Log records.
Closes a handle to the Event Log.
CloseEventLog(handle)
handle
The handle to close, as obtained from win32evtlog.OpenEventLog().
Opens a handle to one of the Event Logs on the specified machine.
handle = OpenEventLog(machineName, logName)
machineName
The name of the machine to connect to or None for the current machine.
logName
The name of the Event Log to open, such as Application, System, or Security.
The return value is an integer handle to the Event Log.
Reads a number of records from an open Event Log.
records = ReadEventLog(handle, readFlags, recordOffset)
handle
An open handle to the Event Log, obtained from win32evtlog. OpenEventLog().
readFlags
Specify how the read operation is to proceed and may be a combination of the following flags:
win32evtlog.EVENTLOG_FORWARDS_READ
The Log is read in forward chronological order.
win32evtlog.EVENTLOG_BACKWARDS_READ
The Log is read in reverse chronological order.
win32evtlog.EVENTLOG_SEEK_READ
The read operation proceeds from the record specified by the recordOffset parameter. If this flag is used, readFlags must also specify EVENTLOG_FORWARDS_READ or EVENTLOG_BACKWARDS_READ, which indicates the direction for successive read operations.
win32evtlog.EVENTLOG_SEQUENTIAL_READ
The read operation proceeds sequentially from the last call to the win32evtlog.ReadEventLog() function using this handle.
recordOffset
Specifies the log-entry record number at which the read operation should start. This parameter is ignored unless the readFlags parameter includes the EVENTLOG_SEEK_READ flag.
The result is a list of PyEVENTLOGRECORD objects. The number of records returned by a single call can be determined only after the call has returned.
A PyEVENTLOGRECORD object reads records from the Event Log or writes new records to the Log.
This object has no methods.
RecordNumber
The number of the Event Log record. This number can be used to find the specific record.
TimeGenerated
A Time object indicating the time the record was generated.
TimeWritten
A Time object indicating the time the record was actually written to the Log.
EvenID
An integer eventID, as defined by the application writing the record.
EventType
An integer defining the event type, which can be one of the following:
EVENTLOG_ERROR_TYPE
EVENTLOG_WARNING_TYPE
EVENTLOG_INFORMATION_TYPE
EVENTLOG_AUDIT_SUCCESS
EVENTLOG_AUDIT_FAILURE
EventCategory
An integer event category, as defined by the application writing the record.
SourceName
The name of the application that generated the Event Log record.
ComputerName
The name of the computer that generated this message.
StringInserts
A list of string inserts for this message.
Sid
The security identifier of a user to be associated with this record.
Data
The raw binary data for the Event Log record.
The win32evtlog.pyd file contains embedded messages suitable for using to write to the Event Log. Only generic messages are provided.
|
The win32file module contains functions that interface to the File and other I/O-related Win32 API functions.
Opens or creates a file or a number of other objects and returns a handle that can access the object.
handle = CreateFile(FileName, DesiredAccess, ShareMode, SecurityAttributes,
CreationDisposition, FlagsAndAttributes, TemplateFile)
FileName
The name of the file, pipe, or other resource to open.
DesiredAccess
An integer determining the access this file is opened with. This allows the file to be opened with read access, write access, read-write access, or device access. The following flags are defined:
0 Specifies the file to be opened with device query access. This allows the application to query the device attributes without accessing the device.
win32file.GENERIC_READ
Specifies read access to the file. Combine with win32file.GENERIC_WRITE for read-write access.
win32file.GENERIC_WRITE
Specified write access to the file. Combine with win32file.GENERICWRITE for read-write access.
ShareMode
A set of bit flags that determines how the file is to be shared. If ShareMode is 0, the file can't be shared, and all subsequent attempts to open the file fail
until the handle is closed. This parameter can be a combination of the following values:
win32file.FILE_SHARE_DELETE
Windows NT only. Only requests to open the file for delete mode succeed.
win32file.FILE_SHARE_READ
Only requests to open the file for read mode succeed.
win32file.FILE_SHARE_WRITE
Only requests to open the file for write mode succeed.
SecurityAttributes
Determines whether the file is inherited by child processes. On Windows NT, this specifies the security descriptor for the file if the underlying filesystem supports security.
CreationDisposition
Specifies what action to take on files that already exist and what action to take on files that don't already exist. This can be one of the following values:
win32file.CREATE_NEW
A new file is to be created. An exception is thrown if the file already exists.
win32file.CREATE_ALWAYS
A new file is to be created. If an existing file exists, it's overwritten.
win32file.OPEN_EXISTING
Opens an existing file. If the file doesn't already exist, an exception is thrown.
win32file.OPEN_ALWAYS
Opens an existing file if it exists, or creates a new file if not.
win32file.TRUNCATE_EXISTING
Opens the file and truncates its length to zero. The file must have been opened with write access. If the file doesn't exist, an exception is thrown.
FlagsAndAttributes
Specifies the attributes and other flags for the file. This can be a combination of the following flags:
win32file.FILE_ATTRIBUTE_ARCHIVE
The file should be archived; that is, it has the archive attribute set.
win32file.FILE_ATTRIBUTE_ENCRYPTED
The file or directory is to be encrypted. This flag has no affect if the filesystem doesn't support encryption.
win32file.FILE_ATTRIBUTE_HIDDEN
The file is hidden and not included in a normal directory listing.
win32file.FILE_ATTRIBUTE_NORMAL
There are no special attributes on the file. This value is valid only when used alone.
win32file.FILE_ATTRIBUTE_OFFLINE
The data of the file isn't available immediately because it has been moved to temporary offline storage.
win32file.FILE_ATTRIBUTE_READONLY
The file is marked as read-only. Applications can open the file for read access but not write access.
win32file.FILE_ATTRIBUTE_SYSTEM
The file is a system file and used exclusively by the operating system.
win32file.FILE_ATTRIBUTE_TEMPORARY
The file is used for temporary storage, and the operating system attempts to keep the entire file in memory when possible to speed access. Applications should remove these files as soon as possible.
win32file.FILE_FLAG_WRITETHROUGH
The system writes all data immediately to the disk, bypassing the lazywrite capabilities of the cache.
win32file.FILE_FLAG_OVERLAPPED
All I/O on this file occurs asynchronously. When a file is opened in this mode, read and write operations may return ERROR_IO_PENDING, and the event in the OVERLAPPED object is set when the I/O operation completes. Files opened with this flag must provide an OVERLAPPED object.
win32file.FILE_FLAG_NO_BUFFERING
The system opens the file with no buffering or caching.
win32file.FILE_FLAG_RANDOM_ACCESS
Indicates the file is accessed randomly. The system uses this as a hint to optimize caching of the file.
win32file.FILE_FLAG_SEQUENTIAL_SCAN
Indicates the file is accessed sequentially. The system uses this as a hint to optimize caching of the file.
win32file.FILE_FLAG_DELETE_ON_CLOSE
The operating system deletes the file automatically when the last handle to it is closed. Subsequent attempts to open the file (except for delete) fail.
win32file.FILE_FLAG_BACKUP_SEMANTICS
Indicates the file is being opened for a backup operation. Special NT security requirements apply.
win32file.FILE_FLAG_POSIX_SEMANTICS
Changes the semantics of the file to resemble POSIX files. Used only by the POSIX subsystem; shouldn't be used by Windows applications.
win32file.FILE_FLAG_OPEN_REPARSE_POINT
Inhibits the reparse functionality of the NTFS filesystem and is beyond the scope of this book.
win32file.FILE_FLAG_OPEN_NO_RECALL
Used by remote storage systems and is beyond the scope of this book.
TemplateFile
A handle to another file used as a template for file attributes or None. Under Windows 95, this parameter must be None.
A PyHANDLE object to the file.
Reads data from an open file.
errCode, data = ReadFile(FileHandle, Size, Overlapped)
FileHandle
The file handle identifying the file to read from. This handle typically is obtained from win32file.CreateFile().
Size or ReadBuffer
If Size is specified as a Python integer, it's the number of bytes to read from the file. When using overlapped I/O, a ReadBuffer should be used, indicating where the ReadFile operation should place the data.
Overlapped
An OVERLAPPED object or None if overlapped I/O isn't being performed. This parameter can be omitted, in which case None is used.
errCode
Either 0, or ERROR_IO_PENDING.
Data
The data read from the file.
Writes data to an open file.
errCode = WriteFile(FileHandle, Data, Overlapped)
FileHandle
The file handle identifying the file to read from. This handle typically is obtained from win32file.CreateFile().
Data
The data to write to the file, as a Python string.
Overlapped
An OVERLAPPED object or None if overlapped I/O isn't being performed. This parameter can be omitted, in which case None is used.
errCode
Either 0 or ERROR_IO_PENDING.
The win32pipe module contains functions that interface to the pipe-related Win32 API functions.
Connects to a message-type pipe (and waits if an instance of the pipe isn't available), writes to and reads from the pipe, and then closes the pipe.
data = CallNamedPipe(pipeName, sendData, readSize, timeout)
pipeName
The name of the named pipe to connect to.
sendData
The data, as a Python string, to send to the service.
readSize
The size of the buffer to allocate for the result data.
timeout
Specifies the number of milliseconds to wait for the named pipe to be available or one of the following values:
win32pipe.NMPWAIT_NOWAIT
Doesn't wait for the named pipe. If the named pipe isn't available, the function throws an exception.
win32pipe.NMPWAIT_WAIT_FOREVER
Waits indefinitely.
win32pipe.NMPWAIT_USE_DEFAULT_WAIT
Uses the default timeout specified by the pipe in the call to the win32pipe.CreateNamedPipe() function.
The result is the data read from the pipe, as a Python string.
Creates an anonymous pipe and returns handles to the read and write ends of the pipe.
readHandle, writeHandle = CreatePipe(SecurityAttributes, BufferSize)
SecurityAttributes
The security to be applied to the pipe or None for the default security.
BufferSize
An integer specifying the default buffer size for the pipe. This is simply a hint to the operating system. Zero can be passed, in which case the default buffer size is used.
readHandle
A handle to the read end of the pipe. This handle can be used by the win32file.ReadFile() function.
WriteHandle
A handle to the write end of the pipe. This handle can be used by the win32file.WriteFile() function.
The win32process module interfaces to the process and
thread-related Win32 API functions.
Creates a new process and its primary thread.
procHandle, threadHandle, procId, threadId = CreateHandle(ApplicationName,\
CommandLine,\
ProcessSecurityAttributes,\
ThreadSecurityAttributes,\
bInheritHandles,\
CreationFlags,\
Environment,\
CurrentDirectory,\
StartupInfo)
ApplicationName
The name of the executable that creates the process. This can either be a full path to the executable or just the filename portion. If no path is specified, Windows searches the system path for the process. This parameter may be None, in which case the executable must be specified in the CommandLine parameter.
CommandLine
The command line that executes the program. If the ApplicationName parameter is None, this must also include the name of the executable. If ApplicationName is specified, this contains additional arguments for the executable.
ProcessSecurityAttributes
The security attributes for the new process or None if the current attributes are to be inherited. Security attributes can be created using the win32security module.
ThreadSecurityAttributes
The security attributes for the main thread in the new process or None if the current attributes are to be inherited.
bInheritHandles
A boolean flag indicating if the new process should inherit Windows handles from the creating process. If true (that is, 1), each open handle in the creating process is valid for the new process.
CreationFlags
A set of flags that allow special options to be set for the created process. The following flags are currently defined:
win32process.CREATE_DEFAULT_ERROR_MODE
Creates the new process using a default error mode. If this flag isn't set, the error mode for the creating process is used. The error mode for a pro-
cess determines how the application handles certain error conditions and can be set via win32api.SetErrorMode().
win32process.CREATE_NEW_CONSOLE
The new process is created using a new console, rather than inheriting the current console. If the creating process is a GUI process, and the process to be created is a console process, this flag has no effect.
win32process.CREATE_NEW_PROCESS_GROUP
A new process group is created for this process and all subprocesses. A process group determines Ctrl-C or Ctrl-Break handling for console application.
win32process.CREATE_SEPARATE_WOW_VDM
win32process.CREATE_SHARED_WOW_VDM
Under Windows NT when executing a 16-bit program, these flags allow you to specify the Virtual DOS machine the process executes in. The Windows SDK documentation contains more information on these flags.
win32process.CREATE_SUSPENDED
The main thread of the new process is created in a suspended state. The function win32process.ResumeThread() starts the actual execution.
win32process.DEBUG_PROCESS
win32process.DEBUG_ONLY_THIS_PROCESS
These flags are typically used by Windows debuggers. The creating process is assumed to be a debugger, and the system notifies the creator of certain debug-related events.
win32process.DETACHED_PROCESS
If the new process is a console application, the process is created without a console. This is often used to execute console programs in the background.
In addition, these flags can determine the new process's system priority. These flags include:
win32process.HIGH_PRIORITY_CLASS
Used for processes that perform time-critical operations. This should be used sparingly, as a single process at this priority could cause severe disruption to the operating system itself.
win32process.IDLE_PRIORITY_CLASS
Indicates the process need execute only while the machine is otherwise unused. Suitable for background operations that can execute slowly, but should not disrupt the normal operations of the machine.
win32process.NORMAL_PRIORITY_CLASS
Indicates a normal process with no special scheduling requirements.
win32process.REALTIME_PRIORITY_CLASS
The new process has the highest possible priority. Threads at this priority preempt the threads of all other processes, including critical operating-system threads, such as the mouse driver or filesystem cache.
Environment
The environment for the new process or None to inherit the environment of the calling process. If specified, this parameter must be a dictionary of string key/value pairs or Unicode string/value pairs.
CurrentDirectory
A string that specifies the current drive and directory for the process or None to use the current drive and directory of the calling process.
StartupInfo
A Python STARTUPINFO object that specifies information about the window for the new process. A default STARTUPINFO structure can be created by calling win32process.STARTUPINFO(), and if necessary, properties of this object can be set.
procHandle
A handle to the new process.
threadHandle
A handle to the main thread in the new process.
procId
The ID of the new process.
threadId
The ID of the main thread in the new process.
Terminates the specified process and all its threads.
TerminateProcess(processHandle, exitCode)
processHandle
A handle to the process to be terminated. This handle must have sufficient permissions to terminate the process; otherwise an ''access denied'' Win32 exception will be thrown.
exitCode
The integer exit code for the process. This exit code is returned to any program that requests it (e.g., as the return code from the os.system() function or via the win32process.GetExitCodeProcess() function.
Retrieves the process affinity mask for a process and the system affinity mask for the system.
processMask, systemMask = GetProcessAffinityMask(handle)
handle
A PyHANDLE or integer that represents the handle to the process for which the affinity mask is to be retrieved.
processMask
An integer representing the affinity mask for the specified process.
systemMask
An integer representing the affinity mask for the system.
A process affinity mask is a bit mask in which each bit represents the processors on which a process is allowed to run. A system affinity mask is a bit mask in which each bit represents the processors that are configured in a system.
A process affinity mask is a subset of a system affinity mask. A process is allowed to run only on the processors configured into a system.
Under the Windows 95/98 family, both result masks are always set to 1.
Sets a processor affinity mask for the threads of a specified process.
SetProcessAffinityMask(handle, affinityMask)
handle
A PyHANDLE or integer that represents the handle to the process for which the affinity mask is to be set.
affinityMask
An integer defining the new affinity mask for the process.
A process affinity mask is a bit mask in which each bit represents the processor on which the threads of the process are allowed to run. The value of the process affinity mask must be a proper subset of the system affinity mask values obtained by the GetProcessAffinityMask() function.
This function is supported only in the Windows 2000/NT families.
Sets the processor affinity mask for a thread.
oldMask = SetThreadAffinityMask(handle, affinityMask)
handle
A PyHANDLE or integer that represents the handle to the thread for which the affinity mask is to be set.
affinityMask
For Windows NT/2000, an integer defining the new affinity mask for the thread. For Windows 95/98, this must be 1.
On Windows NT/2000, the result is the previous affinity mask for the process. On Windows 95/98, the result is always 1.
Sets the priority class for the specified process.
SetPriorityClass(handle, priorityClass)
handle
A PyHANDLE or integer that represents the handle to the thread for which the affinity mask is to be set.
priorityClass
Specifies the priority class for the process. Specify one of the following values:
win32process.ABOVE_NORMAL_PRIORITY_CLASS
Windows 2000 only: indicates a process that has priority above NORMAL_PRIORITY_CLASS but below HIGH_PRIORITY_CLASS.
win32process.BELOW_NORMAL_PRIORITY_CLASS
Windows 2000 only: indicates a process that has priority above IDLE_PRIORITY_CLASS but below NORMAL_PRIORITY_CLASS.
win32process.HIGH_PRIORITY_CLASS
A process that performs time-critical tasks that must be executed immediately. The threads of the process preempt the threads of normal or idle
priority class processes. An example is the Task List, which must respond quickly when called by the user, regardless of the load on the operating system. Use extreme care when using the high-priority class, because a high-priority class application can use nearly all available CPU time. |
win32process.IDLE_PRIORITY_CLASS
Threads run only when the system is idle. The threads of the process are preempted by the threads of any process running in a higher priority class. An example is a screen saver. The idle-priority class is inherited by child processes.
win32process.NORMAL_PRIORITY_CLASS
No special scheduling needs.
win32process.REALTIME_PRIORITY_CLASS
The highest possible priority. The threads of the process preempt the threads of all other processes, including operating-system processes performing important tasks. For example, a real-time process that executes for more than a brief interval can cause disk caches not to flush or cause the mouse to be unresponsive.
There are a number of Python modules related to Windows NT Services.
The win32serviceutil module is a higher-level interface to the Win32 Service functions. It builds on the win32service module to provide a more convenient interface to service-related functions.
Connects to the Service Control Manager on the specified machine, then attempts to control the service.
status = ControlService(serviceName, code, machine = None)
serviceName
The name of the service from which to obtain the status information.
code
The control code to send to the service. See the win32service. ControlService() function for further information.
machineName = None
The name of the machine to connect to. If not specified, the current machine is used.
The result is the same as for the win32service.ControlService() function.
Connects to the Service Control Manager on the specified machine, then queries the service status.
status = QueryServiceStatus(serviceName, machineName = None)
serviceName
The name of the service from which to obtain the status information.
machineName = None
The name of the machine to connect to. If not specified, the current machine is used.
The result is the same as the win32service.QueryServiceStatus() function's.
Connects to the Service Control Manager on the specified machine, then starts the service using the specified arguments.
StartService(serviceName, args = None, machineName = None)
serviceName
The name of the service to start.
args
A sequence of strings defining the arguments for the service. May be None for no arguments.
machineName
The name of the machine on which to start the service.
Connects to the Service Control Manager on the specified machine, then sends a SERVICE_CONTROL_STOP message to the specified service.
StopService(serviceName, machineName = None)
serviceName
The name of the service to stop.
machineName
The name of the machine on which to stop the service.
The win32service module provides an interface to the low-level Windows NT Service-related functions.
Establishes a connection to the Service Control Manager on the specified computer and opens the specified SCM database.
handle = OpenSCManager(machineName, databaseName, desiredAccess)
machineName
Names the target computer. If None or an empty string, the function connects to the local computer.
databaseName
Names the SCM database to open. If None, the database SERVICES_ACTIVE_DATABASE is used.
desiredAccess
Specifies the access to the SCM. Any or all of the following flags can be used. The value win32service.SC_MANAGER_CONNECT is implied.
win32service.SC_MANAGER_ALL_ACCESS
Includes STANDARD_RIGHTS_REQUIRED, plus the access types in this list.
win32service.SC_MANAGER_CONNECT
Enables connecting to the SCM.
win32service.SC_MANAGER_CREATE_SERVICE
Enables calling the win32service.CreateService() function to create a service and add it to the database.
win32service.SC_MANAGER_ENUMERATE_SERVICE
Enables calling the win32service.EnumServicesStatus() function to list the services in the database.
win32service.SC_MANAGER_LOCK
Enables calling the win32service.LockServiceDatabase() function to acquire a lock on the database.
win32service.SC_MANAGER_QUERY_LOCK_STATUS
Enables calling the win32service.QueryServiceLockStatus() function to retrieve the lock status information for the database.
The following access types can also be used.
win32con.GENERIC_READ
Combines the following access types: STANDARD_RIGHTS_READ, SC_MANAGER_ENUMERATE_SERVICE, and SC_MANAGER_QUERY_LOCK_STATUS.
win32con.GENERIC_WRITE
Combines the following access types: STANDARD_RIGHTS_WRITE and SC_MANAGER_CREATE_SERVICE.
win32con.GENERIC_EXECUTE
Combines the following access types: STANDARD_RIGHTS_EXECUTE, SC_MANAGER_CONNECT, and SC_MANAGER_LOCK.
handle
A handle to the SCM. When no longer needed, it should be closed with win32service.CloseServiceHandle().
Opens a handle to an existing service.
handle = OpenService(scHandle, serviceName, desiredAccess)
scHandle
A handle to the Service Control Manager, as obtained from win32service. OpenSCManager().
serviceName
The name of the service to open. Service-name comparisons are case-insensitive.
desiredAccess
Specifies the access to the service. Before granting the requested access, the system checks the access token of the calling process against the service object.
win32service.SERVICE_ALL_ACCESS
Includes win32con.STANDARD_RIGHTS_REQUIRED in addition to all the access types listed here.
win32service.SERVICE_CHANGE_CONFIG
Enables calling the win32service.ChangeServiceConfig() function to change the service configuration.
win32service.SERVICE_ENUMERATE_DEPENDENTS
Enables calling the win32service.EnumDependentServices() function to enumerate all the services dependent on the service.
win32service.SERVICE_INTERROGATE
Enables calling the win32service.ControlService() function to ask the service to report its status immediately.
win32service.SERVICE_PAUSE_CONTINUE
Enables calling the win32service.ControlService() function to pause or continue the service.
win32service.SERVICE_QUERY_CONFIG
Enables calling the win32service.QueryServiceConfig() function to query the service configuration.
win32service.SERVICE_QUERY_STATUS
Enables calling the win32service.QueryServiceStatus() function to ask the SCM about the status of the service.
win32service.SERVICE_START
Enables calling the win32service.StartService() function to start the service.
win32service.SERVICE_STOP
Enables calling the win32service.ControlService() function to stop the service.
win32service.SERVICE_USER_DEFINED_CONTROL
Enables calling the win32service.ControlService() function to specify a user-defined control code.
You may also specify any of the following standard access types:
win32con.GENERIC_READ
Combines the following access types: STANDARD_RIGHTS_READ, SERVICE_QUERY_CONFIG, SERVICE_QUERY_STATUS, and SERVICE_ENUMERATE_DEPENDENTS.
win32con.GENERIC_WRITE
Combines the following access types: STANDARD_RIGHTS_WRITE and SERVICE_CHANGE_CONFIG.
win32con.GENERIC_EXECUTE
Combines the following access types: STANDARD_RIGHTS_EXECUTE, SERVICE_START, SERVICE_STOP, SERVICE_PAUSE_CONTINUE, SERVICE_INTERROGATE, and SERVICE_USER_DEFINED_CONTROL.
handle
A handle to the service. This should be closed using win32service. CloseServiceHandle().
Closes a handle to a service or the Service Control Manager.
CloseServiceHandle(handle)
handle
A handle obtained from win32service.OpenSCManager(), win32service. OpenService(), or win32service.CreateService().
Sends control requests to a service.
status = ControlService(handle, code)
handle
Handle to the service, as obtained from win32service.OpenService().
code
Specifies the requested control code. May be one of the following values:
win32service.SERVICE_CONTROL_STOP
Requests the service to stop. The handle must have SERVICE_STOP access.
win32service.SERVICE_CONTROL_PAUSE
Requests the service to pause. The handle must have SERVICE_PAUSE_CONTINUE access.
win32service.SERVICE_CONTROL_CONTINUE
Requests the paused service to resume. The handle must have SERVICE_PAUSE_CONTINUE access.
win32service.SERVICE_CONTROL_INTERROGATE
Requests the service to update immediately its current status information to the SCM. The handle must have SERVICE_INTERROGATE access.
The result is a tuple in the same format as returned by the win32service. QueryServiceStatus() function.
Queries a service for status.
status = QueryServiceStatus(handle)
handle
Handle to the service, as obtained from win32service.OpenService().
The result is a tuple with the following fields:
serviceType
A combination of the following flags:
win32service.SERVICE_WIN32_OWN_PROCESS
Indicates a service that runs in its own process.
win32service.SERVICE_WIN32_SHARE_PROCESS
Indicates a service that shares a process with other services.
win32service.SERVICE_KERNEL_DRIVER
Indicates a device driver.
win32service.SERVICE_FILE_SYSTEM_DRIVER
Indicates a filesystem driver.
win32service.SERVICE_INTERACTIVE_PROCESS
A service process that can interact with the desktop.
currentState
A combination of the following flags:
win32service.SERVICE_STOPPED
The service isn't running.
win32service.SERVICE_START_PENDING
The service is starting.
win32service.SERVICE_STOP_PENDING
The service is stopping.
win32service.SERVICE_RUNNING
The service is running.
win32service.SERVICE_CONTINUE_PENDING
The service continue is pending.
win32service.SERVICE_PAUSE_PENDING
The service pause is pending.
win32service.SERVICE_PAUSED
The service is paused.
controlsAccepted
A set of flags indicating the controls the service accepts:
win32service.SERVICE_ACCEPT_STOP
The service can be stopped. This enables the SERVICE_CONTROL_STOP value.
win32service.SERVICE_ACCEPT_PAUSE_CONTINUE
The service can be paused and continued. This enables the SERVICE_CONTROL_PAUSE and SERVICE_CONTROL_CONTINUE values.
win32service.SERVICE_ACCEPT_SHUTDOWN
The service is notified when system shutdown occurs. This enables the system to send a SERVICE_CONTROL_SHUTDOWN value to the service. The win32service.ControlService() function can't send this control code.
Windows 2000 supports additional flags. See the Windows NT documentation for further information.
win32ExitCode
A Win32 error code the service may set while it's starting or stopping. If this value is win32service.ERROR_SERVICE_SPECIFIC_ERROR, the next tuple item contains the service-specific error code.
serviceSpecificExitCode
An error code set by the service. This should be ignored unless the previous item is win32service.ERROR_SERVICE_SPECIFIC_ERROR.
checkPoint
A value the service periodically increments to report its progress during lengthy start, stop, pause, or continue operations. It's used primarily to indicate to the SCM that meaningful initialization or termination is still happening.
waitHint
Specifies an estimate of the amount of time, in milliseconds, that the service expects a pending start, stop, pause, or continue operation to take before the service makes its next call to the win32service.SetServiceStatus() function with either an incremented checkPoint value or a change in currentState.
Starts the service identified by the handle.
StartService(handle, args)
handle
A handle to a service, as obtained from win32service.OpenService().
args
A sequence of strings (or Unicode objects) to use as arguments to the service. None may be specified if no arguments are required.
The servicemanager module is implemented by the Python service framework; thus, there is no servicemanager file on disk, and the module is available only when code is running under the Service Control Manager. See Chapter 18, Windows NT Services, for more information.
Logs a specific message to the Event Log.
LogMsg(errorType, eventId, inserts = ())
errorType
An integer that identifies the class of error. May be either the EVENTLOG_ERROR_TYPE, EVENTLOG_WARNING_TYPE, EVENTLOG_INFORMATION_TYPE, EVENTLOG_AUDIT_SUCCESS, or EVENTLOG_AUDIT_FAILURE constants from the servicemanager module.
eventId
The event ID, which can be any of the valid IDs listed in the messages section for this module.
inserts = ()
A sequence with the inserts for the message. Each sequence item must be a string and is replaced with the specified marker in the message text.
Logs a generic informational, warning or error message to the Event Log.
LogInfoMsg(message)
LogWarningMsg(message)
LogErrorMsg(message)
message
A string containing the message to be written.
The servicemanager module contains embedded messages suitable to write to the Event Log using the methods described previously.
|
Retrieves information about a particular global group in the security database.
data = NetGroupGetInfo (serverName, groupName, level)
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
groupName
A string specifying the name of the global group.
level
An integer that specifies the information level of the returned data. May be 0, 1, or 2.
The result is a dictionary, the contents of which are defined by one of the GROUP_INFO structures, depending on the level parameter.
Enumerates the users in a global group.
entries, total, resume = NetGroupGetUsers (serverName, groupName, level, resume = 0, len=4096)
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
groupName
A string specifying the name of the global group.
level
An integer that specifies the level of data to be returned for each group. Only 0(zero) is currently valid.
resume
A value that controls the iteration when there are a large number of servers to list. Zero should be passed the first time it's called, and while a non-zero resume result is returned from the function, it can be called again with the new resume value to obtain the rest of the servers.
len = 4096
A hint to the Win32 function about how much data to allocate. See the Win32 documentation for more details.
The result is a tuple with the following items:
entries
A list of dictionaries of format GROUP_USERS_INFO_0, one for each user returned.
total
The total number of items left to read before making the call. Thus, totallen (entries) are the number of entries left to read after this call.
resume
A resume handle that can obtain the next set of users. When resume is zero, there are no more items to read.
Sets the membership for the specified global group. Each user you specify is enrolled as a member of the global group. Users you don't specify, but who are currently members of the global group, will have their membership revoked.
NetGroupSetUsers(serverName, groupName ,level=0 , members)
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
groupName
A string specifying the name of the global group.
level
An integer that specifies the data in the members parameter. Only 0 (zero) is currently valid.
members
A sequence (for example, list or tuple) of dictionaries, each of which contains data that corresponds to the GROUP_USERS_INFO_0 structure.
Sets information about a particular group account on a server.
NetGroupSetInfo(serverName, groupName, level, data)
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
groupName
A string specifying the name of the global group.
level
An integer that specifies the data in the data parameter. May be 0, 1, 2, 1002, or 1005.
data
A dictionary with the data for the group. The data is in the format of one of the GROUP_INFO structures, depending on the level parameter.
Creates a new global group in the security database.
NetGroupAdd(serverName, level, data)
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
level
An integer that specifies the data in the data parameter. May be 0, 1, or 2.
data
A dictionary with the data for the group. The data is in the format of one of the GROUP_INFO structures, depending on the level parameter.
Gives an existing user account membership in an existing global group in the security database.
NetGroupAddUser(serverName, groupName, userName)
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
groupName
A string specifying the name of the global group to which the user is to be given membership.
userName
A string specifying the name of the user to be added to the group.
Deletes a global group from the security database.
NetGroupDel(serverName, groupName)
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
groupName
A string specifying the name of the global group to be deleted.
Deletes a user from the specified global group
NetGroupDelUser(serverName, groupName, userName)
serverName
A string-specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
groupName
A string specifying the name of the global group from which the user is to be removed.
userName
A string specifying the name of the user to be removed from to the group.
Retrieves information about each global group in the security database.
entries, total, resume = NetGroupEnum(serverName, level, resume = 0, len=4096
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
level
An integer that specifies the level of the data to be returned. May be 0, 1, or 2.
resume
A value that controls the iteration when there are a large number of servers to list. Zero should be passed the first time it's called, and while a non-zero resume result is returned from the function, it can be called again with the new resume value to obtain the rest of the servers.
len = 4096
A hint to the Win32 function about how much data to allocate. See the Win32 documentation for more details.
The result is a tuple with the following items:
entries
A list of dictionaries in the format of one of the GROUP_INFO structures, depending on the level parameter, one for each group returned.
total
The total number of items left to read before making the call. Thus, totallen (entries) are the number of entries left to read after this call.
resume
A resume handle that can obtain the next set of users. When resume is zero, there are no more items to read.
Adds users to a local group.
NetLocalGroupAddMembers(serverName, groupName, level, members)
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
groupName
A string specifying the name of the global group.
level
An integer that specifies the data in the members parameter; can be 0 or 3.
members
A sequence (for example, list or tuple) of dictionaries, each of which contains data that corresponds to the relevant LOCALGROUP_MEMBERS_INFO structure, depending on the level parameter.
Deletes one or more users from a local group.
NetLocalGroupDelMembers(serverName, groupName, level, members)
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
groupName
A string specifying the name of the global group.
level
An integer that specifies the data in the members parameter; can be 0 or 3.
members
A sequence (for example, list or tuple) of dictionaries, each of which contains data that corresponds to the relevant LOCALGROUP_MEMBERS_INFO structure, depending on the level parameter.
Enumerates the members in a local group.
entries, total, resume = NetLocalGroupGetMembers(serverName, groupName, level, resume = 0, len=4096)
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
groupName
The name of the local group from which to enumerate the members.
level
An integer that specifies the level of data to be returned. May be 0, 1, 2, or 3.
resume
A value that controls the iteration when there are many servers to list. Zero should be passed the first time it's called, and while a non-zero resume result is returned from the function, it can be called again with the new resume value to obtain the rest of the servers.
len = 4096
A hint to the Win32 function about how much data to allocate. See the Win32 documentation for more details.
The result is a tuple with the following items:
entries
A list of dictionaries in the format of one of the LOCALGROUP_MEMBERS_INFO structures; depending on the level parameter, one for each user returned.
total
The total number of items left to read before making the call. Thus, totallen(entries) are the number of entries left to read after this call.
resume
A resume handle that can obtain the next set of users. When resume is zero, there are no more items to read.
Sets the members of a local group. Any existing members not listed are removed.
NetLocalGroupSetMembers(serverName, groupName, level, members)
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
groupName
A string specifying the name of the global group.
level = 0
An integer that specifies the data in the members parameter. May be 0 or 3.
members
A sequence (for example, list or tuple) of dictionaries, each of which contains data that corresponds to one of the LOCALGROUP_MEMBERS_INFO structures.
Sends a string to a registered message alias.
NetMessageBufferSend(domain, userName, fromName, message)
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
userName
The username or message alias to which the message should be sent.
fromName
A string that specifies the username or message alias from whom the message is from, or None for the logged-in user.
message
A string containing the message text.
Retrieves information about all servers of a specific type
entries, total, resume = NetServerEnum(serverName, level, serverTypes=win32netcon.SV_TYPE_ALL, resume = 0, len=4096)
serverName
The name of the server to execute on or None for the current machine.
level
An integer specifying the level of information requested; can be 101 or 102.
serverTypes
A bitmask of flags indicating the types of servers to list. A list of the common flags is presented here; please refer to the Win32 documentation for more details.
SV_TYPE_WORKSTATION
All Internet workstations.
SV_TYPE_SERVER
All Internet servers.
SV_TYPE_SQLSERVER
Any server running with Microsoft SQL Server.
SV_TYPE_DOMAIN_CTRL
Primary domain controller.
SV_TYPE_DOMAIN_BAKCTRL
Backup domain controller.
SV_TYPE_TIMESOURCE
Server running the time-source service.
SV_TYPE_PRINT
Server sharing print queue.
SV_TYPE_DIALIN
Server running dial-in service.
SV_TYPE_NT
Windows NT (either workstation or server).
SV_TYPE_SERVER_NT
Windows NT nondomain controller server.
SV_TYPE_DOMAIN_MASTER
Server running the domain master browser.
SV_TYPE_DOMAIN_ENUM
Primary domain.
SV_TYPE_WINDOWS
Windows 95 or later.
SV_TYPE_ALL
All servers.
resume
A value that controls the iteration when there are many servers to list. Zero should be passed the first time it's called, and while a non-zero resume result is returned from the function, it can be called again with the new resume value to obtain the rest of the servers.
len = 4096
A hint to the Win32 function about how much data to allocate. See the Win32 documentation for more details.
The result is a tuple with the following items:
entries
A list of dictionaries, each of the format define in one of the SERVER_INFO structures depending on the level parameter, one for each server returned.
total
The total number of items left to read before making the call. Thus, totallen (entries) are the number of entries left to read after this call.
resume
A resume handle that can obtain the next set of users. When resume is zero, there are no more items to read.
Retrieves information about a particular server.
data = NetServerGetInfo(serverName, level)
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
level
An integer that specifies the data returned by the function. May be 100, 101, or 102 on all platforms, 1 or 50 on Windows 95/98, or 402 or 403 for Windows 2000.
The result is a dictionary in the format of one of the SERVER_INFO structures, depending on the level parameter.
Sets information about a particular server.
NetServerSetInfo(serverName, level, data)
serverName
A string-specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
level
An integer that specifies the data in the data parameter. May be one of 100, 101, 102, 402, or 403.
data
A dictionary with the data for the server. The data is in the format of one of the SERVER_INFO structures, depending on the level parameter.
Adds a server resource.
NetShareAdd(serverName, level, data)
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
level
An integer that specifies the data in the data parameter. May be 2 or 502.
data
A dictionary with the data for the server resource. The data is in the format of one of the SHARE_INFO structures, depending on the level parameter.
Deletes a server resource.
NetShareDel(serverName, networkName)
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
networkName
A string specifying the resource name to be deleted.
Checks if server is sharing a device.
result, type = NetShareCheck(serverName, deviceName)
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
deviceName
A string specifying the name of the device to check for shared access
result
true if the device is shared, otherwise false.
type
If result is true, indicates the type of device, and may be one of the following values:
win32net.STYPE_DISKTREE
The device is a shared disk drive.
win32net.STYPE_PRINTQ
The device is a shared print queue.
win32net.STYPE_DEVICE
The device is a shared communications device.
win32net.STYPE_IPC
An interprocess communication device.
win32net.STYPE_SPECIAL
A special device.
Retrieves information about each shared resource on a server.
entries, total, resume = NetShareEnum(serverName, level, resume = 0, len=4096)
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
level
An integer that specifies the level of the data to be returned; may be 0, 1, 2, or 502.
resume
A value that controls the iteration when there are many servers to list. Zero should be passed the first time it's called, and while a non-zero resume result is returned from the function, it can be called again with the new resume value to obtain the rest of the servers.
len = 4096
A hint to the Win32 function about much data to allocate. See the Win32 documentation for more details.
The result is a tuple with the following items:
entries
A list of dictionaries in the format of one of the SHARE_INFO structures, depending on the level parameter, one for each resource returned.
total
The total number of items left to read before making the call. Thus, total-len(entries) are the number of entries left to read after this call.
resume
A resume handle, that can be used to obtain the next set of users. When resume is zero, there are no more items to read.
Retrieves information about a particular share on a server.
data = NetShareGetInfo(serverName, networkName, level)
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
networkName
A string specifying the network name of the share on which to return information.
level
An integer that specifies the data returned by the function. May be 0, 1, 2, 501, 502, or 1005.
The result is a dictionary in the format of one of the SHARE_INFO structures, depending on the level parameter.
Sets information about a particular share on a server.
NetShareSetInfo(serverName, networkName, level, data)
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
networkName
A string specifying the network name to set.
level
An integer that specifies the data in the data parameter. May be 1, 2, 502, 1004, 1006, or 1501.
data
A dictionary with the data for the server. The data is in the format of one of the SHARE_INFO structures, depending on the level parameter.
Creates a new user account.
NetUserAdd(serverName, level, data)
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
level
An integer that specifies the data in the data parameter. May be 1, 2, or 3.
data
A dictionary with the data for the server resource. The data must be in the format of the relevant USER_INFO structure, depending on the level parameter.
Changes a user's password on the specified domain.
NetUserChangePassword(serverName, userName, oldPassword, newPassword)
serverName
A string specifying the name of a remote server or domain on which the account is changed. If this parameter is None, the logon domain of the caller is used.
userName
The username for which the password is to be changed or None for the current user.
oldPassword
The user's old password.
newPassword
The user's new password.
Provides information about all user accounts on a server.
entries, total, resume = NetUserEnum(serverName, level, filter=win32netcon.FILTER_ACCOUNT_NORMAL resume = 0, len=4096)
serverName
The name of the server to execute on or None for the current machine.
level
An integer specifying the level of information requested. This can be 0, 1, 2, 3, 10, 11, or 20.
filter
Specifies the account types to enumerate, which may be one of the following values:
FILTER_TEMP_DUPLICATE_ACCOUNT
Enumerates local user account data on a domain controller.
FILTER_NORMAL_ACCOUNT
Enumerates global user account data on a computer.
FILTER_INTERDOMAIN_TRUST_ACCOUNT
Enumerates domain trust account data on a domain controller.
FILTER_WORKSTATION_TRUST_ACCOUNT
Enumerates workstation or member server account data on a domain controller.
FILTER_SERVER_TRUST_ACCOUNT
Enumerates domain-controller account data on a domain controller.
The result is a tuple with the following items:
entries
A list of dictionaries, one for each user returned. Each dictionary is in the format specified by the relevant USER_INFO structure, depending on the level parameter.
total
The total number of items left to read before making the call. Thus, total-len(entries) are the number of entries left to read after this call.
resume
A resume handle, that can be used to obtain the next set of users. When resume is zero, there are no more items to read.
Retrieves information about a particular user account on a server.
data = NetUserGetInfo(serverName, userName, level)
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
networkName
A string specifying the network name of the share on which to return information.
level
An integer that specifies the data returned by the function. May be 0, 1, 2, 3, 10, 11, or 20.
The result is a dictionary in the format of one of the USER_INFO structures, depending on the level parameter.
Sets information about a particular user account on a server.
NetUserSetInfo(serverName, userName, level, data)
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
userName
A string specifying the username for which the information is to be set.
level
An integer that specifies the data in the data parameter. May be any level corresponding to a USER_INFO structure.
data
A dictionary with the data for the server. The data is in the format of one of the USER_INFO structures, depending on the level parameter.
Deletes a user account from a server.
NetUserDel(serverName, userName)
serverName
A string specifying the name of the remote server on which the function is to execute. If this parameter is None, the local computer is used.
userName
A string specifying the username to be deleted.
|
|
|
|
|
|
|
|
|
|
(table continued on next page)
(table continued from previous page)
|
|
|
|
|
|
|
|
|
|
|
|
(table continued on next page)
(table continued from previous page)
|
|
|
(table continued on next page)
(table continued from previous page)
|
|
(table continued on next page)
(table continued from previous page)
|
(table continued on next page)
(table continued from previous page)
|
|
(table continued on next page)
(table continued from previous page)
|
|
(table continued on next page)
(table continued from previous page)
|
(table continued on next page)
(table continued from previous page)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|