manual ntXdll manual

Introduction

Monday, January 08, 2001

What is ntXdll ?

ntXdll is an ActiveX Dll which provides a lot of methods and properties. These methods and properties encapsulate internal Windows NT® functions (API - Application Programming Interface). The most of internal Windows NT API are very difficult to use.

ntXdll gives an interface to handle these API in an easy way. It is offered especially to network administrators or documentors, who want to manage their tasks over script languages like Windows Scripting Host®. ntXdll can also be binded to Office VBA macros or other languages, which support COM objects.

People, who want to work with ntXdll should know how to work with COM Objects, Methods and Properties.

For the most functions in the classes of ntXdll, you must have enough privileges to execute them. The best way to prevent errors is to log on as local or domain administrator.

This help

The samples, contained in the manual, are written in Visual Basic®. The most of them are manually inserted. Please write me, if you have detected mistakes:

support@kleinetools.de


Installation

Introduction

Friday, January 12, 2001

Installation of ntXdll

ntXdll is developed in Visual Basic® 6.0. Therefore some additional runtime libraries have to be installed on the system. To read the help, some files for the HTML help control have to be installed (the help requires Internet Explorer 4.0 or higher).

You have to distribute these files if you have binded ntXdll to a program you have developed.

Installation with Setup

The advantage of installing over setup is, that you are able to uninstall all components (registry entries inclusive) over control panel - Add/Remove
Programs. Moreover you always have the newest files on your machine.

Execute Setup.exe and follow the instructions. The files will be copied in predefined directories. You only will be asked for the name of the link to the help in the startmenu.

Some installations require a reboot, if systemfiles have to be replaced.

Manually Installation

After executing the setup on a reference machine you can install other machines manually. Copy the following files in the named directories and then register some files on your system. Some files are normally present on a standard Windows® NT 4.0 machine but is recommended to replace these files with newer versions:

Filename | Path | Normally present on a NT machine | Function
ntXdll.dll | %WINSYSDIR% | No | the tool
ntXdll.chm | %WINDIR%\Help | No | the help file
PSAPI.DLL | %WINSYSDIR% | No | needed to get process informations
COMCAT.DLL | %WINSYSDIR% | Yes | system file
STDOLE2.TLB | %WINSYSDIR% | Yes | system file
ASYCFILT.DLL | %WINSYSDIR% | Yes | system file
OLEPRO32.DLL | %WINSYSDIR% | Yes | system file
OLEAUT32.DLL | %WINSYSDIR% | Yes | system file
hh.exe | %WINDIR% | No | help executable
itircl.dll | %WINSYSDIR% | No | runtime to the help
itss.dll | %WINSYSDIR% | No | runtime to the help
hhctrl.ocx | %WINSYSDIR% | No | activeX control to read the help
MSVBVM60.DLL | %WINSYSDIR% | No | VB runtime

After copying the files above, at last register the following files

%WINSYSDIR%\hhctrl.ocx
%WINSYSDIR%\ntXdll.dll
%WINSYSDIR%\COMCAT.DLL
%WINSYSDIR%\STDOLE2.TLB
%WINSYSDIR%\OLEPRO32.DLL
%WINSYSDIR%\OLEAUT32.DLL
%WINSYSDIR%\MSVBVM60.DLL
%WINSYSDIR%\itircl.dll
%WINSYSDIR%\itss.dll

with the command regsvr32.exe <filepath>, for example regsvr32.exe c:\winnt\system32\hhctrl.ocx

You can open the help with command
hh.exe %WINDIR%\Help\ntXdll.chm, for example hh.exe c:\winnt\help\ntXdll.chm
or by doubleclicking the file ntXdll.chm.

Licencing

The demo version of ntXdll, which can be downloaded on www.kleinetools.de or other sites, becomes a full version with the file keyfile.ntx. This file must be copied in the same directory where ntXdll.dll is installed. You will get the file keyfile.ntx via EMail if you have ordered ntXdll. More infos on www.kleinetools.de .

12/09/2000

KleineTools
Frank Seidel


Class Computer

Tuesday, January 08, 2002

Class Computer

This class uses the Win32 network API to query or set computer properties on the local or a remote system in a Windows NT® 4.0 Domain and needs Windows NT® 4.0 Service Pack 4 or higher.

To query or set computer properties, you have to initialize Computer objects at first. Function InitComputerInfo initializes a collection Computers , which represents all computers, you want to query. You have to access the properties over the object instances of the collection members.

You can use wildcards for the computer names in function InitComputerInfo to make a filter for the collection. If you specify a computername without wildcards, there is no collection created and you have to access the properties of the computer directly over the object instance, you called the function from. This is the recommended method, if you want to change a property of a special computer.

You also can specify different types of computer in function InitComputerInfo , which should be added to the collection.

You can change computer properties by assigning a value of the right type to the property (syntax: <computer object>.<property> = <value>). In this version of ntXdll, you only can change the following properties:

CompHidden
CompComment

All other properties of the class are read only.

You only can change properties within a Computer object, which is initialized .This means, you have to execute function InitComputerInfo at first.

There are some additional functions, which you can use seperate and which do not require initialized Computer objects. These functions are:

GetDCName
GetPDCName
GetMachineName

You get detailed information in the help of each function or property.


InitComputerInfo(...) As Long

Class Computer

Saturday, June 17, 2000

InitComputerInfo ([strName As String], [lngType As Long], [strDefault As String], [lngLevel As Long], [strServer As String], [strDomain As String]) As Long

Function

Return value

Returnes 0 on success, otherwise a nonzero value. If an error occurs, the error number will be returned, but it can be an error from the network API or from VisualBasic. The function initializes the computer properties and the collection Computers of this class. In this version, the Server service and the Workstation service has to run on each machine which is queried or added to the collection with level SV_ENUM_WITH_INFO . Otherwise the initialzation will fail. The optional parameters are:

Parameters

strName
contains the name of the machine from which you want to get the infos from. You can use the wildcards "*" and "?". In this case, the collection Computers of this class will be created (example 1). If you assign a computername, this computer will be searched in the network and you must access the informations directly (example 2). If you omitt this parameter, the local machine will be queried. The default value is an empty string for the local computer (example3).

lngType
if you don't want to search for all types of computers ( SV_TYPE_ALL is the default value) in the network, assign the type to search for. To do this, use the SV_TYPE *-constants. You can combine several types. This parameter is only important, if you want to create a collection.

strDefault
all properties of the class which would contain an empty string are filled with this value. The default is "unknown".

lngLevel
this parameter is only important for creating a collection. It can be SV_ENUM_ONLY (default) or SV_ENUM_WITH_INFO . If you assign SV_ENUM_ONLY , the computers are enumerated only with basic informations ( CompName , CompComment , CompPlatformID , CompType , CompVerMajor , CompVerMinor , CompEntriesRead , CompTotalEntries ). The other informations will contain no informations. If you assign, SV_ENUM_WITH_INFO , the other informations are available, but you have no such performance, because some machines may be not visible for the extended informations in the moment of executing the query, but the network APIs will search for this machines some seconds.

strServer
contains the machine from which you want to execute the query from without leading "\\". If you assign an empty string (this is the default value), the local machine is used. But if this machine is no MasterBrowser or DomainController, it's not sure, that all machines are enumerated ( CompEntriesRead < CompTotalEntries ). Then, there will probably an error returned and only the actually enumerated machines will be added to the collection.

strDomain
assigns the name of the domain for which the list of machines is to returned. If this parameter is an empty string (default), the primary domain is implied.

See also

InitComputerInfo (...)
 Computers
SV_TYPE* constants
SV_ENUM* constants

Example1

Dim cmp1 As Object, Dim
    cmp2 As Object
Dim result As Long
Set cmp1 = CreateObject("ntXdll.Computer")
Set cmp2 = CreateObject("ntXdll.Computer")

'enumerate all domain controller and SQL server
result = cmp1.InitComputerInfo("*", cmp1.SV_TYPE_SQLSERVER Or _
cmp1.SV_TYPE_DOMAIN_CTRL, , cmp1.SV_ENUM_WITH_INFO, "MyPDC")

For Each cmp2 In cmp1.Computers

Debug.Print cmp2.CompName
Debug.Print cmp2.CompType
Debug.Print cmp2.CompEntriesRead
Debug.Print cmp2.CompTotalEntries

Next
Debug.Print cmp1.Computers.Count
Debug.Print cmp1.Computers("MyPDC").CompLoggedOnUsers

Example2

Dim cmp As Object, s As String, result As Long
Set cmp = CreateObject("ntXdll.Computer")
'You must have an account in the other domain
result = cmp.InitComputerInfo("OtherComputer", , "empty", , "OtherPDC", "OtherDomain")
s = cmp.CompComment
MsgBox s

Example3

Dim cmp As Object, s As String, result As Long
Set cmp = CreateObject("ntXdll.Computer")
'Infos about the local computer
result = cmp.InitComputerInfo()
s = cmp.CompComment
MsgBox s


SV_

Class Computer

Saturday, June 17, 2000

SV_ENUM_ONLY
SV_ENUM_WITH_INFO

Properties (read only)

Return values

Long numbers. These propterties are used like constants in the function InitComputerInfo (...) with parameter lngLevel. But they are only necessary if you want to create a collection by using wildcards in the parameter strName. If you assign SV_ENUM_ONLY , the computers are enumerated only with basic informations ( CompName , CompComment , CompPlatformID , CompType , CompVerMajor , CompVerMinor , CompEntriesRead , CompTotalEntries ). The other informations will contain no informations. If you assign SV_ENUM_WITH_INFO , the other informations are available, but you have no such performance, because some machines may be not visible for extended informations in the moment of executing the query, but the Network APIs will search for this machines some seconds. The default value for the optional parameter lngLevel is SV_ENUM_ONLY .

See also

InitComputerInfo (...)
 Computers

Example

Dim cmp1 As Object, Dim
    cmp2 As Object
Dim result As Long
Set cmp1 = CreateObject("ntXdll.Computer")
Set cmp2 = CreateObject("ntXdll.Computer")

result = cmp1.InitComputerInfo("*", , , cmp1.SV_ENUM_WITH_INFO, "MyPDC")

For Each cmp2 In cmp1.Computers

Debug.Print cmp2.CompName
Debug.Print cmp2.CompComment
Debug.Print cmp2.CompLoggedOnUsers

Next


SV_

Class Computer

Saturday, June 17, 2000

SV_TYPE_WORKSTATION
SV_TYPE_SERVER
SV_TYPE_SQLSERVER
SV_TYPE_DOMAIN_CTRL
SV_TYPE_DOMAIN_BAKCTRL
SV_TYPE_TIME_SOURCE
SV_TYPE_AFP
SV_TYPE_NOVELL
SV_TYPE_DOMAIN_MEMBER
SV_TYPE_PRINTQ_SERVER
SV_TYPE_DIALIN_SERVER
SV_TYPE_XENIX_SERVER
SV_TYPE_NT
SV_TYPE_WFW
SV_TYPE_SERVER_MFPN
SV_TYPE_SERVER_NT
SV_TYPE_POTENTIAL_BROWSER
SV_TYPE_BACKUP_BROWSER
SV_TYPE_MASTER_BROWSER
SV_TYPE_DOMAIN_MASTER
SV_TYPE_SERVER_OSF
SV_TYPE_SERVER_VMS
SV_TYPE_WINDOWS
SV_TYPE_DFS
SV_TYPE_CLUSTER_NT
SV_TYPE_DCE
SV_TYPE_ALTERNATE_XPORT
SV_TYPE_LOCAL_LIST_ONLY
SV_TYPE_DOMAIN_ENUM
SV_TYPE_ALL

Properties (read only)

Return values

Long numbers. These propterties are used like constants in the function InitComputerInfo (...) with parameter lngType. But they are only necessary if you want to create a collection by using wildcards in the parameter strName. Then, all machines with the assigned type(s) are enumerated. You can combine several types. The default value for the optional parameter in InitComputerInfo (...) is SV_TYPE_ALL .

See also

InitComputerInfo (...)
 Computers

Example

Dim cmp1 As Object, Dim
    cmp2 As Object
Dim result As Long
Set cmp1 = CreateObject("ntXdll.Computer")
Set cmp2 = CreateObject("ntXdll.Computer")

'list all SQL Server and PrintQueue Server with leading 'M'
result = cmp1.InitComputerInfo("M*", cmp1.SV_TYPE_SQLSERVER Or cmp1.SV_TYPE_PRINTQ_SERVER, , , _
"MyPDC")

For Each cmp2 In cmp1.Computers

'this properties have the same values for all machines in the collection
Debug.Print cmp2.CompName
Debug.Print cmp2.CompComment

Next


Computers As Collection

Class Computer

Saturday, June 17, 2000

Computers As Collection

Property (read only)

Return value

Returnes a Computers-collection when using wildcards in the parameter strName of the function InitComputerInfo (...). The key to access an element in this collection is the computername. So you must not use the For Each - loop. Another property of a collection is 'Count' to query the number of elements in the collection.

See also

InitComputerInfo (...)
 CompEntriesRead
CompTotalEntries

Example

Dim cmp1 As Object, Dim
    cmp2 As Object
Dim result As Long
Set cmp1 = CreateObject("ntXdll.Computer")
Set cmp2 = CreateObject("ntXdll.Computer")
result = cmp1.InitComputerInfo("*")

For Each cmp2 In cmp1.Computers

Debug.Print cmp2.CompName
Debug.Print cmp2.CompComment

Next

Debug.Print cmp1.Computers("Computername").CompLangroup
Debug.Print cmp1.Computers.Count


CompEntriesRead As Long

Class Computer

Saturday, June 17, 2000

CompEntriesRead As Long

Property (read only)

Return value

Returnes the count of computers actually enumerated. This property is only important in case of creating a Computers -collection by using wildcards in the parameter strName of the function InitComputerInfo (...). In all other cases or in the case of an error, a negative number will be returned. Know, that the actually number of enumerated computers is sometimes less than the total number of visible machines in the network. Then, there will probably an error returned by InitComputerInfo (...) and only the actually enumerated machines will be added to the collection. This depends on the machine, from which the enumeration is executed (parameter strServer in function InitComputerInfo (...)).

See also

InitComputerInfo (...)
 Computers
CompTotalEntries

Example

Dim cmp1 As Object, Dim
    cmp2 As Object
Dim result As Long
Set cmp1 = CreateObject("ntXdll.Computer")
Set cmp2 = CreateObject("ntXdll.Computer")
result = cmp1.InitComputerInfo("MyC*puter")

For Each cmp2 In cmp1.Computers

'this properties have the same values for all machines in the collection
Debug.Print cmp2.CompEntriesRead
Debug.Print cmp2.CompTotalEntries

Next


CompTotalEntries As Long

Class Computer

Saturday, June 17, 2000

CompTotalEntries As Long

Property (read only)

Return value

Returnes the total number of visible machines in the network. This property is only important in case of creating a Computers -collection by using wildcards in the parameter strName of the function InitComputerInfo (...). In all other cases or in the case of an error, a negative number will be returned. Know, that the actually number of enumerated computers is sometimes less than the total number of visible machines in the network. Then, there will probably an error returned by InitComputerInfo (...) and only the actually enumerated machines will be added to the collection. This depends on the machine, from which the enumeration is executed (parameter strServer in function InitComputerInfo (...)).

See also

InitComputerInfo (...)
 Computers
CompEntriesRead

Example

Dim cmp1 As Object, Dim
    cmp2 As Object
Dim result As Long
Set cmp1 = CreateObject("ntXdll.Computer")
Set cmp2 = CreateObject("ntXdll.Computer")
result = cmp1.InitComputerInfo("MyC*puter")

For Each cmp2 In cmp1.Computers

'this properties have the same values for all machines in the collection
Debug.Print cmp2.CompEntriesRead
Debug.Print cmp2.CompTotalEntries

Next


CompName As String

Class Computer

Saturday, June 17, 2000

CompName As String

Property (read only)

Return value

Returns the network name of the machine. To get the information, you have to init the info with InitComputerInfo (..) at first.

See also

InitComputerInfo (...)
 Computers

Example

Dim cmp As Object, s As
    String, result As Long
Set cmp = CreateObject("ntXdll.Computer")
result = cmp.InitComputerInfo("ThisComputer")
s = cmp.CompName
MsgBox s


CompComment As String

Class Computer

Wednesday, December 06, 2000

CompComment As String

Property

Return value

Returnes or sets the description of the machine. In case of an empty string, if you query the property, the parameter strDefault of the function InitComputerInfo (...) will be returned. At first, you have to init the info with InitComputerInfo (..).

To set the property, you assign a string to the property in the object instance where the computer infos are initializes with InitComputerInfo (..) (example2). If there is occurs an error on setting CompComment, the property LastError of this class gets the value of this error number. This can be a VB or an API error.

See also

InitComputerInfo (...)
 Computers
LastError

Example1 (query the property)

Dim cmp As Object, s As
    String, result As Long
Set cmp = CreateObject("ntXdll.Computer")
result = cmp.InitComputerInfo("MyComputer")
s = cmp.CompComment
MsgBox s

Example2 (set the property)

Dim cmp As Object, s As
    String, result As Long
Set cmp = CreateObject("ntXdll.Computer")
result = cmp.InitComputerInfo("MyComputer")
cmp.CompComment = "a new comment"
MsgBox cmp.LastError
s = cmp.CompComment
MsgBox s


CompPlatformID As Long

Class Computer

Saturday, June 17, 2000

CompPlatformID As Long

Property (read only)

Return value

Indicates the information level to use to retrieve platform-specific information. To get the information, you have to init the info with InitComputerInfo (..) at first.

See also

InitComputerInfo (...)
 Computers

Example

Dim cmp1 As Object, Dim
    cmp2 As Object
Dim result As Long
Set cmp1 = CreateObject("ntXdll.Computer")
Set cmp2 = CreateObject("ntXdll.Computer")
result = cmp1.InitComputerInfo("*",,,,"OurPDC")

For Each cmp2 In cmp1.Computers

Debug.Print cmp2.CompPlatformID

Next


CompType As String

Class Computer

Saturday, June 17, 2000

CompType As String

Property (read only)

Return value

Describes the type of software the computer is running. This property is a string out of one or more of the SV_TYPE * constant expressions separated by a semicolon. To get the information, you have to init the info with InitComputerInfo (..) at first.

See also

InitComputerInfo (...)
 Computers
SV_TYPE* Constants

Example

Dim cmp As Object, s As
    String, result As Long
Set cmp = CreateObject("ntXdll.Computer")
result = cmp.InitComputerInfo("ThisComputer")
s = cmp.CompType
Debug.Print s

'for example "SV_TYPE_DOMAIN_ENUM;SV_TYPE_WORKSTATION;SV_TYPE_SERVER" is printed for a workstation in the domain


CompAvailable As Boolean

Class Computer

Saturday, June 17, 2000

CompAvailable As Boolean

Property (read only)

Return value

Returnes whether a computer is available for more information. This property is only important for getting extended information by creating a collection Computers with the parameter lngLevel = SV_ENUM_WITH_INFO in InitComputerInfo (..) or assigning an explicit Computername with the parameter strName in InitComputerInfo (..). Mostly the error 53 "The network path was not found" is the reason, that a machine is not available. At first, you have to init the info with InitComputerInfo (..). If an error occurs or by creating a collection with the parameter lngLevel = SV_ENUM_ONLY in InitComputerInfo (..), the ReturnValue is False.

See also

InitComputerInfo (...)
 Computers

Example

Dim cmp As Object, b As
    Boolean, result As Long
Set cmp = CreateObject("ntXdll.Computer")
result = cmp.InitComputerInfo("MyComputer")
b = cmp.CompAvailable
MsgBox CStr(b)


CompHidden As Boolean

Class Computer

Wednesday, December 06, 2000

CompHidden As Boolean

Property

Return value

Returns or sets whether the machine is visible to other computers in the same network domain. This member can be True or False. To get the information, you have to init the info with InitComputerInfo (..) at first.

To set the property, you assign a boolean value to the property in the object instance where the computer infos are initializes with InitComputerInfo (..) (example2). If there is occurs an error on setting CompHidden, the property LastError of this class gets the value of this error number. This can be a VB or an API error.

See also

InitComputerInfo (...)
 Computers
LastError

Example1 (query the property)

Dim cmp1 As Object, Dim
    cmp2 As Object
Dim result As Long
Set cmp1 = CreateObject("ntXdll.Computer")
Set cmp2 = CreateObject("ntXdll.Computer")
result = cmp1.InitComputerInfo("*",,,,"OurPDC")

For Each cmp2 In cmp1.Computers

Debug.Print cmp2.CompHidden

Next

Example2 (set the property)

Dim cmp1 As Object, Dim
    cmp2 As Object
Dim result As Long
Set cmp1 = CreateObject("ntXdll.Computer")
Set cmp2 = CreateObject("ntXdll.Computer")
result = cmp1.InitComputerInfo("*",,,,"OurPDC")

For Each cmp2 In cmp1.Computers

If cmp2.CompName = "IWantToBeHidden" Then

cmp2.CompHidden = True
If cmp2.LastError <> 0 Then MsgBox "Error: " & comp2.LastError

End If

Next


CompUsers As String

Class Computer

Saturday, June 17, 2000

CompUsers As String

Property (read only)

Return value

Indicates the number of users who can attempt to log on to the machine. This property is mostly important for servers. However, it is the license server that determines how many of these users can actually log on. To get the information, you have to init the info with InitComputerInfo (..) at first.

See also

InitComputerInfo (...)
 Computers

Example

Dim cmp As Object, s As
    String, result As Long
Set cmp = CreateObject("ntXdll.Computer")
result = cmp.InitComputerInfo()
s = cmp.CompUsers
Debug.Print s


CompLoggedOnUsers As Long

Class Computer

Saturday, June 17, 2000

CompLoggedOnUsers As Long

Property (read only)

Return value

Returns the number of users who are logged on to the computer. To get the information, you have to init the info with InitComputerInfo (..) at first.

See also

InitComputerInfo (...)
 Computers

Example

Dim cmp As Object, l As
    Long, result As Long
Set cmp = CreateObject("ntXdll.Computer")
result = cmp.InitComputerInfo()
l = cmp.CompLoggedOnUsers
MsgBox CStr(l)


CompUserPath As String

Class Computer

Saturday, June 17, 2000

CompUserPath As String

Property (read only)

Return value

Returnes a string specifying the path to user directories. This property is mostly important for servers. To get the information, you have to init the info with InitComputerInfo (..) at first.

See also

InitComputerInfo (...)
 Computers

Example

Dim cmp As Object, s As
    String, result As Long
Set cmp = CreateObject("ntXdll.Computer")
result = cmp.InitComputerInfo()
s = cmp.CompUserPath
Debug.Print s


CompLangroup As String

Class Computer

Saturday, June 17, 2000

CompLangroup As String

Property (read only)

Return value

Returnes a string specifying the name of the domain to which the computer belongs. To get the information, you have to init the info with InitComputerInfo (..) at first.

See also

InitComputerInfo (...)
 Computers

Example

Dim cmp As Object, s As
    String, result As Long
Set cmp = CreateObject("ntXdll.Computer")
result = cmp.InitComputerInfo("MyComputer")
s = cmp.CompLangroup
MsgBox s


CompLanroot As String

Class Computer

Saturday, June 17, 2000

CompLanroot As String

Property (read only)

Return value

Returnes a string that contains the path to the LANMAN directory. To get the information, you have to init the info with InitComputerInfo (..) at first.

See also

InitComputerInfo (...)
 Computers

Example

Dim cmp As Object, s As
    String, result As Long
Set cmp = CreateObject("ntXdll.Computer")
result = cmp.InitComputerInfo("MyComputer")
s = cmp.CompLanroot
MsgBox s


CompAnnounceDelta As Long

Class Computer

Saturday, June 17, 2000

CompAnnounceDelta As Long

Property (read only)

Return value

Specifies the delta value or change of the property CompAnnounceRate , in milliseconds. This value specifies how much the announce rate can vary from the time specified in the property CompAnnounceRate . The delta value allows randomly varied announce rates. For example, if the property CompAnnounceRate has the value 10 and the CompAnnounceDelta has the value 1, the announce rate can vary from 9.999 seconds to 10.001 seconds. At first, you have to init the info with InitComputerInfo (..). If an error occurs or by creating a collection with the parameter lngLevel = SV_ENUM_ONLY in InitComputerInfo (..), the ReturnValue is a negative number.

See also

InitComputerInfo(...)
CompAnnounceRate
Computers

Example

Dim cmp As Object, l As
    Long, result As Long
Set cmp = CreateObject("ntXdll.Computer")
result = cmp.InitComputerInfo("MyComputer")
l = cmp.CompAnnounceDelta
MsgBox CStr(l)


CompAnnounceRate As Long

Class Computer

Saturday, June 17, 2000

CompAnnounceRate As Long

Property (read only)

Return value

Specifies the network announce rate, in seconds. This rate determines how often the machine is announced to other computers on the network. At first, you have to init the info with InitComputerInfo (..). If an error occurs or by creating a collection with the parameter lngLevel = SV_ENUM_ONLY in InitComputerInfo (..), the ReturnValue is a negative number.

See also

InitComputerInfo(...)
CompAnnounceDelta
Computers

Example

Dim cmp As Object, l As
    Long, result As Long
Set cmp = CreateObject("ntXdll.Computer")
result = cmp.InitComputerInfo("MyComputer")
l = cmp.CompAnnounceRate
MsgBox CStr(l)


CompAutoDisconnect As Long

Class Computer

Saturday, June 17, 2000

CompAutoDisconnect As Long

Property (read only)

Return value

Indicates the auto-disconnect time, in minutes. A session is disconnected if it is idle longer than the time specified by the CompAutoDisconnect property. If the value of CompAutoDisconnect property is 0, auto-disconnect is not enabled. At first, you have to init the info with InitComputerInfo (..). If an error occurs or by creating a collection with the parameter lngLevel = SV_ENUM_ONLY in InitComputerInfo (..), the ReturnValue is negative number.

See also

InitComputerInfo (...)
 Computers

Example

Dim cmp As Object, l As
    Long, result As Long
Set cmp = CreateObject("ntXdll.Computer")
result = cmp.InitComputerInfo("MyComputer")
l = cmp.CompAutoDisconnect
MsgBox CStr(l)


CompLicenses As Long

Class Computer

Saturday, June 17, 2000

CompLicenses As Long

Property (read only)

Return value

Specifies the number of users per license. By default, this number is 5. To get the information, you have to init the info with InitComputerInfo (..) at first.

See also

InitComputerInfo (...)
 Computers

Example

Dim cmp1 As Object, Dim
    cmp2 As Object
Dim result As Long
Set cmp1 = CreateObject("ntXdll.Computer")
Set cmp2 = CreateObject("ntXdll.Computer")
result = cmp1.InitComputerInfo("*",,,,"OurPDC")

For Each cmp2 In cmp1.Computers

Debug.Print cmp2.CompLicenses

Next


CompVerMajor As Long

Class Computer

Saturday, June 17, 2000

CompVerMajor As Long

Property (read only)

Return value

Specifies, in the least significant 4 bits, the major release version number of the operating system. The most significant 4 bits specifies the server type. To get the information, you have to init the info with InitComputerInfo (..) at first.

See also

InitComputerInfo (...)
 Computers

Example

Dim cmp1 As Object, Dim
    cmp2 As Object
Dim result As Long
Set cmp1 = CreateObject("ntXdll.Computer")
Set cmp2 = CreateObject("ntXdll.Computer")
result = cmp1.InitComputerInfo("*", , , , "OurPDC")

For Each cmp2 In cmp1.Computers

Debug.Print cmp2.CompVerMaior

Next


CompVerMinor As Long

Class Computer

Saturday, June 17, 2000

CompVerMinor As Long

Property (read only)

Return value

The minor release version number of the operating system. To get the information, you have to init the info with InitComputerInfo (..) at first.

See also

InitComputerInfo (...)
 Computers

Example

Dim cmp1 As Object, Dim
    cmp2 As Object
Dim result As Long
Set cmp1 = CreateObject("ntXdll.Computer")
Set cmp2 = CreateObject("ntXdll.Computer")
result = cmp1.InitComputerInfo("*", , , , "OurPDC")

For Each cmp2 In cmp1.Computers

Debug.Print cmp2.CompVerMinor

Next


LastError As Long

Class Computer

Tuesday, December 19, 2000

LastError As Long

Property

Return value

The property returns an error number which is set by different functions and properties of this class. A value of 0 means no error. Otherwise the error number can be a VB or an API error. It is documented in the help of the functions which set this property. To get the description of the error, use function FormatAPIMessage of class DllClass (see example 2).

See also

FormatAPIMessage

Example1 (late binding)

Dim cmp
Set cmp = CreateObject("ntXdll.Computer")

MsgBox cmp.GetPDCName("TheComputer", "MyDomain", "error") & " " & cmp.LastError

Example2 (set a property, late binding)

Dim cmp, dll, s, result

Set cmp = CreateObject("ntXdll.Computer")
Set dll = CreateObject("ntXdll.DllClass")

result = cmp.InitComputerInfo("MyComputer")
cmp.CompComment = "a new comment"
result = cmp.LastError

MsgBox dll.FormatAPIMessage(result, dll.FormatAPIMessage(result, Error(result)), "netmsg.dll")


GetMachineName(...) As String

Class Computer

Saturday, June 17, 2000

GetMachineName (strDefault As String) As String

Function

Return value

Returnes the Name of the local computer. If an error occurs, parameter strDefault will be returned.

Example

Debug.Print GetMachineName("error")


GetDCName(...) As String

Class Computer

Saturday, December 09, 2000

GetDCName

([strMachine As String], [strDomain As String], [strDefault As String]) As String

Function

Return value

The function returns the name of any domain controller (DC) for a domain that is directly trusted by the with parameter strMachine specified machine. The function returns strDefault if an error occurs. Then, the property LastError of this class is nonzero. This can be a VB or an API error. For further functions look under 'See also'.

Parameters

strMachine (String, optional)
the machine (without backslashes '\\') on which the function is to execute. If strMachine is omitted, the local machine is used

strDomain (String, optional)
the name of the domain. If strMachine specifies a standalone Workstation or server, the parameter must be omitted. If strMachine specifies a workstation or server, which is member of a domain, strDomain must be the name of the domain, the machine is member of. If strMachine specifies a domain controller, strDomain must be one of the domains trusted by the domain for which the server is a controller.

strDefault (String, optional)
the value which is returned by the function on error.

See also

GetPDCName
LastError

Example (early binding)

Dim cmp As New Computer

MsgBox cmp.GetDCName("TheComputer", "MyDomain", "error") & " " & cmp.LastError


GetPDCName(...) As String

Class Computer

Saturday, December 09, 2000

GetPDCName

([strMachine As String], [strDomain As String], [strDefault As String = "ERROR"]) As String

Function

Return value

The function returns the name of the primary domain controller (PDC). You cannot remote this function to a non-PDC server.
The function returns strDefault if an error occurs. Then, the property LastError of this class is nonzero. This can be a VB or an API error. For further functions look under 'See also'.

Parameters

strMachine (String, optional)
the machine (without backslashes '\\') on which the function is to execute. If strMachine is omitted, the local machine is used

strDomain (String, optional)
the NETBIOS name of the domain. If you omitt this parameter, the primary domain is used. DNS names like xxx.yyy.com are not supported.

strDefault (String, optional)
the value which is returned by the function on error.

See also

GetDCName
LastError

Example (early binding)

Dim cmp As New Computer

MsgBox cmp.GetPDCName("TheComputer", "MyDomain", "error") & " " & cmp.LastError


Class Registry

Saturday, June 17, 2000

Class Registry

Class Registry provides a lot of functions and properties, which enable the user of ntXdll to read and modify the registry on the local or a remote compputer. Class Registry includes a lot of properties and functions. Please read the manual carefully, to see, how the properties are initialized.

For all functions and properties, you have to open a registry and a registry key with the functions OpenRegistry and OpenRegKey at first. Additionally, these functions initialize some properties of the opened registry or the opened key within the object instance, you call the functions from. After finishing a task, you have to close the key and the registry with functions CloseRegKey and CloseRegistry .

If you want to query the properties of a value in an opened key, you have to execute function GetRegValueInfo within the object instance, you called function OpenRegKey from.

If you want to query informations about the subkeys or the values of an opened key, you have to execute one of the functions

InitRegSubKeys ,
 InitRegValues ,
 InitRegRights or
 InitRegAudits

within the object instance, you called function OpenRegKey from. These function initialize the collections

RegSubKeys ,
 RegValues ,
 RegRights or
 RegAudits .

The members of these collection contain the properties, you want to query. The functions InitRegRights and InitRegAudits give you informations about the access rights or configured audits of registry keys.

Additional functions are:

CreateRegSubKey
DeleteRegSubKey
SetRegValue
DeleteRegValue
LoadRegKey
UnloadRegKey
SaveRegKey
RestoreRegKey

The class uses the ANSI versions of the registry APIs.

The examples are partially coded with 'early binding' and partially with 'late binding', which is to use in script languages like Windows Scripting Host.

You get detailed information in the help of each function or property of the class.


OpenRegistry(...) As Long

Class Registry

Saturday, June 17, 2000

OpenRegistry(ByVal lngHKey As Long, [ByVal strMachine As String]) As Long

Function

Return value

Use this function to open a registry hive. You have to execute this function before opening and accessing a registry key.

OpenRegistry initializes the properties
 RegKeyRoot ,
 RegKeyRootHandle ,
 RegMachine
of this class. The function returnes 0 (zero) in case of success, otherwise a non zero value. This can be a VB or an API error. To open a registtry key, use the function OpenRegKey . To close a regsitry or registry key, use CloseRegistry or CloseRegKey . You have to execute CloseRegistry before opening a new registry hive with the same object.

Parameters

lngHKey
is a predefined Handle to a registry hive. Use one of the HK_* Properties to assign this parameter.

strMachine
is a remote machine name, you want to connect to. But if you want to access a remote registry, only the hives HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_PERFORMANCE_DATA can be accessed. strMachine must be without leading backslashes ('\\'). If you omitt this parameter, the local registry will be opened.

See also:

HK_* Properties
OpenRegKey
RegKeyRoot
RegKeyRootHandle
RegMachine
CloseRegKey
CloseRegistry

Example (early binding):

Dim reg As New Registry
Dim lngResult As Long
'open the local registry
lngResult = OpenRegistry(reg.HK_LOCAL_MACHINE)
Debug.Print lngResult
Debug.Print reg.RegKeyRoot
Debug.Print reg.RegKeyRootHandle
Debug.Print reg.RegMachine
lngResult = reg.CloseRegistry

'open the remote registry
lngResult = OpenRegistry(reg.HK_LOCAL_MACHINE, 'OtherMachine')
Debug.Print lngResult
Debug.Print reg.RegKeyRoot
Debug.Print reg.RegKeyRootHandle
Debug.Print reg.RegMachine
lngResult = reg.CloseRegistry


OpenRegKey(...) As Long

Class Registry

Saturday, June 17, 2000

OpenRegKey(ByVal lngDesAccess As Long, [ByVal strKey As String]) As Long

Function

Return value:

Attention: You have to execute OpenRegistry before using this function without error. The function opens a registry key for reading or writing.

OpenRegKey initializes the properties
 RegKeyPath ,
 RegKeyName ,
of this class on every opening.

Additional, OpenRegKey initializes the properties
 RegKeyClass
RegKeyMaxClassLen
RegKeyMaxSubKeyLen
RegKeyMaxValueLen
RegKeyMaxValueNameLen
RegKeyNumSubKeys
RegKeyNumValues
RegKeyWriteTime
of this class - but only if K_QUERY_VALUE is a member of the parameter lngDesAccess ( K_READ includes K_QUERY_VALUE ).

The function returnes 0 (zero) in case of success, otherwise a non zero value. This can be a VB or an API error.

With the function, you can determine, whether a key exists, because if OpenRegKey returns 0, it exists. The return code 2 means 'File not found' and this means that the key does not exist (under the premise, you have enough rights to query the info).

To close a regsitry or registry key, use CloseRegistry or CloseRegKey . You have to execute CloseRegKey before opening a new registry key with the same object. To open more than one registry keys at the same time you have to use different object instances (Example 3). But you can open and close different keys within the same hive with the same object instance several times without closing the registry after each key (Example 4)

Parameters

lngDesAccess
is the parameter for the desired access. Use the K_* Properties to assign this parameter. If you only want to enumerate subkeys of the key for example, assign K_ENUMERATE_SUB_KEYS . You can combine more than one K_* Properties in this parameter with the '+' or 'Or' operator. The minimal access, you need for the functions and properties of this class is documented in this help.

strKey
is the key to open. Use the whole path, 'Software\Microsoft' with backslashs for example. But do not add the hive to the path ('HKEY_LOCAL_MACHINE' for example) because to open a key through function OpenRegKey without error, you have to execute the function OpenRegistry at first to initialize the hive to open. If you assign an empty string '', the hive specified in function OpenRegistry is opened. Parameter strKey is optional, because if you want to open a subkey member of collection RegSubKeys of this class, you do not have to assign the parameter strKey. In this case you have to execute the function through the object instance of the collection member (Example 2).

See also:

K_* Properties
OpenRegistry
CloseRegKey
CloseRegistry
RegKeyPath
RegKeyName
RegKeyClass
RegKeyMaxClassLen
RegKeyMaxSubKeyLen
RegKeyMaxValueLen
RegKeyMaxValueNameLen
RegKeyNumSubKeys
RegKeyNumValues
RegKeyWriteTime

Example 1 (early binding):

Dim reg As New Registry
Dim i As Integer

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_QUERY_VALUE, "Software\Dummy\Dummy10")

MsgBox reg.GetRegValueInfo("DummyValue")

Select Case reg.RegValueTypeStr

Case "R_BINARY", "R_RESOURCE_REQUIREMENTS_LIST", "R_FULL_RESOURCE_DESCRIPTOR", "R_RESOURCE_LIST"

For i = 0 To UBound(reg.regValue)

Debug.Print reg.regValue(i) & " " & i

Next

Case Else

Debug.Print reg.regValue

End Select

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()

Example 2 (early binding):

Dim reg As New Registry
Dim reg1 As Registry

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_QUERY_VALUE Or reg.K_ENUMERATE_SUB_KEYS, _
"Software\Dummy")

MsgBox reg.InitRegSubKeys

For Each reg1 In reg.RegSubKeys

MsgBox reg1.OpenRegKey(reg.K_QUERY_VALUE)
Debug.Print reg1.RegKeyWriteTime
MsgBox reg1.CloseRegKey

Next

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()

Example 3 (early binding):

Dim reg1 As New Registry
Dim reg2 As New Registry
Dim reg3 As Registry

MsgBox reg1.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg1.OpenRegKey(reg1.K_QUERY_VALUE, "Software\Dummy")

'... here the code for the key in object instance reg1 ....

'now open a additional key at the same time with a new object
'here you have to open the registry again because the hive is not initialized in this new object

MsgBox reg2.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg2.OpenRegKey(reg2.K_QUERY_VALUE Or reg2.K_ENUMERATE_SUB_KEYS, _
"Software\Dummy\Sub")

MsgBox reg2.InitRegSubKeys

For Each reg3 In reg2.RegSubKeys

'now open a key through a collection member
'you do not have to open the registry and you do not
'have to specify the key path

MsgBox reg3.OpenRegKey(reg.K_QUERY_VALUE)
Debug.Print reg3.RegKeyWriteTime
MsgBox reg3.CloseRegKey

Next

MsgBox reg2.CloseRegKey()
MsgBox reg2.CloseRegistry()

MsgBox reg1.CloseRegKey()
MsgBox reg1.CloseRegistry()

Example 4(early binding):

Dim reg As New Registry
Dim lngResult As Long

'open the first key - here you have to open registry and reg key
MsgBox "OpenRegistry " & reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_QUERY_VALUE Or reg.K_ENUMERATE_SUB_KEYS, _
"Software\DummyFirst")

'... now the code for the first key...

'closing only the key
MsgBox reg.CloseRegKey()

'open the second key - here, you have to open only the reg key
MsgBox reg.OpenRegKey(reg.K_QUERY_VALUE, _
"Software\DummySecond")

'... now the code for the second key...

'closing registry and reg key
MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


HK

Class Registry

Saturday, June 17, 2000

HK_CLASSES_ROOT As Long
HK_CURRENT_CONFIG As Long
HK_CURRENT_USER As Long
HK_LOCAL_MACHINE As Long
HK_PERFORMANCE_DATA As Long
HK_USERS As Long

Properties (read only)

Return value:

The properties are used like constants in functions or properties of this class to specify, which registry hive is to open or which hive is opened. If a function or property works with this values, it is documented.

See also:

RegKeyRootHandle
OpenRegistry

Example (early binding):

Dim reg As New Registry
Dim lngResult As Long

'open the local registry
lngResult = reg.OpenRegistry(reg.HK_LOCAL_MACHINE)

Debug.Print reg.RegKeyRootHandle
Debug.Print reg.HK_LOCAL_MACHINE

lngResult = reg.CloseRegistry


K

Class Registry

Saturday, June 17, 2000

K_ACCESS_SYSTEM_SECURITY As Long
K_ALL_ACCESS As Long
K_CREATE_LINK As Long
K_CREATE_SUB_KEY As Long
K_ENUMERATE_SUB_KEYS As Long
K_NOTIFY As Long
K_QUERY_VALUE As Long
K_READ As Long
K_READ_CONTROL As Long
K_SET_VALUE As Long
K_WRITE As Long
K_WRITE_DAC As Long
K_WRITE_OWNER As Long

Properties (read only)

Return value:

The properties are used like constants in functions or properties of this class to specify, with which rights you want to open a registry key. If a function uses this values, it is documented (like 'you can use the K_* propperties to assign the parameter'). It is documented at functions or properties in this class, with which minimal right you have to open a key for success.

K_ALL_ACCESS includes K_QUERY_VALUE, K_SET_VALUE, K_CREATE_SUB_KEY, K_ENUMERATE_SUB_KEYS, K_NOTIFY, K_CREATE_LINK

K_READ includes K_QUERY_VALUE, K_ENUMERATE_SUB_KEYS, K_NOTIFY

K_WRITE includes K_SET_VALUE, K_CREATE_SUB_KEY

See also:

OpenRegKey

Example (early binding):

Dim reg As New Registry
Dim lngResult As Long

'open the local registry
lngResult = reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
'open a key
lngResult = reg.OpenRegKey(reg.K_QUERY_VALUE, "Software\Dummy")

lngResult = reg.GetRegValueInfo("DummyValue")

Debug.Print reg.RegValueName
If reg.RegValueType = reg.R_DWORD Then

Debug.Print reg.RegValue

End If

lngResult = reg.CloseRegKey
lngResult = reg.CloseRegistry


RegMachine

Class Registry

Saturday, June 17, 2000

RegMachine As String

Property (read only)

Return value:

The property returns the name of the machine, where the registry was opened over the function OpenRegistry . If you have opened the local registry, the property returns the string 'local'. The property is initialized through the functions OpenRegKey and InitRegSubKeys .

See also:

OpenRegKey
InitRegSubKeys

Example (late binding):

Dim reg As Object
Dim reg1 As Object

Set reg = CreateObject("ntXdll.Registry")

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_READ, "Software\Dummy")

Debug.Print reg.RegMachine

MsgBox reg.InitRegSubKeys

For Each reg1 In reg.RegSubKeys

Debug.Print reg1.RegMachine

Next

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


CloseRegKey() As Long

Class Registry

Tuesday, December 05, 2000

CloseRegKey() As Long

Function

Return value:

The function returns 0 in case of success, otherwise a non zero value. This can be a VB or an API error.

The function closes the key, which was opened through function OpenRegKey of this class. Almost all functions and properties of this class only work, if a key is opened with OpenRegKey . If you already have opened a key with an object instance, you have to close the registry key with CloseRegKey before opening a key with this object again.

If you have to open more than one keys in the same registry hive (HKEY_LOCAL_MACHINE for example) you must not execute CloseRegistry each time before opening the new key. You only have to close the last opened key before opening the new one (see the example).

The function needs no parameters because the key which will be closed was defined by opening it with function OpenRegKey .

See also:

OpenRegistry
OpenRegKey
CloseRegistry

Example (early binding):

Dim reg As New Registry

'Open the local registry
MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)

'Opening the first key
MsgBox reg.OpenRegKey(reg.K_QUERY_VALUE, "Software\Dummy\Dummy10")

'.... now the code with any function or property of this class for the first key

'Close the first key
MsgBox reg.CloseRegKey()

'Opening the second key
MsgBox reg.OpenRegKey(reg.K_QUERY_VALUE, "Software\Dummy\Dummy11")

'.... now the code with any function or property of this class for the second key

'Close the second key
MsgBox reg.CloseRegKey()

'Close the registry
MsgBox reg.CloseRegistry()


CloseRegistry() As Long

Class Registry

Tuesday, December 05, 2000

CloseRegistry() As Long

Function

Return value:

The function returns 0 in case of success, otherwise a non zero value. This can be a VB or an API error.

The function closes the registry, which was opened through function OpenRegistry of this class. Mostly all functions and properties of this class only work, if a registry hive is opened with OpenRegistry . If you already have opened a registry with an object instance, you have to close the registry with CloseRegistry before opening a registry with this object again.

The function needs no parameters because the registry which will be closed was defined by opening it with function OpenRegistry .

See also:

OpenRegistry
OpenRegKey
CloseRegKey

Example (early binding):

Dim reg As New Registry

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)

MsgBox reg.OpenRegKey(reg.K_QUERY_VALUE, "Software\Dummy\Dummy10")

'.... now the code with any function or property of this class

MsgBox reg.CloseRegKey()

MsgBox reg.CloseRegistry()


InitRegSubKeys() As Long

Class Registry

Saturday, June 17, 2000

InitRegSubKeys() As Long

Function

Return value:

The function returns 0 in case of success, otherwise a non zero value. This can be a VB or an API error. The function initializes the collection RegSubKeys of this class. Each member of the collection will get the properties

RegKeyName
RegKeyPath
RegKeyClass
RegKeyWriteTime
RegKeyRoot
RegKeyRootHandle
RegMachine

initialized. You can access these properties only over the object instances of the collection members and not over the object from which InitRegSubKeys was called.To get further informations about the SubKeys or values within the SubKeys, you have to open them with OpenRegKey .

The function needs no parameters because you have to open a registry hive with function OpenRegistry and a reg key with function OpenRegKey before executing InitRegSubKeys. The minimal access for success is K_ENUMERATE_SUB_KEYS ( K_READ includes K_ENUMERATE_SUB_KEYS ). You can query the number of SubKeys before executing this function through property RegKeyNumSubKeys . This property is initialized through OpenRegKey . After executing the function, you can get the number of members via RegSubKeys .Count.

The members of the collection are indexed with the name of the SubKey. You can access each member of the collection with the 'For Each' structure or directly over the index (see the Example).

See also:

OpenRegistry
OpenRegKey
K_* Properties
RegSubKeys
RegKeyName
RegKeyPath
RegKeyClass
RegKeyWriteTime
RegKeyRoot
RegKeyRootHandle
RegMachine
CloseRegistry
CloseRegKey
RegKeyNumSubKeys

Example (early binding):

Dim reg As New Registry
Dim reg1 As Registry

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_QUERY_VALUE Or reg.K_ENUMERATE_SUB_KEYS, _
"Software\Dummy")

MsgBox reg.InitRegSubKeys

'accessing the members over the index
'index is the name of the SubKey
Debug.Print reg.RegSubKeys("SubDummy").RegKeyWriteTime

'accessing the members over the 'For Each'
For Each reg1 In reg.RegSubKeys

MsgBox reg1.OpenRegKey(reg.K_QUERY_VALUE)
Debug.Print reg1.RegKeyWriteTime
MsgBox reg1.CloseRegKey

Next

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


RegSubKeys

Class Registry

Saturday, June 17, 2000

RegSubKeys As Collection

Property (read only)

Return value:

The property returns a collection of class registry which offers informations about each subkey of a currently opened registry key. The property is initialized through the function InitRegSubKeys . To get information about which properties of each member are initialized by InitRegSubKeys and about how to call this function, see the help of this function. Each member of the collection is indexed by the name of the subkey. You can access each member directly through its index or over the 'For Each' structure.

See also:

InitRegSubKeys
RegKeyNumSubKeys

Example (early binding):

Dim reg As New Registry
Dim reg1 As Registry

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_QUERY_VALUE Or reg.K_ENUMERATE_SUB_KEYS, _
"Software\Dummy")

MsgBox reg.InitRegSubKeys

For Each reg1 In reg.RegSubKeys

MsgBox reg1.OpenRegKey(reg.K_READ_CONTROL)
MsgBox reg1.GetRegKeyOwner
Debug.Print reg1.RegKeyOwner
Debug.Print reg1.RegKeyOwnerDomain
MsgBox reg1.CloseRegKey

Next

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


RegKeyClass

Class Registry

Saturday, June 17, 2000

RegKeyClass As String

Property (read only)

Return value:

The property returns the class string of a registry key. The property is initialized through the function OpenRegKey or through InitRegSubKeys . In this case, each member of the collection RegSubKeys gets this property. You can define a class by creating a key. But usually, this information is not very important and currently, no classes are defined under NT.

See also:

RegKeyMaxClassLen
OpenRegKey
InitRegSubKeys

Example (early binding):

Dim reg As New Registry
Dim reg1 As Registry

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_QUERY_VALUE Or reg.K_ENUMERATE_SUB_KEYS, _
"Software\Dummy")

Debug.Print reg.RegKeyClass

MsgBox reg.InitRegSubKeys

For Each reg1 In reg.RegSubKeys

Debug.Print reg1.RegKeyClass

Next

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


RegKeyMaxClassLen

Class Registry

Saturday, June 17, 2000

RegKeyMaxClassLen As Long

Property (read only)

Return value:

The property returns the length, in characters, of the longest string specifying a subkey class of a registry key. The property is initialized through the function OpenRegKey . But usually, this information is not very important. You can determine, whether any subkey of a opened key has a class.

See also:

RegKeyClass
OpenRegKey

Example (early binding):

Dim reg As New Registry

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_READ, "Software\Dummy")

Debug.Print reg.RegKeyMaxClassLen

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


RegKeyMaxSubKeyLen

Class Registry

Saturday, June 17, 2000

RegKeyMaxSubKeyLen As Long

Property (read only)

Return value:

The function returns the length, in characters, of the key's subkey with the longest name. The property is initialized through the function OpenRegKey . But usually, this information is not very important. It is one way to determine, whether any subkey of a opened key exists (otherwise, the property is 0).

See also:

OpenRegKey
RegSubKeys
RegKeyName

Example (early binding):

Dim reg As New Registry

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_READ, "Software\Dummy")

Debug.Print reg.RegKeyMaxSubKeyLen

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


RegKeyMaxValueLen

Class Registry

Saturday, June 17, 2000

RegKeyMaxValueLen As Long

Property (read only)

Return value:

The property returns the length, in bytes, of the longest data component among the key's values of an opened key. The property is initialized through the function OpenRegKey . But usually, this information is not very important. It is one way to determine, whether any value of a opened key exists (otherwise, the property is 0).

See also:

OpenRegKey
RegValues
RegValue

Example (early binding):

Dim reg As New Registry

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_READ, "Software\Dummy")

Debug.Print reg.RegKeyMaxValueLen

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


RegKeyMaxValueNameLen

Class Registry

Saturday, June 17, 2000

RegKeyMaxValueNameLen As Long

Property (read only)

Return value:

The function returns the length, in characters, of the key's longest value name. The property is initialized through the function OpenRegKey . But usually, this information is not very important. It is one way to determine, whether any value of a opened key exists (otherwise, the property is 0).

See also:

OpenRegKey
RegValues
RegValue
RegValueName

Example (early binding):

Dim reg As New Registry

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_READ, "Software\Dummy")

Debug.Print reg.RegKeyMaxValueNameLen

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


RegKeyName

Class Registry

Saturday, June 17, 2000

RegKeyName As String

Property (read only)

Return value:

The property returns the Name of a key or a subkey of an opened key. The property is initialized through the function OpenRegKey and InitRegSubKeys . The name is the expression after the last backslash in the RegKeyPath.

See also:

OpenRegKey
InitRegSubKeys
RegKeyPath

Example (early binding):

Dim reg As New Registry
Dim reg1 As Registry

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_READ, "Software\Dummy")

Debug.Print reg.RegKeyName

MsgBox reg.InitRegSubKeys

For Each reg1 In reg.RegSubKeys

Debug.Print reg1.RegKeyName

Next

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


RegKeyNumSubKeys

Class Registry

Saturday, June 17, 2000

RegKeyNumSubKeys As Long

Property (read only)

Return value:

The property returns the number of subkeys existing in an opened key. You can proof, whether any subkey exists before executing the function InitRegSubKeys , which initializes the collection RegSubKeys . The property is initialized through the function OpenRegKey . After executing InitRegSubKeys , you can use RegSubKeys .Count.

See also:

OpenRegKey
InitRegSubKeys
RegSubKeys

Example (early binding):

Dim reg As New Registry

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_READ, "Software\Dummy")

Debug.Print reg.RegKeyNumSubKeys

MsgBox reg.InitRegSubKeys

Debug.Print reg.RegSubKeys.Count

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


RegKeyNumValues

Class Registry

Saturday, June 17, 2000

RegKeyNumValues As Long

Property (read only)

Return value:

The property returns the number of values existing in an opened key. You can proof, whether any value exists before executing the function InitRegValues , which initializes the collection RegValues . The property is initialized through the function OpenRegKey . After executing InitRegValues , you can use RegValues .Count.

See also:

OpenRegKey
InitRegSubKeys
RegSubKeys

Example (early binding):

Dim reg As New Registry

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_READ, "Software\Dummy")

Debug.Print reg.RegKeyNumValues

MsgBox reg.InitRegValues

Debug.Print reg.RegValues.Count

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


RegKeyPath

Class Registry

Saturday, June 17, 2000

RegKeyPath As String

Property (read only)

Return value:

The property returns the path of an opened key or a member of the collection RegSubKeys ('SOFTWARE\Microsoft\Internet Explorer' for example). The path is not including the hive of the opened registry (like HKEY_LOCAL_MACHINE - this information is in property RegKeyRoot ). The property is initialized through the functions OpenRegKey and InitRegSubKeys .

See also:

OpenRegKey
InitRegSubKeys
RegSubKeys
RegKeyRoot
RegKeyRootHandle

Example (late binding):

Dim reg As Object
Dim reg1 As Object

Set reg = CreateObject("ntXdll.Registry")

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_READ, "Software\Dummy")

Debug.Print reg.RegKeyPath

MsgBox reg.InitRegSubKeys

For Each reg1 In reg.RegSubKeys

Debug.Print reg1.RegKeyPath

Next

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


RegKeyRoot

Class Registry

Saturday, June 17, 2000

RegKeyRoot As String

Property (read only)

Return value:

The property returns the hive of an opened registry (remote or local) or a member of the collection RegSubKeys as a string value ('HKEY_LOCAL_MACHINE' for example). The property is initialized through the functions OpenRegistry and InitRegSubKeys . The root as the handle to the hive or to the hive of a remote computer is in property RegKeyRootHandle . You can create the 'whole' path of a key through combining the properties RegKeyRoot and RegKeyPath with a backslash.

See also:

OpenRegKey
InitRegSubKeys
RegSubKeys
RegKeyPath
RegKeyName
RegKeyRootHandle

Example (late binding):

Dim reg As Object
Dim reg1 As Object

Set reg = CreateObject("ntXdll.Registry")

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_READ, "Software\Dummy")

Debug.Print reg.RegKeyRoot

MsgBox reg.InitRegSubKeys

For Each reg1 In reg.RegSubKeys

Debug.Print reg1.RegKeyRoot

Next

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


RegKeyRootHandle

Class Registry

Saturday, June 17, 2000

RegKeyRootHandle As Long

Property (read only)

Return value:

The property returns the handle to a hive of an opened registry (remote or local) or a member of the collection RegSubKeys as a long value. The property is not very important for the usage of the class and it's only for addtional information. It is initialized through the functions OpenRegistry and InitRegSubKeys . The root as a string like 'HKEY_LOCAL_MACHINE' is in property RegKeyRoot .

See also:

OpenRegKey
InitRegSubKeys
RegSubKeys
RegKeyRoot
RegKeyPath
RegKeyName

Example (late binding):

Dim reg As Object
Dim reg1 As Object

Set reg = CreateObject("ntXdll.Registry")

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_READ, "Software\Dummy")

Debug.Print reg.RegKeyRootHandle

MsgBox reg.InitRegSubKeys

For Each reg1 In reg.RegSubKeys

Debug.Print reg1.RegKeyRootHandle

Next

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


RegKeyWriteTime

Class Registry

Saturday, June 17, 2000

RegKeyWriteTime As Date

Property (read only)

Return value:

The property returns the last time when the regkey was changed. A key is changed when a value or a subkey was changed or added. The property is initialized only through the function OpenRegKey .

See also:

OpenRegKey

Example (late binding):

Dim reg As Object
Dim reg1 As Object

Set reg = CreateObject("ntXdll.Registry")

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_READ, "Software\Dummy")

Debug.Print reg.RegKeyWriteTime

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


CreateRegSubKey(...) As Long

Class Registry

Saturday, June 17, 2000

CreateRegSubKey(strKeyName As String, [booVolatile As Boolean], [strClass As String]) As Long

Function

Return value:

The function creates a subkey of the currently opened key.

The key is created with the default security attributes of the parent opened key.

You have to open the registry hive where the subkey is to be created with function OpenRegistry of this class and you have to open the parent registry key with function OpenRegKey of this class. The minimum access to open the parent key is K_CREATE_SUB_KEY .
The function cannot create a key that is a direct child of HKEY_USERS or HKEY_LOCAL_MACHINE. The function creates no values. To set a value inside the created key, use the function SetRegValue of this class.
The function returns 0 (zero) in case of success, otherwise a nonzero value, that indicates a VB or an API error. The function returns -9999 if the subkey already exists. This is not a error but an internal return value of the function, that should indicate, that the key already exists.

Parameters

strKeyName
specifies the name of the subkey to create.

booVolatile
specifies whether the key should be volatile. The parameter is optional and False by default. A volatile key is a temporary key and exists only for the current NT session.

strClass
specifies the class, to which the key shoul belong to. The parameter is optional. By default, not class is specified. If the key already exists, this parameter is ignored. Currently, not registry classes are defined in the system of Windows NT. So, the parameter has only application specific meaning.

See also:

OpenRegistry
OpenRegKey
K_* Properties
HK_* Properties
SetRegValue

Example (late binding):

Dim reg As New Registry

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_CREATE_SUB_KEY, "Software\Dummy\DummyDummy12")

MsgBox reg.CreateRegSubKey("DummyCreated", , "ClassOf")

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


DeleteRegSubKey(...) As Long

Class Registry

Saturday, June 17, 2000

DeleteRegSubKey(strKeyName As String) As Long

Function

Return value:

The function deletes a subkey of the currently opened key.

The function returns 0 (zero) in case of success, otherwise a nonzero value, that indicates a VB or an API error. If the key does not exist, the function returns 2 (file not found). The function cannot delete a key with existing subkeys. Then, the function returns 5 (access denied). In this case, you have to recursively delete all subkeys of the subkey to delete (see the Example).
The function deletes the key with all values in it. To delete only a value, use the function DeleteRegValue of this class.
Before executing the function, you have to open the registry hive where the subkey is to be deleted with function OpenRegistry of this class and you have to open the parent registry key with function OpenRegKey of this class. The minimum access to open the parent key is K_DELETE .

Parameters

strKeyName
specifies the name of the subkey to delete.

See also:

OpenRegistry
OpenRegKey
K_* Properties
HK_* Properties
DeleteRegValue

Example (early binding):
Deleting a key with all subkeys (without error handling).
The code of an additional function 'RecursivDelete' is listed below.

Dim reg As New Registry
Dim lngResult As Long

lngResult = reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
lngResult = reg.OpenRegKey(reg.K_DELETE Or reg.K_ENUMERATE_SUB_KEYS Or _
reg.K_QUERY_VALUE, "SOFTWARE\Dummy\DummyDummy12\Dummy")

'at first delete all subkeys, which exist in the open key
'the code of the function is listed below
'the function works even if there is'nt any subkey
lngResult = RecursivDelete(reg)

lngResult = reg.CloseRegKey

lngResult = reg.OpenRegKey(reg.K_DELETE, "SOFTWARE\Dummy\DummyDummy12")
lngResult = reg.DeleteRegSubKey("Dummy")

lngResult = reg.CloseRegKey
lngResult = reg.CloseRegistry

Function RecursivDelete(ByVal oReg As Registry) As Long

Dim regSubKey As
    Registry
Dim lngResult As Long
Dim strKey As String

lngResult = oReg.InitRegSubKeys
For Each regSubKey In oReg.RegSubKeys

lngResult = regSubKey.OpenRegKey(regSubKey.K_QUERY_VALUE Or _
regSubKey.K_ENUMERATE_SUB_KEYS Or regSubKey.K_DELETE)
lngResult = RecursivDelete(regSubKey)

'now, the function
        returns and there exist no more subkey
strKey = regSubKey.RegKeyName
lngResult = regSubKey.CloseRegKey
lngResult = oReg.DeleteRegSubKey(strKey)
RecursivDelete = 0

Next

End Function


LoadRegKey(...) As Long

Class Registry

Saturday, June 17, 2000

LoadRegKey(strPath As String, strKeyName As String) As Long

Function

Return value:

The User, who executes the function, must have the Restore Privilege enabled (SE_RESTORE_NAME). Otherwise, error 1314 is returned ('A required privilege is not held by the client'). Look at the user manager - user rights - which users have this privilege enabled.

The function returns 0 in case of success, otherwise a non zero value. This can be a VB or an API error.

The function creates a subkey under HKEY_USERS or HKEY_LOCAL_MACHINE and stores registration information from a specified file into that subkey. This registration information is in the form of a hive. All changes, you do in the loaded key, will be saved immediately to the file.

You have to open a registry with function OpenRegistry of this class before executing LoadRegKey. Only HK_USERS and HK_LOCAL_MACHINE are valid parameters. You do not have to open a registry key with function OpenRegKey of this class because files can only be loaded into registry hives. Then, of course, you only have to execute CloseRegistry (and not CloseRegKey ) after using the function.

Parameters

strPath
specifies the path to the file. 'c:\temp\ntconfig.pol' for example loads a domain policy, which was saved to "c:\temp" before using it through this function (another way to document your policies than doing it with the tools poledit).

strKeyName
specifies the name of the key, that will be created after loading the file. The key will be loaded in the root of the registry hive, you opened with OpenRegistry .

Remarks

If you opened a remote registry with function OpenRegistry , then the path specified in strPath is relative to the remote computer.

To unload the registry key, use the function UnloadRegKey of this class.

See also:

OpenRegistry
HK_* Properties
CloseRegKey
CloseRegistry
UnloadRegKey

Example 1 (early binding):

Dim reg As New Registry

MsgBox "OpenRegistry " & reg.OpenRegistry(reg.HK_LOCAL_MACHINE)

MsgBox "LoadRegKey " & reg.LoadRegKey("c:\temp\dummy.txt", "dummy_load")

MsgBox reg.CloseRegistry()


UnloadRegKey(...) As Long

Class Registry

Saturday, June 17, 2000

UnloadRegKey(strKeyName As String) As Long

Function

Return value:

The User, who executes the function, must have the Restore Privilege enabled (SE_RESTORE_NAME). Otherwise, error 1314 is returned ('A required privilege is not held by the client'). Look at the user manager - user rights - which users have this privilege enabled.

The function returns 0 in case of success, otherwise a non zero value. This can be a VB or an API error.

The function unloads the specified registry key (parameter strKeyName) under HKEY_USERS or HKEY_LOCAL_MACHINE and its subkeys from the registry.

You have to open a registry with function OpenRegistry of this class before executing UnloadRegKey . Only HK_USERS and HK_LOCAL_MACHINE are valid parameters. You do not have to open a registry key with function OpenRegKey of this class because files can only be loaded into registry hives. Then, of course, you only have to execute CloseRegistry (and not CloseRegKey ) after using the function.

Parameter

strKeyName
specifies the name of the key, that should be unloaded. The key will be unloaded from the root of the registry hive, you opened with OpenRegistry .

Remarks

To load a file into a registry key, use the function LoadRegKey of this class.

See also:

OpenRegistry
HK_* Properties
CloseRegKey
CloseRegistry
LoadRegKey

Example 1 (early binding):

Dim reg As New Registry

MsgBox "OpenRegistry " & reg.OpenRegistry(reg.HK_LOCAL_MACHINE)

MsgBox "LoadRegKey " & reg.LoadRegKey("c:\temp\dummy.txt", "dummy_load")

MsgBox "LoadRegKey " & reg.UnloadRegKey("dummy_load")

MsgBox reg.CloseRegistry()


SaveRegKey(...) As Long

Class Registry

Saturday, June 17, 2000

SaveRegKey(strPath As String) As Long

Function

Return value:

Attention: the User, who executes the function, must have the Backup Privilege enabled (SE_BACKUP_NAME). Otherwise, error 1314 is returned ('A required privilege is not held by the client'). Look at the user manager - user rights - which users have this privilege enabled.

The function returns 0 in case of success, otherwise a non zero value. This can be a VB or an API error.

The function saves the key, you opened with function OpenRegKey of this class, and all of its subkeys and values to a new file. The new file will have the archive attribute. If the file already exists, an error will occur (183 - ERROR_ALREADY_EXISTS). The function saves only nonvolatile keys. It does not save volatile keys.

You have to open a registry with function OpenRegistry of this class before executing SaveRegKey. And you have to open the key, you want to save to a file with function OpenRegKey of this class. The minimal access to open the key is K_QUERY_VALUE .

Parameters

strPath
specifies the path to the file, you want to save the key to. If you opened a remote registry with function OpenRegistry , then the path specified in strPath is relative to the remote computer.

Remarks

To restore a registry key from a file, use the function RestoreRegKey of this class.

See also:

OpenRegistry
OpenRegKey
HK_* Properties
K_* Properties
CloseRegKey
CloseRegistry
RestoreRegKey

Example 1 (early binding):

Dim reg As New Registry

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)

MsgBox reg.OpenRegKey(reg.K_QUERY_VALUE, "Software\Dummy\Dummy10")

MsgBox reg.SaveRegKey("c:\temp\dummy.txt")

MsgBox reg.CloseRegKey()

MsgBox reg.CloseRegistry()


RestoreRegKey(...) As Long

Class Registry

Saturday, June 17, 2000

RestoreRegKey(strPath As String, [booVolatile As Boolean = False]) As Long

Function

Return value:

The User, who executes the function, must have the Restore Privilege enabled (SE_RESTORE_NAME). Otherwise, error 1314 is returned ('A required privilege is not held by the client'). Look at the user manager - user rights - which users have this privilege enabled.

The function returns 0 in case of success, otherwise a non zero value. This can be a VB or an API error.

The function reads the registry information in a specified file (parameter strPath) and copies it over the registry key, you opened with function OpenRegKey of this class. This registry information may be in the form of a key and multiple levels of subkeys. If any subkeys of the opened key are open, the function fails.

You have to open a registry with function OpenRegistry of this class before executing RestoreRegKey. And you have to open the key, you want to restore from a file with function OpenRegKey of this class. The minimal access to open the key is K_QUERY_VALUE .

Parameters

strPath
specifies the path to the file, you want to restore the key from. If you opened a remote registry with function OpenRegistry , then the path specified in strPath is relative to the remote computer.

booVolatile
specifies, whether the restored key should be volatile or not. The parameter is optional and False by default. A volatile key is temporary (memory only) and exists only for the current session.

Remarks

To save a registry key to a file, use the function SaveRegKey of this class.

Attention: This function replaces the keys and values below the opened key with the keys and values that are subsidiary to the top-level key in the file, no matter what the name of the top-level key in the file might be. The new information in the file specified by strPath overwrites the contents of the opened key, except for the key name.

See also:

OpenRegistry
OpenRegKey
HK_* Properties
K_* Properties
CloseRegKey
CloseRegistry
SaveRegKey

Example 1 (early binding):

Dim reg As New Registry

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)

MsgBox reg.OpenRegKey(reg.K_QUERY_VALUE, "Software\Dummy\Dummy10")

MsgBox "RestoreRegKey " & reg.RestoreRegKey("c:\temp\dummy.txt")

MsgBox reg.CloseRegKey()

MsgBox reg.CloseRegistry()


InitRegValues() As Long

Class Registry

Saturday, June 17, 2000

InitRegValues() As Long

Function

Return value:

The function returns 0 in case of success, otherwise a non zero value. This can be a VB or an API error. The function initializes the collection RegValues of the object instance from which the function is called. Each member of the collection will get the properties

RegValueName
RegValue
RegValueType
RegValueTypeStr

initialized. Only these properties of the collection members are initialized. The other propperties are empty. You must access the properties through the object instances of the collection members.

The function needs no parameters because you have to open a registry hive with function OpenRegistry and a reg key with function OpenRegKey before executing InitRegValues. This means, that the key, in which to enumerate the values is already defined. The minimal access for success is K_QUERY_VALUE ( K_READ includes K_QUERY_VALUE ).

You can query the number of Values before executing this function through property RegKeyNumValues . This property is initialized through OpenRegKey . After executing the function InitRegValues, you can get the number of members via RegValues .Count. The members of the collection are indexed with the name of the value. You can access each member of the collection with the 'For Each' structure or directly over the index (Example).

Remarks:

To get information of one special value, use the function GetRegValueInfo of this class.

See also:

OpenRegistry
OpenRegKey
K_* Properties
RegValues
RegValue
RegValueName
RegValueType
RegValueTypeStr
RegKeyNumValues
GetRegValueInfo

Example (early binding):

Dim reg As New Registry
Dim reg1 As Registry

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_QUERY_VALUE, "Software\Dummy")

MsgBox reg.InitRegValues

'accessing the members over the index
'index is the name of the Value
Debug.Print reg.RegValues("DummyValue").RegValueTypeStr

'accessing the members over the 'For Each'
For Each reg1 In reg.RegValues

Debug.Print reg1.RegValueTypeStr

Next

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


RegValues

Class Registry

Saturday, June 17, 2000

RegValues As Collection

Property (read only)

Return value:

The function returns a collection of class Registry. Each member has properties with informations about each value of a currently opened key. The collection is initialized through function InitRegValues of this class. Read the help to this function to get information about, which properties are initialized within each member object of this collection and how to call the function. Each member of the collection is indexed by the name of the value. You can access each member directly through its index or over the 'For Each' structure.

See also:

InitRegValues
RegKeyNumValues

Example (early binding):

Dim reg As New Registry
Dim reg1 As Registry

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_QUERY_VALUE, "Software\Dummy")

MsgBox reg.InitRegValues

'accessing the members over the index
'index is the name of the Value
Debug.Print reg.RegValues("DummyValue").RegValueTypeStr

'accessing the members over the 'For Each'
For Each reg1 In reg.RegValues

Debug.Print reg1.RegValueTypeStr

Next

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


GetRegValueInfo(...) As Long

Class Registry

Saturday, June 17, 2000

GetRegValueInfo(strName As String) As Long

Function

Return value:

The function returns 0 in case of success, otherwise a non zero value. This can be a VB or an API error.

The function initializes the properties

RegValue
RegValueName
RegValueType
RegValueTypeStr

of the object instance, from which the function is called. These properties representate informations about a value of a currently opened key. You have to open a registry hive with function OpenRegistry and a reg key with function OpenRegKey before executing GetRegValueInfo. The minimum access to open the key for success is K_QUERY_VALUE .

Parameters

strName
specifies the Name of the value to query the information from. This value must exist in the currently opened key. Otherwise error 2 ('file not found') will be returned by the function.

Remarks:

To get informations about each value of a currently opened key, use the function InitRegValues , which initializes a collection.

See also:

OpenRegistry
OpenRegKey
K_* Properties
HK_* Properties
RegValue
RegValueName
RegValueType
RegValueTypeStr
InitRegValues
RegValues

Example (early binding):

Dim reg As New Registry
Dim i As Integer

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_QUERY_VALUE, "Software\Dummy\Dummy10")

MsgBox reg.GetRegValueInfo("DummyValue")

Select Case reg.RegValueType

Case R_BINARY, R_RESOURCE_REQUIREMENTS_LIST, _
R_FULL_RESOURCE_DESCRIPTOR, R_RESOURCE_LIST

For i = 0 To UBound(reg.regValue)

Debug.Print reg.regValue(i) & " " & i

Next

Case Else

Debug.Print reg.regValue

End Select

Debug.Print reg.RegValueName
Debug.Print reg.RegValueType
Debug.Print reg.RegValueTypeStr

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


R

Class Registry

Saturday, June 17, 2000

R_SZ As Long
R_EXPAND_SZ As Long
R_MULTI_SZ As Long
R_DWORD As Long
R_DWORD_LITTLE_ENDIAN As Long
R_DWORD_BIG_ENDIAN As Long
R_BINARY As Long
R_RESOURCE_LIST As Long
R_RESOURCE_REQUIREMENTS_LIST As Long
R_FULL_RESOURCE_DESCRIPTOR As Long

Properties (read only)

Return value

This properties are used like constants in functions of the class Registry ( GetRegValueInfo , InitRegValues , SetRegValue , SetRegValueSZ ). Each of them representate a type of a registry value. Each registry value type stands for a type, you can assign through functions of this class:

Registry Value Type | VB Type:
R_BINARY | Array of bytes
R_DWORD | Long Number
R_DWORD_BIG_ENDIAN | Long Number
R_DWORD_LITTLE_ENDIAN | Long Number
R_SZ | String
R_EXPAND_SZ | String with '%' characters, that enclose an environment string
R_MULTI_SZ | Strings, seperated by a NULL character (vbNullChar)
R_RESOURCE_LIST | Array of bytes, but this value should not be set by applications
R_RESOURCE_REQUIREMENTS_LIST | Array of bytes, but this value should not be set by applications
R_FULL_RESOURCE_DESCRIPTOR | Array of bytes, but this value should not be set by applications

See also:

GetRegValueInfo
InitRegValues
SetRegValue
RegValueType
RegValueTypeStr
SetRegValueSZ

Example

Dim reg As New Registry
Dim i As Integer

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_QUERY_VALUE, "Software\Dummy\Dummy10")

MsgBox reg.GetRegValueInfo("DummyValue")

Select Case reg.RegValueType

Case reg.R_BINARY, reg.R_RESOURCE_REQUIREMENTS_LIST, _
reg.R_FULL_RESOURCE_DESCRIPTOR, reg.R_RESOURCE_LIST

For i = 0 To UBound(reg.regValue)

Debug.Print reg.regValue(i) & " " & i

Next

Case Else

Debug.Print reg.regValue

End Select

Debug.Print reg.RegValueName
Debug.Print reg.RegValueType
Debug.Print reg.RegValueTypeStr

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


RegValue

Class Registry

Saturday, June 17, 2000

RegValue As Variant

Property (read only)

Return value:

The property returns the data of a value in a currently opened key. The property is initialized through the functions InitRegValues and GetRegValueInfo of this class. Read the help to this functions, to get further informations. The property is of type variant. The type of data, which is returned, depends on the type of registry value, which is queried. See the following table, to see which data is returned dependend on the type of registry value:

Registry Value Type | Returned VB data type
R_BINARY | Array of bytes (use Ubound to determine the dimension)
R_DWORD | Long Number
R_DWORD_BIG_ENDIAN | Long Number
R_DWORD_LITTLE_ENDIAN | Long Number
R_SZ | String
R_EXPAND_SZ | String with '%' characters, that enclose an environment string. You can use the function ReplaceEnvVars of class Stringer to convert the string.
R_MULTI_SZ | String, including NULL characters (vbNullChar), that seperated multi strings. You can use the function InitSeperator of class Stringer to extract the strings of this string
R_RESOURCE_LIST | Array of bytes (use Ubound to determine the dimension)
R_RESOURCE_REQUIREMENTS_LIST | Array of bytes (use Ubound to determine the dimension)
R_FULL_RESOURCE_DESCRIPTOR | Array of bytes (use Ubound to determine the dimension)

You can determine the type of the queried value over the properties RegValueType or RegValueTypeStr of this class. These properties are initialized together with property RegValue.

See also:

RegValueType
RegValueTypeStr
GetRegValueInfo
InitRegSubKeys
ReplaceEnvVars
InitSeperator

Example (early binding):

Dim reg As New Registry
Dim i As Integer

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_QUERY_VALUE, "Software\Dummy\Dummy10")

MsgBox reg.GetRegValueInfo("DummyValue")

Select Case reg.RegValueType

Case R_BINARY, R_RESOURCE_REQUIREMENTS_LIST, _
R_FULL_RESOURCE_DESCRIPTOR, R_RESOURCE_LIST

'Get data from an array of bytes
For i = 0 To UBound(reg.regValue)

Debug.Print reg.regValue(i) & " " & i

Next

Case Else

'Get String and Long data
Debug.Print reg.regValue

End Select

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


RegValueName

Class Registry

Saturday, June 17, 2000

RegValueName As String

Property (read only)

Return value:

The property returns the name of a value in a currently opened key. The property is initialized through the functions InitRegValues and GetRegValueInfo of this class. Read the help to this functions, to get further informations.

See also:

GetRegValueInfo
InitRegSubKeys

Example (early binding):

Dim reg As New Registry, reg1 As Registry

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_QUERY_VALUE, "Software\Dummy\Dummy10")

MsgBox reg.InitRegValues

For Each reg1 In reg.RegValues

Debug.Print reg1.RegValueName

Next

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


RegValueType

Class Registry

Saturday, June 17, 2000

RegValueType As Long

Property (read only)

Return value:

The property returns the type of a value in a currently opened key. The property is initialized through the functions InitRegValues and GetRegValueInfo of this class. Read the help to this functions, to get further informations. The property is equal to one of the HK_* Properties of this class.

To get the type of a value as a string, use the property RegValueTypeStr of this class.

See also:

GetRegValueInfo
InitRegSubKeys
HK_* Properties
RegValueTypeStr

Example (early binding):

Dim reg As New Registry, reg1 As Registry

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_QUERY_VALUE, "Software\Dummy\Dummy10")

MsgBox reg.InitRegValues

For Each reg1 In reg.RegValues

Debug.Print reg1.RegValueType

Next

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


RegValueTypeStr

Class Registry

Saturday, June 17, 2000

RegValueTypeStr As String

Property (read only)

Return value:

The property returns the type of a value in a currently opened key as a string value. The property is initialized through the functions InitRegValues and GetRegValueInfo of this class. Read the help to this functions, to get further informations. The property can be one of the following strings:

'R_BINARY'
'R_DWORD'
'R_DWORD_BIG_ENDIAN'
'R_DWORD_LITTLE_ENDIAN'
'R_SZ'
'R_EXPAND_SZ'
'R_MULTI_SZ'
'R_RESOURCE_LIST'
'R_RESOURCE_REQUIREMENTS_LIST'
'R_FULL_RESOURCE_DESCRIPTOR'

To get the type of a value as a long data, use the property RegValueType of this class.

See also:

GetRegValueInfo
InitRegSubKeys
HK_* Properties
RegValueType

Example (late binding):

Dim reg As Object

Set reg = CreateObject("ntXdll.Registry")

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_QUERY_VALUE, "Software\Dummy\Dummy10")

MsgBox reg.GetRegValueInfo("DummyValue")

Debug.Print reg.RegValueTypeStr

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


SetRegValue(...) As Long

Class Registry

Saturday, June 17, 2000

SetRegValue(strName As String, lngType As Long, varData As Variant) As Long

Function

Return value:

The function sets a value of the currently opened key. If the value does not exist, the value will be created. If the value exists, it will be overwritten. You can determine, whether a value exists with the functions InitRegValues or GetRegValueInfo of this class ( GetRegValueInfo returns 2 if the value does not exist). To insert a string in a value of type R_MULTI_SZ , you have to query the value at first and then to modify.

You have to open the registry hive where the value is to be set OpenRegistry of this class and you have to open the parent registry key with function OpenRegKey of this class. The minimum access to open the parent key is K_SET_VALUE ( K_WRITE includes K_SET_VALUE )
The function returns 0 (zero) in case of success, otherwise a nonzero value, that indicates a VB or an API error.
The function initialzes the properties

RegValue
RegValueName
RegValueType
RegValueTypeStr

of this class. The properties are set in the instance of the object, you executed the function.

Parameters

strName
specifies the name of the value to set.

lngType
specifies the type of the value to set. You can use the R_* Properties to assign this parameter. For additional information look at the help of these properties.

varData
specifies the data of the value to wirte. The parameter is of type Variant. This means, you can assign numbers, strings or arrays of bytes to the parameter. You would be able to assign any type of parameter, but the type must be compatible to the type, you assigned in parameter lngType - otherwise an error occurs. If you assign R_DWORD to parameter lngType for example, you should assign a number to parameter varData. Following a listing of the R_* Properties and the Types of varData, that is compatible to this types:

Registry Value Type | Confirms with
R_BINARY | Array of bytes
R_DWORD | Long Number
R_DWORD_BIG_ENDIAN | Long Number
R_DWORD_LITTLE_ENDIAN | Long Number
R_SZ | String
R_EXPAND_SZ | String with '%' characters, that enclose an environment string
R_MULTI_SZ | Strings, seperated by a NULL character (vbNullChar)
R_RESOURCE_LIST | Array of bytes, but this value should not be set by system
R_RESOURCE_REQUIREMENTS_LIST | Array of bytes, but this value should not be set by system
R_FULL_RESOURCE_DESCRIPTOR | Array of bytes, but this value should not be set by system

See also:

OpenRegistry
OpenRegKey
K_* Properties
HK_* Properties
R_* Properties
InitRegValues
GetRegValueInfo
RegValue
RegValueName
RegValueType
RegValueTypeStr

Example (early binding):

Dim lngData As Long
Dim bteData() As Byte
Dim strData As String
Dim lngResult As Long
Dim reg As New Registry
Dim i As Integer

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_SET_VALUE, "Software\Dummy\dummy10")

strData = "data1" & vbNullChar & "data2" & vbNullChar & "data3" & vbNullChar
lngData = 123456789
ReDim bteData(255)
bteData = "This is the data in bytes which to set to a registry value"

MsgBox reg.SetRegValue("reg_sz", reg2.R_SZ, strData)
Debug.Print reg.regValue
Debug.Print reg.RegValueName
Debug.Print reg.RegValueType
Debug.Print reg.RegValueTypeStr

MsgBox reg.SetRegValue("reg_expand_sz", reg2.R_EXPAND_SZ, strData)
Debug.Print reg.regValue
Debug.Print reg.RegValueName
Debug.Print reg.RegValueType
Debug.Print reg.RegValueTypeStr

MsgBox reg.SetRegValue("reg_multi_sz", reg2.R_MULTI_SZ, strData)
Debug.Print reg.regValue
Debug.Print reg.RegValueName
Debug.Print reg.RegValueType
Debug.Print reg.RegValueTypeStr

MsgBox reg.SetRegValue("reg_dword", reg2.R_DWORD, lngData)
Debug.Print reg.regValue
Debug.Print reg.RegValueName
Debug.Print reg.RegValueType
Debug.Print reg.RegValueTypeStr

MsgBox reg.SetRegValue("reg_little_endian", reg.R_DWORD_LITTLE_ENDIAN, lngData)
Debug.Print reg.regValue
Debug.Print reg.RegValueName
Debug.Print reg.RegValueType
Debug.Print reg.RegValueTypeStr

MsgBox reg.SetRegValue("reg_big_endian", reg.R_DWORD_BIG_ENDIAN, lngData)
Debug.Print reg.regValue
Debug.Print reg.RegValueName
Debug.Print reg.RegValueType
Debug.Print reg.RegValueTypeStr

MsgBox reg.SetRegValue("reg_binary", reg2.R_BINARY, bteData)
For i = 0 To UBound(reg.regValue)

Debug.Print reg.regValue(i)

Next
Debug.Print reg.RegValueName
Debug.Print reg.RegValueType
Debug.Print reg.RegValueTypeStr

'Following, there are three RESOURCE descriptors values created. This is only for test in a
'temporary test key. Normally, this values are set by the system and should not changed by applications
'The RESOURCE descriptors, created in this example cannot be read by system or REGEDT32.EXE, because
'they are filled with self created arrays of bytes.
MsgBox reg.SetRegValue("reg_res_list", reg.R_RESOURCE_LIST, bteData)
For i = 0 To UBound(reg.regValue)

Debug.Print reg.regValue(i)

Next
Debug.Print reg.RegValueName
Debug.Print reg.RegValueType
Debug.Print reg.RegValueTypeStr

MsgBox reg.SetRegValue("reg_res_req_list", reg.R_RESOURCE_REQUIREMENTS_LIST, bteData)
For i = 0 To UBound(reg.regValue)

Debug.Print reg.regValue(i)

Next
Debug.Print reg.RegValueName
Debug.Print reg.RegValueType
Debug.Print reg.RegValueTypeStr

MsgBox reg.SetRegValue("reg_res_descriptor", reg.R_FULL_RESOURCE_DESCRIPTOR, bteData)
For i = 0 To UBound(reg.regValue)

Debug.Print reg.regValue(i)

Next
Debug.Print reg.RegValueName
Debug.Print reg.RegValueType
Debug.Print reg.RegValueTypeStr

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


DeleteRegValue(...) As Long

Class Registry

Saturday, June 17, 2000

DeleteRegValue(strValueName As String) As Long

Function

Return value:

The function deletes a value of the currently opened key.

The function returns 0 (zero) in case of success, otherwise a nonzero value, that indicates a VB or an API error. If the value does not exist, the function returns 2 (file not found). To delete a registry key DeleteRegSubKey of this class.
Before executing the function, you have to open the registry hive where the value is to be deleted with function OpenRegistry of this class and you have to open the parent registry key with function OpenRegKey of this class. The minimum access to open the parent key is K_SET_VALUE ( K_WRITE includes K_SET_VALUE )

Parameters

strValueName
specifies the name of the value to delete.

See also:

OpenRegistry
OpenRegKey
K_* Properties
HK_* Properties

Example (early binding):

Dim reg As New Registry

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_SET_VALUE, "Software\Dummy\DummyDummy12")

MsgBox reg.DeleteRegValue("dummy")

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


GetRegValueSZ(...) As String

Class Registry

Saturday, June 17, 2000

GetRegValueSZ(strComputer As String, strKey As String, strValue As String, strDefault As String) As String

Function

Return value

The function now is obsolet. Please use GetRegValueInfo or InitRegValues to get the data of registry values.

Returns the value of a REG_SZ, REG_EXPAND_SZ or REG_MULTI_SZ. You can remotely read the registry by assigning the ComputerName with parameter strComputer (without leading "\\"). If strComputer is an empty string, the local registry will be used. Assign the path strKey and the value strValue. If the value or key doesn't exist, parameter strDefault will be returned. Several lines in a MULTI_SZ value will be seperated by "^" like value1^value2^value3....

See also:

GetRegValueInfo
InitRegValues

Example

Dim reg As Object, s As String
Set reg = CreateObject("ntXdll.Registry")
s = reg.GetRegValueSZ ("", "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "Shell", _
"Unknown error")
s will have the value "Explorer.exe"


SetRegValueSZ(...) As Long

Class Registry

Saturday, June 17, 2000

SetRegValueSZ(strComputer As String, strKey As String, strValueName As String, strValue As String, lngType As Long) As Long

Function

Return value

The function now is obsolet. Please use SetRegValue to set the data of a registry value.

0 if the function failes, otherwise 1.

Sets a REG_SZ, EXPAND_SZ or MULTI_SZ value in a local or remote registry. If strComputer is an empty string, the local registry will be used, else assign the strComputer without leading "\\". lngType can be one of the properties R_SZ, R_EXPAND_SZ or R_MULTI_SZ of the class Registry. Several lines in MULTI_SZ must be seperated by vbCrLf. If the key or the value does not exist, it will be created. Existing keys or values will be overwritten.

See also:

SetRegValue
R_SZ, R_EXPAND_SZ, R_MULTI_SZ, R_DWORD, R_BINARY

Example1

Dim reg As Object, l As Long
Set reg = CreateObject("ntXdll.Registry")
l = reg.SetRegValueSZ ("", "HKEY_LOCAL_MACHINE\Software\MySoft", "Parameter1", "Parameter", reg.R_SZ)

Example2

Dim reg As Object, l As Long
Set reg = CreateObject("ntXdll.Registry")
l = reg.SetRegValueSZ ("", "HKEY_LOCAL_MACHINE\Software\MySoft", "Parameters", "Parameter1" & vbCrLf & _
"Parameter2", reg.R_MULTI_SZ)


GetRegKeyOwner() As Long

Class Registry

Saturday, June 17, 2000

GetRegKeyOwner As Long

Function

Return value:

The function initializes the properties

RegOwner
RegOwnerDomain

of the object instance, from which the function is called. These properties represent informations about the owner of a currently opened key. Before executing GetRegKeyOwner, you have to open a registry hive with function OpenRegistry and you have to open the reg key to query the owner from with function OpenRegKey (through the object instance, from which you want to execute the function). The minimum access to open the key for success is K_READ_CONTROL .

The function needs no parameters. The reg key to get the information from is already defined, because it was opened with function OpenRegKey .

The function returns 0 in case of success, otherwise a non zero value. This can be a VB or an API error.

Remarks:

In this version of ntXdll, taking ownership (writing the registry security) is not supported.To get the reg key security, use the function InitRegRights of this class. To get the auditing rules of a reg key, use the function InitRegAudits . To get the primary group of a currently opened key, use function GetRegKeyPrimaryGroup .

See also:

OpenRegistry
OpenRegKey
HK_* Properties
K_* Properties
RegOwner
RegOwnerDomain
InitRegRights
InitRegAudits
GetRegKeyPrimaryGroup

Example (late binding):

Dim reg As Object

Set Reg = CreateObject("ntXdll.Registry")

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_READ_CONTROL, "Software\Dummy")

MsgBox reg.GetRegKeyOwner

MsgBox reg.RegOwner
MsgBox reg.RegOwnerDomain

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


RegOwner

Class Registry

Saturday, June 17, 2000

RegOwner As String

Property (read only)

Return value:

The property returns the name (UserID) of the owner of a currently opened key. The property is initialized through the function GetRegKeyOwner of this class. Read the help to this functions, to get further informations.

Remarks:

To get the domain of the returned owner, use the property RegOwnerDomain of this class.

See also:

GetRegKeyOwner
RegOwnerDomain

Example (early binding):

Look at the example to function GetRegKeyOwner


RegOwnerDomain

Class Registry

Saturday, June 17, 2000

RegOwnerDomain As String

Property (read only)

Return value:

The property returns the domain of the owner of a currently opened key. The property is initialized through the function GetRegKeyOwner of this class. Read the help to this functions, to get further informations.

Remarks:

To get the name (UserID) of the keys owner, use the property RegOwner of this class.

See also:

GetRegKeyOwner
RegOwner

Example (early binding):

Look at the example to function GetRegKeyOwner


GetRegKeyPrimaryGroup() As Long

Class Registry

Saturday, June 17, 2000

GetRegKeyPrimaryGroup() As Long

Function

Return value:

The function initializes the properties

RegPrimaryGroup
RegPrimaryGroupDomain

of the object instance, from which the function is called. These properties representate informations about the primary group of a currently opened key. Before executing GetRegKeyPrimaryGroup, you have to open a registry hive with function OpenRegistry and you have to open the reg key to query the group from with function OpenRegKey (through the object instance, from which you want to execute the function). The minimum access to open the key for success is K_READ_CONTROL .

The function needs no parameters. The reg key to get the information from is already defined, because it was opened with function OpenRegKey .

The function returns 0 in case of success, otherwise a non zero value. This can be a VB or an API error.

Remarks:

To get the reg key security, use the function InitRegRights of this class. To get the auditing rules of a reg key, use the function InitRegAudits . To get the owner of a currently opened key, use function GetRegKeyOwner .

See also:

OpenRegistry
OpenRegKey
K_* Properties
HK_* Properties
RegPrimaryGroup
RegPrimaryGroupDomain
InitRegRights
InitRegAudits
GetRegKeyOwner

Example (late binding):

Dim reg As Object

Set reg = CreateObject("ntXdll.Registry")

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_READ_CONTROL, "Software\Dummy")

MsgBox reg.GetRegKeyPrimaryGroup

MsgBox reg.RegPrimaryGroup
MsgBox reg.RegPrimaryGroupDomain

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


RegPrimaryGroup

Class Registry

Saturday, June 17, 2000

RegPrimaryGroup As String

Property (read only)

Return value:

The property returns the name of the primary group of a currently opened key. The property is initialized through the function GetRegKeyPrimaryGroup of this class. Read the help to this functions, to get further informations.

Remarks:

To get the domain of the returned group, use the property RegPrimaryGroupDomain of this class.

See also:

GetRegKeyPrimaryGroup
RegPrimaryGroupDomain

Example (early binding):

Look at the example to function GetRegKeyPrimaryGroup


RegPrimaryGroupDomain

Class Registry

Saturday, June 17, 2000

RegPrimaryGroupDomain As String

Property (read only)

Return value:

The property returns the domain of the primary group of a currently opened key. The property is initialized through the function GetRegKeyPrimaryGroup of this class. Read the help to this functions, to get further informations.

Remarks:

To get the name of the keys primary group, use the property RegPrimaryGroup of this class.

See also:

GetRegKeyPrimaryGroup
RegPrimaryGroup

Example (early binding):

Look at the example to function GetRegKeyPrimaryGroup


InitRegRights() As Long

Class Registry

Saturday, June 17, 2000

InitRegRights() As Long

Function

Return value:

The function returns 0 in case of success, otherwise a non zero value. This can be a VB or an API error. The function initializes the collection RegRights of this class. This collection with its members contains informations about the access rights of a currently opened key. Each member of the collection will get the properties

RegRightUser
RegRightUserDomain
RegRightStr
RegRightTypeStr
RegRightFlagsStr

initialized. Read the help to this properties to get further informations about what they mean. The members of collection RegRights have only these properties initialized. The other properties of the class are empty. You can access these properties only over the object instances of the collection members and not over the object from which InitRegRights was called.

You have to open a registry hive with function OpenRegistry and a registry key with function OpenRegKey before executing InitRegRights. The function needs no parameters because the key, you want to get the informations from, is already defined by opening it with OpenRegKey .

The minimal access for success is K_READ_CONTROL . You can get the number of members of the collection via RegRights .Count. The members of the collection are indexed with the character '#', followed by an unique number (e.g. '#3'). You access each member of the collection with the 'For Each' structure.

Remarks

In this version of ntXdll, setting registry access rights is not supported.

See also:

OpenRegistry
OpenRegKey
K_* Properties
HK_* Properties
RegRights
RegRightUser
RegRightUserDomain
RegRightStr
RegRightTypeStr
RegRightFlagsStr
CloseRegKey
CloseRegistry

Example (early binding):

Dim reg As New Registry, reg1 As Registry

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_READ_CONTROL, "Software\Dummy")

MsgBox reg.InitRegRights

Debug.Print reg.RegRights.Count

For Each reg1 In reg.RegRights

Debug.Print reg1.RegRightTypeStr
Debug.Print reg1.RegRightUserDomain & "\" & reg1.RegRightUser
Debug.Print reg1.RegRightStr & " " & reg1.RegRightFlagsStr

Next

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


InitRegAudits() As Long

Class Registry

Saturday, June 17, 2000

InitRegAudits() As Long

Function

Return value:

The User, who executes the function, must have the Security Privilege enabled (SE_SECURITY_NAME). Otherwise, error 1314 is returned ('A required privilege is not held by the client'). Look at the user manager - user rights, which users have this privilege enabled.

The function returns 0 in case of success, otherwise a non zero value. This can be a VB or an API error. The function initializes the collection RegAudits of this class. This collection with its members contains informations about the auditing rules of a currently opened key. Each member of the collection will get the properties

RegRightUser
RegRightUserDomain
RegRightStr
RegRightTypeStr
RegRightFlagsStr

initialized. If you have already read the help to function InitRegRights , you know, that these properties are also initialized by this function. The properties can store informations about registry rights or informations about registry audits (but not at the same time), because this informations are very similar. Read the help to this properties to get further informations about what they mean.

The members of collection RegAudits have only these properties initialized. The other properties of the class are empty. You can access these properties only over the object instances of the collection members and not over the object from which InitRegAudits was called.

You have to open a registry hive with function OpenRegistry and a registry key with function OpenRegKey before executing InitRegAudits. The function needs no parameters because the key, you want to get the informations from, is already defined by opening it with OpenRegKey .

The minimal access for success is K_ACCESS_SYSTEM_SECURITY . You can get the number of members of the collection via RegAudits .Count. The members of the collection are indexed with the character '#', followed by an unique number (e.g. '#3'). You access each member of the collection with the 'For Each' structure.

Remarks

In this version of ntXdll, setting registry audits is not supported.

See also:

OpenRegistry
OpenRegKey
K_* Properties
HK_* Properties
RegRights
RegRightUser
RegRightUserDomain
RegRightStr
RegRightTypeStr
RegRightFlagsStr
CloseRegKey
CloseRegistry

Example (early binding):

Dim reg As New Registry, reg1 As Registry

MsgBox reg.OpenRegistry(reg.HK_LOCAL_MACHINE)
MsgBox reg.OpenRegKey(reg.K_ACCESS_SYSTEM_SECURITY, "Software\Dummy")

MsgBox reg.InitRegAudits

Debug.Print reg.RegAudits.Count

For Each reg1 In reg.RegAudits

Debug.Print reg1.RegRightTypeStr
Debug.Print reg1.RegRightUserDomain & "\" & reg1.RegRightUser
Debug.Print reg1.RegRightStr & " " & reg1.RegRightFlagsStr

Next

MsgBox reg.CloseRegKey()
MsgBox reg.CloseRegistry()


RegRights

Class Registry

Saturday, June 17, 2000

RegRights As Collection

Property (read only)

Return value:

The function returns a collection of class Registry. Each member has only the properties

RegRightUser
RegRightUserDomain
RegRightStr
RegRightTypeStr
RegRightFlagsStr

filled with information. The other properties of the class are empty.

The collection is initialized through the function InitRegRights of this class. Each member has properties with informations about how the access rights are defined at a currently opened key. Each member of the collection is indexed by the character '#', followed by an unique number (e.g. '#3'). You access each member of the collection with the 'For Each' structure.

See also:

InitRegRights
RegRightUser
RegRightUserDomain
RegRightStr
RegRightTypeStr
RegRightFlagsStr

Example:

Look at the example to function InitRegRights


RegAudits

Class Registry

Saturday, June 17, 2000

RegAudits As Collection

Property (read only)

Return value:

The function returns a collection of class Registry. Each member has only the properties

RegRightUser
RegRightUserDomain
RegRightStr
RegRightTypeStr
RegRightFlagsStr

filled with information. The other properties of the class are empty.

The collection is initialized through the function InitRegAudits of this class.Each member has properties with informations about how the auditing rules are defined at a currently opened key. Each member of the collection is indexed by the character '#', followed by an unique number (e.g. '#3'). You access each member of the collection with the 'For Each' structure.

See also:

InitRegAudits
RegRightUser
RegRightUserDomain
RegRightStr
RegRightTypeStr
RegRightFlagsStr

Example:

Look at the example to function InitRegAudits


RegRightUser

Class Registry

Saturday, June 17, 2000

RegRightUser As String

Property (read only)

Return value:

The property can only be accessed over a member object of collection RegRights or RegAudits . These collections are initialized through the functions InitRegRights or InitRegAudits . Dependend on the collection, the object is a member of, the property specifies either a user or group who has access rights defined on the currently opened key or it specifies a user or group, for which access auditing rules are defined. To get further access informations about the opened key, look at the other RegRight* Properties of this class.

See also:

InitRegRights
RegRights
InitRegAudits
RegAudits
RegRightUserDomain
RegRightStr
RegRightTypeStr
RegRightFlagsStr

Example (early binding):

Look at the examples to functions InitRegRights and InitRegAudits .


RegRightUserDomain

Class Registry

Saturday, June 17, 2000

RegRightUserDomain As String

Property (read only)

Return value:

The property can only be accessed over a member object of collection RegRights or RegAudits . These collections are initialized through the functions InitRegRights or InitRegAudits . Dependend on the collection, the object is a member of, the property specifies either the domain of a user or group who has access rights defined on the currently opened key or it specifies the domain of a user or group, for which access auditing rules are defined. To get further access informations about the opened key, look at the other RegRight* Properties of this class.

See also:

InitRegRights
RegRights
InitRegAudits
RegAudits
RegRightUser
RegRightStr
RegRightTypeStr
RegRightFlagsStr

Example (early binding):

Look at the examples to functions InitRegRights and InitRegAudits .


RegRightStr

Class Registry

Saturday, June 17, 2000

RegRightStr As String

Property (read only)

Return value:

The property can only be accessed over a member object of collection RegRights or RegAudits . These collections are initialized through the functions InitRegRights or InitRegAudits . Dependend on the collection, the object is a member of, the property specifies either the access rights of a user or group to the currently opened key or it specifies the access auditing rules of a user or group, for which access auditing rules are defined on the opened key.

If the object is a member of RegRights , the property can be any combination of the following characters (or it can be the string 'FULL', 'READ' or 'ZERO' if access is denied to the specified user or group):

'Q' | the right to query values in the opened key
'S' | the right to set values in the opened key
'C' | the right to create subkeys in the opened key
'E' | the right to enumerate subkeys in the opened key
'N' | the right to set notifications to the opened key
'L' | the right to create a link in the opened key
'D' | the right to delete the opened key
'P' | the right to define the ACL on the opened key
'O' | the right to take ownership of the opened key
'R' | the right to read the ACL of the opened key
'QENR' | for example is equal to 'READ' access

If the object is a member of RegAudits , the property is equal to a member of RegRights , but the character 'O' is missing because taking ownership can't be audited. 'FULL' and 'READ' is also missing because only discretionary rights can be audited.

To get further access informations about the opened key, look at the other RegRight* Properties of this class.

See also:

InitRegRights
RegRights
InitRegAudits
RegAudits
RegRightUser
RegRightUserDomain
RegRightTypeStr
RegRightFlagsStr

Example (early binding):

Look at the examples to functions InitRegRights and InitRegAudits .


RegRightTypeStr

Class Registry

Saturday, June 17, 2000

RegRightTypeStr As String

Property (read only)

Return value:

The property can only be accessed over a member object of collection RegRights or RegAudits . These collections are initialized through the functions InitRegRights or InitRegAudits . Dependend on the collection, the object is a member of, the property specifies either whether the access is allowed or denied to the currently opened key or it specifies that the ACE defines a system audit ACE.

If the object is a member of RegRights , the property can be one of the following strings:

'ACCESS_ALLOWED_ACE_TYPE'
'ACCESS_DENIED_ACE_TYPE'

If the object is a member of RegAudits , the property is the following string:

'SYSTEM_AUDIT_ACE_TYPE'

To get further access informations about the opened key, look at the other RegRight* Properties of this class.

See also:

InitRegRights
RegRights
InitRegAudits
RegAudits
RegRightUser
RegRightStr
RegRightUserDomain
RegRightFlagsStr

Example (early binding):

Look at the examples to functions InitRegRights and InitRegAudits .


RegRightFlagsStr

Class Registry

Saturday, June 17, 2000

RegRightFlagsStr As String

Property (read only)

Return value:

The property can only be accessed over a member object of collection RegRights or RegAudits . These collections are initialized through the functions InitRegRights or InitRegAudits . Dependend on the collection, the object is a member of, the property specifies either the rules of inheritance of the access rights o key.

If the object is a member of RegRights , the property can be any combination of the following strings (seperated by a semicolon):

String | Explanation from MSDN®
'CONTAINER_INHERIT_ACE' | Non-container child objects inherit the ACE (Access Control Entry) as an effective ACE. For child objects that are containers, the ACE is inherited as an inherit-only ACE unless the NO_PROPAGATE_INHERIT_ACE bit flag is also set.
'INHERIT_ONLY_ACE' | Indicates an inherit-only ACE which does not control access to the object to which it is attached. If this flag is not set, the ACE is an effective ACE which controls access to the object to which it is attached. Both effective and inherit-only ACEs can be inherited depending on the state of the other inheritance flags
'NO_PROPAGATE_INHERIT_ACE' | If the ACE is inherited by a child object, the system clears the OBJECT_INHERIT_ACE and CONTAINER_INHERIT_ACE flags in the inherited ACE. This prevents the ACE from being inherited by subsequent generations of objects
'OBJECT_INHERIT_ACE' | Non-container child objects inherit the ACE as an effective ACE. For child objects that are containers, the ACE is inherited as an inherit-only ACE unless the NO_PROPAGATE_INHERIT_ACE bit flag is also set.

If the object is a member of RegAudits , the property is one of the following strings:

'FAILED_ACCESS_ACE_FLAG'
'SUCCESSFUL_ACCESS_ACE_FLAG'

To get further access informations about the opened key, look at the other RegRight* Properties of this class.

See also:

InitRegRights
RegRights
InitRegAudits
RegAudits
RegRightUser
RegRightStr
RegRightTypeStr
RegRightUserDomain

Example (early binding):

Look at the examples to functions InitRegRights and InitRegAudits .


Class Eventer

Saturday, June 17, 2000

Class Eventer

Class Eventer gives you a lot of functionality to read, write, save or clear the eventlog of the local or a remote computer.

You can read the eventlog with function InitReadEvents . This function initializes a collection Events , which contains the member objects. Each of these objects represents an event. You can access the properties of these objects only through the object instances of the collection members (in this version of ntXdll, you cannot access the properties of one single event).

In function InitReadEvents , you can specify different filters, to limit the count of events in the collection.

In this version of ntXdll, the message-, category- and parameter message files must be present on the local machine when you want to receive the hole description of an event on a remote machine.

There are some additional functions, which you can use seperate and which require no Eventer objects. These functions are:

CleanEventLog
SaveEventLog
WriteEvent

You get detailed information in the help of each function or property.


InitReadEvents (...) As Long

Class Eventer

Tuesday, December 05, 2000

InitReadEvents

([strConnect As String],
[strEventSource As String],
[dteFrom As Date],
[dteUntil As Date],
[lngType As Long],
[strSource As String],
[strCategory As String],
[strDescription As String],
[strDataString As String],
[strComputer As String],
[strUser As String],
[lngID As Long],
[strFile As String])

As Long

Function

Return value

Returns 0 in case of success, otherwise a non zero value which can be an Visual Basic Error or an error from an API. The function initializes the Event Properties and the collection Events .

The function always queries the whole eventlog. But if you assign any filter, only the filters are added to the collection. So, the performance is not so high like in the NT event viewer, where all events appear at once.

If you use the filters lngID, lngType, dteFrom, dteUntil, strSource, strComputer, strUser and / or strCategory (in this sequence), the function works faster, because this filters are analyzed before setting the other properties.

Parameters (all optional)

strConnect (optional)
Specifies the computer on which the functions are to execute. If you omitt this paramater, the local machine is used.

strEventSource (optional)
Specifies the source of eventlog from which the events are to enumerate. You can use the SOURCE* Properties of this class to assign this parameter or use the strings "Application", "Security" or "System". The default value is "Application". You also can assign a user defined event source. If this source does not exist, the Application log will be opened.

dteFrom (optional)
If you assign this parameter, only events written later as dteFrom are added to the collection. By default, all dates are enumerated.

dteUntil (optional)
If you assign this parameter, only events written earlier as dteUntil are added to the collection. By default, all dates are enumerated.

lngType (optional)
You can filter the evnts by using this parameter. Use the TYPE* Properties of this class. You can combine several types with the operator "Or". By default, all types are enumerated.

strSource (optional)
You can filter the events by declaring this parameter. By default, all sources are enumerated. You can use wildcards ("*" or "?") in this parameter.

strCategory (optional)
You can filter the events by declaring this parameter. By default, all categories are enumerated. You can use wildcards ("*" or "?") in this parameter.

strDescription (optional)
You can filter the events by declaring this parameter. By default, all descriptions are enumerated. You can use wildcards ("*" or "?") in this parameter.

strDataString (optional)
You can filter the events by declaring this parameter. By default, all data strings are enumerated. You can use wildcards ("*" or "?") in this parameter.

strComputer (optional)
You can filter the events by declaring this parameter. By default, all computer entries are enumerated. You can use wildcards ("*" or "?") in this parameter.

strUser (optional)
You can filter the events by declaring this parameter. By default, all user entries are enumerated. You can use wildcards ("*" or "?") in this parameter.

lngID (optional)
You can filter the events by declaring this parameter. By default, all event IDs are enumerated. You only can assign a specific ID and not several ID like in the lngType parameter.

strFile (optional)
Specifies a file, to which an eventlog was saved before (for example with function SaveEventLog of this class). With this parameter, you can read the events from a saved eventlog. If you assign this parameter, parameter strConnect of this function will not be used. You must specifiy an existing path including the filename. If you do not specify a directory path (only the filename), the current directory of the process, which calls this function, is used. You must have read access to the file. And you should know, from which event source the file was created. If the file was created from the source "System", you must specify this source in parameter strEventSource. Otherwise, you can only read the inserting strings of the events, but not the descriptions from the event message files. Look at example 2.

See also:

Events
SOURCE* Constants
TYPE* Constants
SaveEventLog

Example1 (early binding)

Dim evt As New eventer
Dim lngResult As Long

'filtering events in local system log with a certain description
lngResult = evt1.InitReadEvents(, evt.SOURCE_SYSTEM, , , , , , "*could not be found. It contains the following insertion string*")
'filtering events in local system log with certain types
lngResult = evt1.InitReadEvents(, "System", , , evt1.TYPE_ERROR Or evt1.TYPE_WARNING)
'filtering events in remote application log with date newer than 11/30/1999
lngResult = evt1.InitReadEvents("RemoteMachineName", , "11/30/1999")
'filtering events in local application log with a certain source
lngResult = evt1.InitReadEvents(, , , , , "Browser")
'filtering events in local application log with a certain category
lngResult = evt1.InitReadEvents(, , , , , , "NETL*")

Example2 (late binding)

'Saves at first an eventlog and then, reads from the file

Dim evt, evtMember
Dim dll
Dim lRes
Dim sPath

Set evt = CreateObject("ntXdll.Eventer")
Set dll = CreateObject("ntXdll.DllClass")

sPath = "c:\temp\evt_sec.evt"

lRes = evt.SaveEventLog(sPath, "RemoteMachineName", evt.SOURCE_SECURITY)
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes), "netmsg.dll"))

lRes = evt.InitReadEvents(, evt.SOURCE_SECURITY, , , , , , , , , , , sPath)
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes), "netmsg.dll"))

For Each evtMember In evt.Events

Debug.Print evtMember.EventType
Debug.Print evtMember.EventDescription
Debug.Print "++++++++++++++++++++++++++++++++"

Next


EventRecordsNum As Long

Class Eventer

Saturday, June 17, 2000

EventRecordsNum As Long

Property (Read only)

Return value

Returns the whole number of entries in the eventlog for the specified source. This property is not an element in the collection Events but of the first instance of the object Eventer you create with InitReadEvents (...). You can get the actual record number of the current event over the property EventRecordNumber of this class.

You must at first execute the function InitReadEvents (...) of this class to initialize the collection Events and to fill this property with a value.

See also:

EventRecordNumber
InitReadEvents (...)
 Events

Example

Dim evt As Object
Dim lngResult As Long

Set evt = CreateObject("ntXdll.Eventer")

lngResult = evt.InitReadEvents("System")

Debug.Print evt.Events("RecordNumber").EventRecordsNum


SOURCE_* Properties

Class Eventer

Saturday, June 17, 2000

SOURCE_APPLICATION
SOURCE_SECURITY
SOURCE_SYSTEM

Properties (Read only)

Return value

Return the event sources as string. This is the name of the logfile, that should be opened. The properties are used like constants in the function InitReadEvents (...). You can use the strings "Application", "Security" or "System" instead of these properties. You can only use one of these values in each function call.

See also:

InitReadEvents(...)

Example

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

'Getting the local events from system eventlog
lngResult = evt1.InitReadEvents(, evt1.SOURCE_SYSTEM)

For Each evt2 In evt1.Events

Debug.Print evt2.EventUser

Next


TYPE_* Properties

Class Eventer

Saturday, June 17, 2000

TYPE_INFORMATION
TYPE_WARNING
TYPE_ERROR
TYPE_AUDIT_SUCCESS
TYPE_AUDIT_FAILURE

Properties (Read only)

Return value

Return the possible event types as a Long data type. The properties are used like constants in the function InitReadEvents (...) to filter specific events. You can combine several types in this function with the operator "Or". But don't mistake these properties with the return values of property EventType . This property returnes a string, which has the same content as the name of a type constant.

See also:

InitReadEvents(...)

Example

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

'Getting the local events from system eventlog
lngResult = evt1.InitReadEvents(, , , , evt.TYPE_INFORMATION)

For Each evt2 In evt1.Events

Debug.Print evt2.EventUser

Next


Events As Collection

Class Eventer

Saturday, June 17, 2000

Events As Collection

Property (Read only)

Return value

Returns the collection of all events and properties which are initialized over the function InitReadEvents (...). You must at first execute the function InitReadEvents (...) of this class to fill the collection Events with members. In addition to the properties EventRecordNumber and EventRecordsNum you can get the number of filtered events over the internal method Count.

The key of every element in the collection is the unique record number of the event log. So, if you know the record number of an event, you must not use the For Each - structure to access the properties (Example2).

See also:

InitReadEvents(...)

Example1

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("System")
MsgBox evt1.Events.Count

For Each evt2 In evt1.Events

Debug.Print evt2.Description

Next

Example2

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("System")
MsgBox evt1.Events.Count

Debug.Print evt2.Events("RecordNumber").Description


EventID As Long

Class Eventer

Saturday, June 17, 2000

EventID As Long

Property (Read only)

Return value

Returns the ID of the current event of the collection Events . This is the specific entry for an event in the EventMessageFile respectively the unique number for the event source to specifiy the event.

You must at first execute the function InitReadEvents (...) of this class to initialize the collection Events and to fill this property with a value. You only can access this property and the most of the other event properties over the collection Events .

See also:

InitReadEvents (...)
 Events

Example1

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("System")

For Each evt2 In evt1.Events

Debug.Print evt2.EventID

Next

Example2

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("System")

Debug.Print evt2.Events("RecordNumber").EventID


EventDescription As String

Class Eventer

Saturday, June 17, 2000

EventDescription As String

Property (Read only)

Return value

Returns the description of the current event of the collection Events . If the EventMessageFile is unavailable or the registry value "EventMessageFile" is missing for the source of this event or the event id does'nt exist in the EventMessageFile, the string

"The description for Event ID ( n ) in Source ( s ) could not be found. It contains the following insertion string(s): "

will be returned, folowed by the list of the insertion strings. In this version, the message file must be present on the local machine when you want to receive the hole description of an event on a remote machine.

You must at first execute the function InitReadEvents (...) of this class to initialize the collection Events and to fill this property with a value. You only can access this property and the most of the other event properties over the collection Events .

See also:

InitReadEvents (...)
 Events

Example1

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("System")

For Each evt2 In evt1.Events

Debug.Print evt2.EventDescription

Next

Example2

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("System")

Debug.Print evt2.Events("RecordNumber").EventDescription


EventSource As String

Class Eventer

Saturday, June 17, 2000

EventSource As String

Property (Read only)

Return value

Returns the source of the current event of the collection Events . Each event has a source (application, service, driver, subsystem) that generated the entry. This is the name used to retrieve from the registry the name of the file containing the message strings for this source. It is used, together with the event identifier, to get the message string that describes this event.

You must at first execute the function InitReadEvents (...) of this class to initialize the collection Events and to fill this property with a value. You only can access this property and the most of the other event properties over the collection Events .

See also:

InitReadEvents (...)
 Events

Example1

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("System")

For Each evt2 In evt1.Events

Debug.Print evt2.EventSource

Next

Example2

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("System")

Debug.Print evt2.Events("RecordNumber").EventSource


EventCategory As String

Class Eventer

Saturday, June 17, 2000

EventCategory As String

Property (Read only)

Return value

Returns the category of the current event of the collection Events . If there is no category declared for this event "---" ore "none" is returned dependend on the users default language. If the CategoryMessageFile is unavailable, the category number is returned in the format "(n)" where n is the category number.

You must execute the function InitReadEvents (...) of this class at first to initialize the collection Events and to fill this property with a value. You only can access this property and the most of the other event properties over the collection Events .

See also:

InitReadEvents (...)
 Events

Example1

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("RemoteMachineName", "System")

For Each evt2 In evt1.Events

Debug.Print evt2.EventCategory

Next

Example2

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("RemoteMachineName", "System")

Debug.Print evt2.Events("RecordNumber").EventCategory


EventType As String

Class Eventer

Saturday, June 17, 2000

EventType As String

Property (Read only)

Return value

Returns the type of the current event of the collection Events . This can be one of the following strings:

"TYPE_AUDIT_FAILURE"
"TYPE_AUDIT_SUCCESS"
"TYPE_ERROR"
"TYPE_INFORMATION"
"TYPE_WARNING"

You must at first execute the function InitReadEvents (...) of this class to initialize the collection Events and to fill this property with a value. You only can access this property and the most of the other event properties over the collection Events .

See also:

InitReadEvents (...)
 Events

Example1

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("System")

For Each evt2 In evt1.Events

Debug.Print evt2.EventType

Next

Example2

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("System")

Debug.Print evt2.Events("RecordNumber").EventType


EventDateWritten As Date

Class Eventer

Saturday, June 17, 2000

EventDateWritten As Date

Property (Read only)

Return value

Returns the date when the current event of the collection Events where written to the eventlog. Mostly, this is the same date as returned by the property EventDateGenerated . The returned format depends on the regional settings.

You must at first execute the function InitReadEvents (...) of this class to initialize the collection Events and to fill this property with a value. You only can access this property and the most of the other event properties over the collection Events .

See also:

EventDateGenerated
InitReadEvents (...)
 Events

Example1

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("System")

For Each evt2 In evt1.Events

Debug.Print evt2.EventDateWritten

Next

Example2

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("System")

Debug.Print evt2.Events("RecordNumber").EventDateWritten

' The returned value has the format like
' 09/25/1999 13:50:04


EventDateGenerated As Date

Class Eventer

Saturday, June 17, 2000

EventDateGenerated As Date

Property (Read only)

Return value

Returns the date when the current event of the collection Events where generated. Mostly, this is the same date as returned by the property EventDateWritten . The returned format depends on the regional settings.

You must at first execute the function InitReadEvents (...) of this class to initialize the collection Events and to fill this property with a value. You only can access this property and the most of the other event properties over the collection Events .

See also:

EventDateWritten
InitReadEvents (...)
 Events

Example1

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("RemoteMachineName", "System")

For Each evt2 In evt1.Events

Debug.Print evt2.EventDateGenerated

Next

Example2

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("RemoteMachineName", "System")

Debug.Print evt2.Events("RecordNumber").EventDateGenerated

' The returned value has the format like
' 09/25/1999 13:50:04


EventComputer As String

Class Eventer

Saturday, June 17, 2000

EventComputer As String

Property (Read only)

Return value

Returns the computername of the current event of the collection Events .

You must at first execute the function InitReadEvents (...) of this class to initialize the collection Events and to fill this property with a value. You only can access this property and the most of the other event properties over the collection Events .

See also:

InitReadEvents (...)
 Events

Example1

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("RemoteMachineName", "System")

For Each evt2 In evt1.Events

Debug.Print evt2.EventComputer

Next

Example2

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("RemoteMachineName", "System")

Debug.Print evt2.Events("RecordNumber").EventComputer


EventUser As String

Class Eventer

Saturday, June 17, 2000

EventUser As String

Property (Read only)

Return value

Returns the user who where logged on in the time when the current event of the collection Events where written to the log. This member can be "N/A" or "---" (dependend on the language) if no user where logged on to this time.

You must at first execute the function InitReadEvents (...) of this class to initialize the collection Events and to fill this property with a value. You only can access this property and the most of the other event properties over the collection Events .

See also:

InitReadEvents (...)
 Events

Example1

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("System")

For Each evt2 In evt1.Events

Debug.Print evt2.EventUser

Next

Example2

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("System")

Debug.Print evt2.Events("RecordNumber").EventUser


EventData As Variant

Class Eventer

Wednesday, November 21, 2001

EventData As Variant

Property (read only)

Return value

Returns the Data of the current event of the collection Events . The returned data type is an array of bytes. This property is probably only usefull for people, who want to examine each byte of the event data. For regular users, who only want to see the event data in textual form, should use the other EventData* properties (look under See also).

If there is no data in the event, the returned array nevertheless contains one element (a zero) to obtain an error when using the property (undefined data type).

You must at first execute the function InitReadEvents (...) of this class to initialize the collection Events and to fill this property with a value. You only can access this property and the most of the other event properties over the collection Events .

See also:

InitReadEvents (...)
 Events
EventDataBytes
EventDataString
EventDataWords

Example (early binding)

Dim ev As New Eventer, evMember As Eventer
Dim lRes As Long, l As Long
Dim ret() As Byte

lRes = ev.InitReadEvents("computer", , , , ev.TYPE_INFORMATION)

For Each evMember In ev.Events

ret = evMember.EventData
For l = 0 To UBound(ret)

Debug.Print ret(l)

Next

Next


EventDataBytes As String

Class Eventer

Saturday, June 17, 2000

EventDataBytes As String

Property (Read only)

Return value

Returns the Byte Data of the current event of the collection Events . The returned string is formatted like in the event viewer. 8 Bytes in a row (one row ends with a line feed) and a length of 2 chars for each byte. Each byte is seperated by a space form the other. The best way to presentate the string is to use a non proportional font with a fixed length (FixedSys for example).

You must at first execute the function InitReadEvents (...) of this class to initialize the collection Events and to fill this property with a value. You only can access this property and the most of the other event properties over the collection Events .

See also:

InitReadEvents (...)
 Events

Example1

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("RemoteMachineName", "System")

For Each evt2 In evt1.Events

Debug.Print evt2.EventDataBytes

Next

Example2

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("RemoteMachineName", "System")

Debug.Print evt2.Events("RecordNumber").EventDataBytes

' The returned value has the format like
' 51 04 00 00 11 00 00 00
' 09 00 00 00 4E 54 36 39
' 38 53 32 30 00 09 00 00
' 00 4E 54 36 39 38 44 42
' 41 00


EventDataString As String

Class Eventer

Saturday, June 17, 2000

EventDataString As String

Property (Read only)

Return value

Returns the Data String of the current event of the collection Events . The returned string is formatted like in the event viewer. 8 chars in a row (one row ends with a line feed). Not supported chars (ASCII 0 to 31) and spaces are replaced by a point "."The best way to presentate the string is to use a non proportional font with a fixed length (FixedSys for example).

You must at first execute the function InitReadEvents (...) of this class to initialize the collection Events and to fill this property with a value. You only can access this property and the most of the other event properties over the collection Events .

See also:

InitReadEvents (...)
 Events

Example1

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("RemoteMachineName", "System")

For Each evt2 In evt1.Events

Debug.Print evt2.EventDataString

Next

Example2

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("RemoteMachineName", "System")

Debug.Print evt2.Events("RecordNumber").EventDataString

' The returned value has
    the format like
' Q.......
' ....ONES
' TRING...
' .OTHERS.
' A.


EventDataWords As String

Class Eventer

Saturday, June 17, 2000

EventDataWords As String

Property (Read only)

Return value

Returns the Data Words of the current event of the collection Events . The returned string is formatted like in the event viewer. 4 Words in a row (one row ends with a line feed) and a length of 4 byte strings for each word. Each word is seperated by a space form the other. The best way to presentate the string is to use a non proportional font with a fixed length (FixedSys for example).

You must at first execute the function InitReadEvents (...) of this class to initialize the collection Events and to fill this property with a value. You only can access this property and the most of the other event properties over the collection Events .

See also:

InitReadEvents (...)
 Events

Example1

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("RemoteMachineName", "System")

For Each evt2 In evt1.Events

Debug.Print evt2.EventDataWords

Next

Example2

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("RemoteMachineName", "System")

Debug.Print evt2.Events("RecordNumber").EventDataWords

' The returned value has
    the format like
' 00000451 00000011 00000009 3936544E
' 30325338 00000900 36544E00 42443839
' 4100


EventRecordNumber As Long

Class Eventer

Saturday, June 17, 2000

EventRecordNumber As Long

Property (Read only)

Return value

Returns the current record number of the event in the eventlog. The record numbers of the eventlog must not begin with 1 because in the most cases, the oldest entries are deleted if the evntlog reaches a certain size. You can get the whole number of records in the eventlog over the property EventRecordsNum of this class.

You must at first execute the function InitReadEvents (...) of this class to initialize the collection Events and to fill this property with a value. You only can access this property and the most of the other event properties over the collection Events .

See also:

EventRecordsNum
InitReadEvents (...)
 Events

Example1

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("System")

For Each evt2 In evt1.Events

Debug.Print evt2.EventRecordNumber

Next

Example2

Dim evt1 As Object, evt2 As Object
Dim lngResult As Long

Set evt1 = CreateObject("ntXdll.Eventer")
Set evt2 = CreateObject("ntXdll.Eventer")

lngResult = evt1.InitReadEvents("System")

Debug.Print evt2.Events("RecordNumber").EventRecordNumber


WriteEvent(...) As Long

Class Eventer

Friday, November 23, 2001

WriteEvent

(intEventType As Integer,
lngEventID As Long,
strSourceName As String,
intCategory As Integer,
strDesc As String,
[varData As Variant],
[strConnect As String],
[strUser As String],
[strUserMachine As String])

As Long

Return value

Returns 0 in case of success, otherwise a non zero value which can be an Visual Basic Error or an error from an API. You can use function FormatAPIMessage of class DllClass, to convert an API message to a string. The function writes an event to the eventlog of the local or a remote computer.

Parameters (all optional)

intEventType
Specifies the type of event, you want to write. You can use one of the TYPE_* properties to specify this parameter. You cannot use a combination of more than one of these types. The TYPE_AUDIT_* properties are used for events in the security log. Note, that only the local system has the right to log events to the security log.

intEventID
Specifies the ID, which identifies the event. If you use an event message file, which name is stored in the registry value "EventMessageFile" under the key HKLM\System\CurrentControlSet\Services\Eventlog\<Eventlog>\<Source>, you must use the ID, to which the message belongs in the file. The file must be on the target computer. Otherwise,, if you don't have such a file, you can use any other number of type integer.

strSourceName
Specifies the source of the event. Each event has a source, to which it belongs and which unique name is stored as a key in the registry path HKLM\System\CurrentControlSet\Services\Eventlog\<Eventlog>\ on the target computer. The name must be unique for all Logs (Application, System and Security).
You can only write events to sources, which are stored as a subkey of this path. Otherwise, if you use another name, the event is automatically written to the Application log. You don't have to have values stored in this subkey (like "EventLogMessageFile" or something else). It would be enough, to have an empty key.
If you want to write an event to the System log of the target machine, for example, which should have the source "MyApp", you only have to create a subkey "MyApp" in the registry path HKLM\System\CurrentControlSet\Services\Eventlog\System. For this task, you could use class Registry of ntXdll. In addition, you should have enough access to the target log. For further information about the permissions, look at the Remarks section.
You even could create a new eventlog and write events to it, if you create a unique subkey in the registry path HKLM\System\CurrentControlSet\Services\Eventlog and then a unique subkey for the source name.

intCategory
Specifies the category, to which the event belongs. If you want to have a string, that describes the category, you must have a category message file, where every category number is assigned to a string. The filename is stored in the value"CategoryMessageFile" in registry path HKLM\System\CurrentControlSet\Services\Eventlog\<Eventlog>\<Source> and must be on the target computer. If you don't have such a file, the category can only be read as the number, you assigned to parameter intCategory.

strDesc
Specifies the string, which is stored in the description of the event. But it is not the whole description of the event. Parameter strDesc represents the inserting strings, which are used to replace placeholders in parameter strings of the event message file. If you want to assign more than one of these inserting strings, seperate your strings with an NULL character (in Visual Basic: vbNullChar - look at the example).
An example: if there is an event message file with event ID 1234, and within the file, this ID represents the parameter message "%1 percent of disk %2 are used", then the string "67" & vbNullChar & "C:" represents the two strings, which replace the placeholders %1 and %2 in the parameter string.
If you don't have a event message file, the inserting strings are stored as well in the eventlog, but if you read the eventlog, the description additionally contains the following note:
The description for Event ID ( intEventID ) in Source ( strSourceName ) could not be found. It contains the following insertion string(s): "
But if you only want to log some events, which are for your own purpose, that doesn't matter. It is by design of the Windows NT eventlog, that the log only stores the inserting strings and the event message file the parameter message strings.

varData (optional)
With this parameter, you can specify the binary data, you want to write to the eventlog. You have to assign an array of bytes. If you omitt the parameter, not binary data will be written. You can use the function StringToANSIByteArrray of class Stringer to convert a string, you want to write as binary data (look to the example). Or you can simply assign a string to an empty array. Then, the array contains the string in UNICODE format.

strConnect (optional)
Specifies the name of the target computer (without backslashes), to which you want to write the event. If you omitt this parameter, the local computer is used.

strUser (optional)
Secifies the user account, which should appear in the event. If you omitt the parameter, no username is written to the target eventlog. If you specify the string "\??\", the current user is used. Otherwise, the user account, you assign to this parameter, will be written. But it must be a valid account. The function searches for this account on the machine, you assign in parameter strUserMachine.

strUserMachine (optional)
Specifies the computer, from which the account, you have assigned to parameter strUser, will be searched. The parameter is only used in combination with parameter strUser. This computer must not be the same machine, which you have specified in parameter strConnect. And you must not take the computer, where the account exists. It only meens the computer, from which the search is executed. If you omitt the parameter, the local machine is used. The function searches in the following sequence for the account:
accounts on the target computer (strUserMachine) - domain accounts - accounts of trusted domains.

Remarks

Here are the permissions for each event log:

Application | Local System | Full (Read, Write, Clear)
Administrators | Full (Read, Write, Clear)
Server Operators | Full (Read, Write, Clear)
Everyone | Read, Write
System | Local System | Full (Read, Write, Clear)
Administrators | Full (Read, Write, Clear)
Server Operators | Read, Clear
Everyone | Read
Security | Local System | Full (Read, Write, Clear)
Administrators | Read, Clear

To read the eventlog, use function InitReadEvents of this class.

See also:

TYPE* Constants
InitReadEvents
StringToANSIByteArrray
SaveEventLog
CleanEventLog
FormatAPIMessage

Example (late binding)

Dim ev, dll, strg
Dim lRes
Dim strDesc
Dim varData

Set ev = CreateObject("ntXdll.Eventer")
Set dll = CreateObject("ntXdll.DllClass")
Set strg = CreateObject("ntXdll.Stringer")

'The string contains three strings, seperated
'by a NULL character
strDesc = "This is the first string - " & vbNullChar & _
"This is the second string - " & vbNullChar & "This is the third string"

varData = strg.StringToANSIByteArray("This is the binary data")

'writing to a remote eventlog with an account on the target machine. The
'event will be written to the Application log, if the event source
'MyTestSource doesn't exist.
lRes = ev.WriteEvent(ev.TYPE_INFORMATION, 999, "MyTestSource", 1234, strDesc, varData, _
"TargetComputer", "Administrator", "TargetComputer")

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes), "netmsg.dll"))


SaveEventLog(...) As Long

Class Eventer

Sunday, November 25, 2001

SaveEventLog

(strFile As String,
[strConnect As String],
[strEventSource As String])

As Long

Return value

Returns 0 in case of success, otherwise a non zero value which can be an Visual Basic Error or an error from an API. You can use function FormatAPIMessage of class DllClass, to convert an API message to a string. The function saves the eventlog of the local or a remote computer to a file.

Parameters (all optional)

strFile
Specifies the path to the file. You have to assign a path including the filename. If you don't specify the directory path, the current directory of the process, which calls the function, is used. You only can save the file to a remote computer by using a null session. If you specify a file, that already exists, an error will be returned.
The format of the file is binary and can be imported fom the builtin Windows NT eventviewer (eventvwr.exe). Or you can read the file, if you assign the filepath in parameter strFile of function InitReadEvents of this class.

strConnect (optional)
Specifies the name of the target computer (without backslashes), from which you want to save the eventlog. If you omitt this parameter, the local computer is used.

strEventSource (optional)
Specifies the name of the source, you want to save. You can use one of the TYPE* properties of this class, to assign the parameter. You cannot use a combination of more than one of these properties. If you omitt the parameter, the Application log will be saved. You must have READ access to this source (read the Remarks section of function WriteEvent of this class).

Remarks

The function does not support the export in text- or csv-format. To implement this feature, you have to create a collection with the events, you want to save, with function InitReadEvents of this class. Then, write the data to a file, seperated by a character you want (comma, tab or something else).

See also:

TYPE* Constants
InitReadEvents
WriteEvent
CleanEventLog
FormatAPIMessage

Example (late binding)

Dim ev, dll
Dim lRes

Set ev = CreateObject("ntXdll.Eventer")
Set dll = CreateObject("ntXdll.DllClass")

lRes = ev.SaveEventLog("c:\temp\ev_sec.evt", , ev.SOURCE_SECURITY)

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes), "netmsg.dll"))


CleanEventLog(...) As Long

Class Eventer

Wednesday, November 28, 2001

CleanEventLog

([strFile As String],
[strConnect As String],
[strEventSource As String])

As Long

Return value

Returns 0 in case of success, otherwise a non zero value which can be an Visual Basic Error or an error from an API. You can use function FormatAPIMessage of class DllClass, to convert an API message to a string. The function clears the eventlog of the local or a remote computer.

Parameters (all optional)

strFile
Specifies the path to a file, to which the eventlog can be saved before it will be cleared (if you only want to save an eventlog without clearing it, you can use SaveEventLog of this class). You have to assign a path including the filename. If you don't specify the directory path, the current directory of the process, which calls the function, is used. You only can save the file to a remote computer by using a null session. If you specify a file, that already exists, an error will be returned.
The format of the file is binary and can be imported fom the builtin Windows NT eventviewer (eventvwr.exe). Or you can read the file, if you assign the filepath in parameter strFile of function InitReadEvents of this class.

strConnect (optional)
Specifies the name of the target computer (without backslashes), from which you want to clear the eventlog. If you omitt this parameter, the local computer is used.

strEventSource (optional)
Specifies the name of the source, you want to clear. You can use one of the TYPE* properties of this class, to assign one of the main eventlog sources of Windows NT. You cannot use a combination of more than one of these properties. If you omitt the parameter, the Application log will be cleared. You must have CLEAR access to this source (read the Remarks section of function WriteEvent of this class).

See also:

TYPE* Constants
InitReadEvents
WriteEvent
SaveEventLog
FormatAPIMessage

Example (late binding)

Dim ev, dll
Dim lRes

Set ev = CreateObject("ntXdll.Eventer")
Set dll = CreateObject("ntXdll.DllClass")

lRes = ev.CleanEventLog("c:\temp\ev_sec_backup.evt", "RemoteComputerName", ev.SOURCE_SECURITY)

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes), "netmsg.dll"))


Class Process

Saturday, June 17, 2000

Class Process

This class gives you informations about running processes on the local computer. To get the information about 32 Bit processes , you have to initialize a collection Processes by setting the name of the process(es) to property SetBaseName . You can use wildcards. "*" means, that all processes are added to the collection. All collection members represent processes on the machine. You can access the properties of the processes only through the object instances of the collection members.

If you want to query 16 Bit processes within the NT virtual dos machine, you have to initialize the collection Processes by setting the PID of the process NTVDM.EXE to property SetNtvdmID .

To run correctly, the file Psapi.dll must be copied to %SystemRoot%\System32.

In this version, you cannot query the processes of a remote machine.

The NT Privilege to debug programs ( SE_DEBUG_NAME ) must be granted to the user, who executes the process information query. Otherwise, the complete informations only of the processes which are created from the user are returned. You can grant privileges to users with function AddPolicyRight of Class LocalSecurer . You can enable a privilege for the current process (if it is already granted to a user) with function SetMyTokenPrivileges of this class.

There are some additional functions, which you can use seperate and which require no Process objects. These functions are:

StartProcess
EndProcess
SetMyTokenPrivileges

You get detailed information of all the functions and properties in the help of each function or property.


SetBaseName As String

Class Process

Saturday, June 17, 2000

SetBaseName As String

Property

Return value

None.

At first, for initializing the class and setting the filter to return the process(es), assign a value to this property. You can use wildcards, for example "expl*" or "ras???.exe". "*" means, that all processes have to be returned. Otherwise, set an exact process basename like "explorer.exe" (without the path). You only can access the process informations over the collection Processes of this class. If you assign a special basename, the collection only have one element.

See also

Processes

Example

Dim proc As Object
Set proc = CreateObject("ntXdll.Process")
proc.SetBaseName = "rasman.exe"
proc.SetBaseName = "*"


SetNtvdmID As Long

Class Process

Saturday, June 17, 2000

SetNtvdmID As Long

Property

Return value

None.

At first, for initializing the collection Processes with 16 Bit Tasks of a NTVDM process, assign a value to this property. This value must be the Process ID (PID) of a VDM process (NTVDM.EXE). If the VDM process contains 16 Bit tasks, then this tasks are added to the collection Processes . But only with the properties ModuleBaseName , ModuleFileName and ProcessPID . You only can access the properties of the 16 Bit tasks over the collection Processes of this class.

How to query running NTVDM tasks - see the example.

Remarks

For initializing 32 Bit processes, use SetBaseName .

See also

Processes
SetBaseName

Example

Dim proc1 As New Process, proc2 As Process
Dim vdmProc1 As New Process, vdmProc2 As Process
proc1.SetBaseName = "NTVDM.EXE"
If proc1.processes.Count > 0 Then

For Each proc2 In proc1.processes

vdmProc1.SetNtvdmID = proc2.ProcessPID
For Each vdmProc2 In vdmProc1.processes

Debug.Print vdmProc2.ModuleBaseName
Debug.Print vdmProc2.ModuleFileName
Debug.Print vdmProc2.ProcessPID

Next

Next

End If


Processes As Collection

Class Process

Saturday, June 17, 2000

Processes As Collection

Property (read only)

Return value

Returns the collection of the process(es), initialized through the setting of property SetBaseName . The key of the elements in the collection is the ProcessPID as a String. So you can access the information without the For Each - loop when you know the PID of the process (Example3).

See also:

SetBaseName

Example1

Dim proc As Object
Set proc = CreateObject("ntXdll.Process")
proc.SetBaseName = "winlogon.exe"
Debug.Print proc.Processes.Count

Example2

Dim proc As Object, p As Object
Set proc = CreateObject("ntXdll.Process")
proc.SetBaseName = "*"
For Each p in proc.Processes

Debug.Print p.ProcessPID

Next

Example3

Dim proc As Object
Set proc = CreateObject("ntXdll.Process")
proc.SetBaseName = "*"
Debug.Print proc.Processes("132").ModuleFileName


ModuleBaseName As String

Class Process

Saturday, June 17, 2000

ModuleBaseName As String

Property (read only)

Return value

Returns the ModuleBaseName of the process(es) or 16 Bit Tasks. This is the name of the executable file, not the whole path. The property is initzialized through function SetBaseName and must be accessed over the collection Processes .

See also:

SetBaseName
SetNtvdmID
Processes

Example

Dim proc As Object, p As Object
Set proc = CreateObject("ntXdll.Process")
proc.SetBaseName = "*"
For Each p in proc.Processes

Debug.Print p.ModuleBaseName

Next


ModuleFileName As String

Class Process

Saturday, June 17, 2000

ModuleFileName As String

Property (read only)

Return value

Returns the ModuleFileName of the process(es) or 16 Bit Tasks. This is the whole path of the executable file. The property is initzialized through function SetBaseName and must be accessed over the collection Processes

See also:

SetBaseName
SetNtvdmID
Processes

Example

Dim proc As Object, p As Object
Set proc = CreateObject("ntXdll.Process")
proc.SetBaseName = "*"
For Each p in proc.Processes

Debug.Print p. ModuleFileName

Next


ProcessPID As Long

Class Process

Saturday, June 17, 2000

ProcessPID As Long

Property (read only)

Return value

Returns the process ID of the process(es) or the thread ID of the 16 Bit processes under NTVDM. The property is initzialized through function SetBaseName and must be accessed over the collection Processes .

See also:

SetBaseName
SetNtvdmID
Processes

Example

Dim proc As Object, p As Object
Set proc = CreateObject("ntXdll.Process")
proc.SetBaseName = "*"
For Each p in proc.Processes

Debug.Print p.ProcessPID

Next


WorkingSetSize As Long

Class Process

Saturday, June 17, 2000

WorkingSetSize As Long
PeakWorkingSetSize As Long

Properties (read only)

Return value

Returns memory and the maximum memory of the process in bytes. The working set is the amount of memory physically mapped to the process context at a given time. The property is initzialized through function SetBaseName and must be accessed over the collection Processes .

See also:

SetBaseName
Processes

Example

Dim proc As Object, p As Object
Set proc = CreateObject("ntXdll.Process")
proc.SetBaseName = "*"
For Each p in proc.Processes

Debug.Print p.WorkingSetSize
Debug.Print p.PeakWorkingSetSize

Next


NonPagedPoolUsage As Long

Class Process

Saturday, June 17, 2000

NonPagedPoolUsage As Long
PeakNonPagedPoolUsage As Long

Properties (read only)

Return value

Returns memory and the maximum of memory in the nonpaged pool in bytes. Memory in the nonpaged pool is system memory that cannot be paged to disk as long as the corresponding objects are allocated. The property is initzialized through function SetBaseName and must be accessed over the collection Processes .

See also:

SetBaseName
Processes

Example

Dim proc As Object, p As Object
Set proc = CreateObject("ntXdll.Process")
proc.SetBaseName = "*"
For Each p in proc.Processes

Debug.Print p.NonPagedPoolUsage
Debug.Print p.PeakNonPagedPoolUsage

Next


PagedPoolUsage As Long,

Class Process

Saturday, June 17, 2000

PagedPoolUsage As Long
PeakPagedPoolUsage As Long

Properties (read only)

Return value

Returns memory and the maximum of memory in the paged pool in bytes. Memory in the paged pool is system memory that can be transferred to the paging file on disk (paged) when it is not being used. The property is initzialized through function SetBaseName and must be accessed over the collection Processes .

See also:

SetBaseName
Processes

Example

Dim proc As Object, p As Object
Set proc = CreateObject("ntXdll.Process")
proc.SetBaseName = "*"
For Each p in proc.Processes

Debug.Print p.PagedPoolUsage
Debug.Print p.PeakPagedPoolUsage

Next


PageFileUsage As Long,

Class Process

Saturday, June 17, 2000

PageFileUsage As Long
Peak PageFileUsage As Long

Properties (read only)

Return value

Returns memory and the maximum of memory in the page file in bytes. The pagefile usage represents how much memory is set aside for the process in the system paging file. The property is initzialized through function SetBaseName and must be accessed over the collection Processes .

See also:

SetBaseName
Processes

Example

Dim proc As Object, p As Object
Set proc = CreateObject("ntXdll.Process")
proc.SetBaseName = "*"
For Each p in proc.Processes

Debug.Print p.PageFileUsage
Debug.Print p.PeakPageFileUsage

Next


PageFaultCount As Long

Class Process

Saturday, June 17, 2000

PageFaultCount As Long

Property (read only)

Return value

Returns number of page faults. The page fault counters for a process are incremented when the process requests code or data that is not found in its working set. The data might be found elsewhere in memory, such as in the file system cache, in the working set of another process, or in transition to disk. The system might also have to read the data from disk. The property is initzialized through function SetBaseName and must be accessed over the collection Processes .

See also:

SetBaseName
Processes

Example

Dim proc As Object, p As Object
Set proc = CreateObject("ntXdll.Process")
proc.SetBaseName = "*"
For Each p in proc.Processes

Debug.Print p.PageFaultCount

Next


SetMyTokenPrivileges(...) As Long

Class Process

Saturday, June 17, 2000

SetMyTokenPrivileges(strPrivilege As String, booEnable As Boolean) As Long

Function

Return value

The function enables or disables NT Privileges for the token of the calling process. It returns 0 (zero) on success. In case of an error, an error number will be returned. This can be an API or a VB error.

Parameters

strPrivilege
You must assign the privilege string in this parameter. You can use the SE_* properties for this parameter.

booEnable
Assign True to this parameter to enable a privilege, otherwise False.

Remarks

The function does not grant privileges - it only enables or disables token privileges, which are already granted to the user, who executes the task (token). You can grant a privilege to a user with function AddPolicyRight of class LocalSecurer .

For many tasks (services for example), privileges ( SE_DEBUG_NAME for example) are disabled by default, even if they are granted to the current user. Ths is a protection from the system, that important tasks are not killed by the user.

See also:

SE* Properties
AddPolicyRight
LocalSecurer

Example

Dim proc As Object
Dim lngReturn As Long
Set proc = CreateObject("ntXdll.Process")
lngReturn = proc.SetMyTokenPrivileges(proc.SE_DEBUG_NAME,
    True)


SE_* Properties

Class Process

Saturday, June 17, 2000

SE_ASSIGNPRIMARYTOKEN_NAME As String

Privilege to modify a process' access token

SE_CREATE_TOKEN_NAME As String

Privilege to create an access token

SE_LOCK_MEMORY_NAME As String

Privilege lock pages in memory to prevent them from being paged out into backing store (such as PAGEFILE.SYS)

SE_INCREASE_QUOTA_NAME As String

Privilege to increase object quotas

SE_UNSOLICITED_INPUT_NAME As String

Privilege to read unsolicited data from a terminal device.

SE_MACHINE_ACCOUNT_NAME As String

Privilege to add computers to the domain

SE_TCB_NAME As String

Privilege to act as a trusted part of the operating system

SE_SECURITY_NAME As String

Privilege to access the system security

SE_TAKE_OWNERSHIP_NAME As String

Privilege to take ownership on files and objects

SE_LOAD_DRIVER_NAME As String

Privilege to load and unload device drivers

SE_SYSTEM_PROFILE_NAME As String

Privilege to use Windows NT profiling capabilities to observe the system

SE_SYSTEMTIME_NAME As String

Privilege to modify the system time

SE_PROF_SINGLE_PROCESS_NAME As String

Privilege to use Windows NT profiling capabilities to observe a process

SE_INC_BASE_PRIORITY_NAME As String

Privilege to boost the sheduling priority of a process

SE_CREATE_PAGEFILE_NAME As String

Privilege to create a page file

SE_CREATE_PERMANENT_NAME As String

Privilege to create permanent shared objects like '\\Device'.

SE_BACKUP_NAME As String

Privilege to backup files and directories

SE_RESTORE_NAME As String

Privilege to restore files and directories

SE_SHUTDOWN_NAME As String

Privilege to shutdown Windows NT

SE_DEBUG_NAME As String

Privilege to debug applications

SE_AUDIT_NAME As String

Privilege to generate audit-log entries

SE_SYSTEM_ENVIRONMENT_NAME As String

Privilege to change system environment variables

SE_CHANGE_NOTIFY_NAME As String

Privilege to traverse a directory tree even if the user has no other rights to access that directory

SE_REMOTE_SHUTDOWN_NAME As String

Privilege to force a shutdown from a remote system

SE_INTERACTIVE_LOGON_NAME As String

Privilege for an account to log on using the interactive logon type

SE_NETWORK_LOGON_NAME As String

Privilege for an account to log on using the network logon type

SE_BATCH_LOGON_NAME As String

Privilege for an account to log on using the batch logon type

SE_SERVICE_LOGON_NAME As String

Privilege for an account to log on using the service logon type

Properties (read only)

Return value

Return privilege strings. The properties can be used like constants in the function SetMyTokenPrivileges of this class.

See also:

SetMyTokenPrivileges

Example

Dim proc As Object
Dim lngReturn As Long
Set proc = CreateObject("ntXdll.Process")
lngReturn = proc.SetMyTokenPrivileges(proc.SE_DEBUG_NAME,
    True)


StartProcess(...) As Long

Class Process

Wednesday, December 06, 2001

StartProcess

(strPath As String,
[lngWait As Long],
[booVisible As Boolean],
[strUser As String],
[strPassword As String],
[strDomain As String],
[booLoadProfile As Boolean],
[strProfilePath As String])

As Long

Function

Return value

Returns 0 in case of success, otherwise a non zero value, which can be an Visual Basic Error, an internal Error or an error from an API. You can use function FormatAPIMessage of class DllClass, to convert an API message to a string.

The function starts a process or an application on the local computer.

Parameters

strPath
Specifies the file to execute. If you do not specify the complete path, the function searches at first in the current directory of the process, which calls the function and then in the path (look at environment variable %PATH%). This parameter is required.

lngWait (optional)
Specifies the time in milliseconds, the function waits for the termination of the started process. It is possible, that the process does not terminate within this period. Then, the function returns error 258 (WAIT_TIMEOUT) although the process has started without error. If you want to wait until the process really terminates, you can specify the value INFINITE . If the process terminates before the period ends, the function does not wait for the rest of the time.
If you omitt the parameter, the function does not wait for the termination (lngWait = 0).
If you specify a value, which lets the function wait until the process really terminates, property ExitCode of this class is set to a value, the terminated process has returned.

booVisible (optional)
Specifies, whether an application, which normally starts with a window, should be visible or not. The default value, if you omitt the parameter, is True.

strUser (optional)
Specifies the user, in which context the process should run. The default value is an empty string. That means, the process will start in the context of the current user. Only users of the local account database and users of the primary or a trusted domain can log on to the local computer.
Note, that Windows® NT has the limitation, that the user, who calls StartProcess, must have the privileges SE_TCB_NAME , SE_ASSIGNPRIMARYTOKEN_NAME and SE_INCREASE_QUOTA_NAME , when he wants to assign the process to another user. Normally, only the LocalSystem has the privilege SE_TCB_NAME and normally, only Administrators and LocalSystem have the privileges SE_ASSIGNPRIMARYTOKEN_NAME and SE_INCREASE_QUOTA_NAME . But you can assign privileges with function AddPolicyRight of class LocalSecurer .
Note further, that the function StartProcess grants the user, you assign to parameter strUser, full access to the desktop. And the function does not remove this permission after StartProcess has finished. But this permission is only valid until the current user logs off from the system.

strPassword (optional)
Specifies the password for the user, you assigned to parameter strUser. The default value is an empty string. This parameter is ignored, if you omitt parameter strUser.

strDomain (optional)
Specifies the domain, where the user, you assigned to parameter strUser, exists. If you specifiy a dot ("."), which is the default value, the function searches within the local account database for the user. This parameter is ignored, if you omitt parameter strUser.

booLoadProfile (optional)
Specifies, whether the profile of the user, you assigned to parameter strUser, should be loaded on the local machine. The default value is False.This parameter is ignored, if you omitt parameter strUser.

strProfilePath (optional)
Specifies the path, where the profile of the user, you assigned to parameter strUser, can be found. The dafault value is an empty string. This means, a default users profile would be loaded. This parameter is ignored, if you omitt parameter booLoadProfile or strUser.

Remarks

To terminate a process on the local machine, use function EndProcess of this class.

See also:

FormatAPIMessage
INFINITE
ExitCode
SE_TCB_NAME
SE_ASSIGNPRIMARYTOKEN_NAME
SE_INCREASE_QUOTA_NAME
AddPolicyRight
EndProcess

Example (late binding)

Dim proc, dll
lRes As Long

Set proc = CreateObject("ntXdll.Process")
Set dll = CreateObject("ntXdll.DllClass")

lRes = proc.StartProcess("c:\winnt\regedit.exe", proc.INFINITE, , "UserName", "Ah5s&", "Domain", True, "\\Server\Users\UserName\Profile")

MsgBox "ExitCode: " & proc.ExitCode

MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))


EndProcess(...) As Long

Class Process

Wednesday, December 06, 2001

EndProcess

([lngProcessID As Long],
[strApplication As String],
[strPath As String],
[booForce As Boolean],
[lngWait As Long])

As Long

Function

Return value

Returns 0 in case of success, otherwise a non zero value, which can be an Visual Basic Error, an internal Error or an error from an API. You can use function FormatAPIMessage of class DllClass, to convert an API message to a string.

The function terminates a process or an application on the local computer.

Parameters

lngProcessID (optional)
Specifies the ID of the process, you want to terminate. You get the ID form property ProcessPID of this class of from the taskmanager of Windows® NT.

strApplication (optional)
Specifies the name of the application, you want to terminate. This is the title of the window, the application displays.
You can use wildcards for this parameter ("*" for any character or "?" for one character). But this does not mean, that all applications with a matching title are terminated. To terminate all matching applications, you have to execute the function, until it returns error 1400 ("Invalid Window Handle").
The parameter is not case sensitive.
The parameter is ignored, if you assign parameter lngProcessID.

strPath (optional)
Specifies the path of the running executable, you want to terminate. This can be only the filename or the complete path (if the parameter contains a backslash). You can get the path from the properties ModuleFileName or ModuleBaseName of this class. You also can get the filename from the process list of the Windows® NT taskmanager.
You can use wildcards for this parameter ("*" for any character or "?" for one character). But this does not mean, that all applications with a matching path are terminated. To terminate all matching applications, you have to execute the function, until it returns error 3 ("Path not found").
The parameter is not case sensitive.
The parameter is ignored, if you assign the parameters lngProcessID or strApplication.

booForce (optional)
Specifies, whether the function should kill the process, if it cannot be terminated cleanly within a specified time period (parameter lngWait). The parameter is ignored, if you omitt parameter lngWait. The default value is False.

lngWait (optional)
Specifies the time in milliseconds, the function waits for the termination of the process. It is possible, that the process does not terminate within this period. Then, if you have assigned parameter booForce to True, the function kills the process. Otherwise, the function returns error 258 (WAIT_TIMEOUT).
If the period is longer than the termination of the process has finished, the function waits for the rest of the time.
If you want to be sure, that the function waits until the process really terminates, assign INFINITE to the parameter. But there can be sometimes a problem, when the process hangs. So, in the most cases, it is better to specify a time period.
If you omitt the parameter, the function does not wait for the termination (lngWait = 0).

Remarks

All of the first three parameters of the function are optional. But nevertheless, you have to assign at least one of them. Otherwise, the function returnes an error 87.
To start a process on the local machine, use function StartProcess of this class.

See also:

FormatAPIMessage
ProcessPID
ModuleFileName
ModuleBaseName
INFINITE
StartProcess

Example (early binding)

Dim proc As New Process
Dim dll As New DllClass
lRes As Long

lRes = proc.EndProcess(, "microsoft word*", , True, 10000)
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

lRes = proc.EndProcess(, , "c:\winnt\regedit.exe")
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

lRes = proc.EndProcess(, , "control.exe", , 10000)
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))


ExitCode As Long

Class Process

Wednesday, December 05, 2001

ExitCode As Long

Property (read only)

Return value

Returns the ExitCode of an application when it terminates. This property is not initialized with SetBaseName like the other properties of this class and it is not a property of a member of the collection Processes . The property is filled with information by function StartProcess of this class. But only, if you specify, that the function should wait for the termination of the started process. Normally, a process terminates with ExitCode 0 (zero).

See also:

StartProcess
SetBaseName
Processes

Example (early binding)

Dim proc As New Process, lRes As Long
Dim dll As New DllClass

lRes = proc.StartProcess("c:\winnt\regedit.exe", proc.INFINITE, True)

MsgBox "ExitCode: " & proc.ExitCode
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))


INFINITE As Long

Class Process

Wednesday, December 05, 2001

INFINITE As Long

Property (read only)

Return value

Returns a value, that you can use like a constant in functions of this class ( StartProcess , EndProcess ). The property instructs these functions, to wait for the termination of a process as long as the process is still alive (in contrast to a specific time to wait). This can sometimes cause problems, when the process hangs, but in the most cases, the processes terminate regulary.

See also:

StartProcess
EndProcess

Example1 - starting a process (early binding)

Dim proc As New Process, lRes As Long
Dim dll As New DllClass

lRes = proc.StartProcess("c:\winnt\regedit.exe", proc.INFINITE, True)

MsgBox "ExitCode: " & proc.ExitCode
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

Example2 - ending a process (late binding)

Dim proc, lRes
Dim dll

Set proc = CreateObject("ntXdll.Process")
Set dll = CreateObject("ntXdll.DllClass")

lRes = proc.EndProcess(, "microsoft word*", , , proc.INFINITE)

MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))


ConsoleCursorPosX As IntegerConsoleCursorPosY As Integer

Class Consoler

Saturday, June 17, 2000

Class Consoler

This class is used to handle console windows (like the little command window).

Console windows normally support multiple screenbuffers through which you can switch to display different screen outputs (or read different screen inputs). In this version of ntXdll, only one screenbuffer is supported, but it is planed to wide the functionality in later versions. Up to then, you have to overwrite the current screenbuffer in order to display a different output (or read a different screen input).

You have a few features to work with the console. You can write to the console ( ConsoleWrite ) and read the console ( ConsoleRead - this is the reading of console inputs). For this tasks, you have to open a console with function ConsoleOpen at first.

You can change a lot of attributes of a console (like ConsoleTextMode , ConsoleCursorSize , ConsoleWindowPos and so on). For this tasks, you have to open a console with function ConsoleOpen at first. To change console properties, you have to assign a value of the right type to the property (syntax: <consoler object>.<property> = <value>). Read the help to each property to determine, whether you can change it or whether it is read only.

You can read events to the console, like ConsoleEventFocus , ConsoleEventKey , ConsoleEventMouse and so on. For this tasks, you have to open a console with function ConsoleOpen at first.

For detailed information, look at the help to each function or property.


ConsoleLastError As Long

Class Console

Saturday, June 17, 2000

ConsoleLastError As Long

Property (read only)

Return value

Returns the last error, which is generated by the different properties or functions of this class. The most functions or properties, which are not read only, are not returning an error number. Instead of this, the property ConsoleLastError is set. The property is 0 (zero) if no error occurrs, otherwise a nonzero value. This value can be an VisualBasic or an API error number. To translate API error, you can use the function FormatAPIMessage of class DLLClass. To determine, which functions or properties of this class are setting the ConsoleLastError, read the documentation of each function or property. You have to open a conaole with function ConsoleOpen before using this property.

See also

ConsoleOpen()
FormatAPIMessage

Example

Dim con As Object
Dim lngResult As Long
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

con.ConsoleInputCP = 437
If con.ConsoleLastError <> 0 Then Exit Sub
lngResult = con.ConsoleWrite("ConsoleInputCP: " & con.ConsoleInputCP)

End If


ConsoleOpen() As Long

Class Console

Saturday, June 17, 2000

ConsoleOpen() As Long

Function

Return value

Returns 0 (zero) if the function succeeds, otherwise a nonzero value. This can be a VisualBasic or an API error number. The function opens a console window.

See also

ConsoleClose()

Example

Dim con As Object
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

lngResult = con.ConsoleWrite("ConsoleInputMode before: " & con.ConsoleInputModeStr & vbCrLf)
con.ConsoleInputMode = con.ConsoleInputMode And Not con.ENABLE_PROCESSED_INPUT
If con.ConsoleLastError <> 0 Then Exit Sub
llngResult = con.ConsoleWrite("ConsoleInputMode after: " & con.ConsoleInputModeStr)

End If


ConsoleClose() As Long

Class Console

Saturday, June 17, 2000

ConsoleClose() As Long

Function

Return value

If the function succeeds, the return value is 0. If an error occurs, the return value is nonzero. This can be an error number from VB or an API error number. The function closes a console which is opened before by the function ConsoleOpen () of this class. If you try to execute the function without an opened console, no error is returned.

See also

ConsoleOpen()

Example

Dim con As Object
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

MsgBox "After this msgbox, the console will be closed"
con.ConsoleClose

End If


ConsoleTitle As String

Class Console

Saturday, June 17, 2000

ConsoleTitle As String

Property

Return value

Returns or sets the consoles title. You have to open a console before using this properties. To determine, whether the setting or reading of this property was successfully, see the Property ConsoleLastError of this class. This property can be an VB or an API error number. If the function succeeds, ConsoleLastError is 0.

See also

ConsoleOpen()
ConsoleLastError

Example

Dim con As Object
Dim lngResult As Long
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

con.ConsoleTitle = "My test console application"
If con.ConsoleLastError <> 0 Then MsgBox "Error setting title"

End If


ConsoleTextMode As Long

Class Console

Saturday, June 17, 2000

ConsoleTextMode As Long

Property

Return value

Returns or sets the foreground (text) and background color attributes to be used for characters that are written to a screen buffer by the ConsoleWrite (...) function of this class, or echoed to a screen buffer by the ConsoleRead (...) function of this class. The attribute values are some combination of the following properties of this class:

FOREGROUND_BLUE
FOREGROUND_GREEN
FOREGROUND_RED
FOREGROUND_INTENSITY
BACKGROUND_BLUE
BACKGROUND_GREEN
BACKGROUND_RED
BACKGROUND_INTENSITY
( BACKGROUND_* and FOREGROUND_* properties )

You have to open a console with function ConsoleOpen before using this properties. To determine, whether the setting or reading of this property succeeded, see the Property ConsoleLastError of this class. This property can be an VB or an API error number. If the function succeeds, ConsoleLastError is 0.

For better reading the text mode of a console, you can use ConsoleTextModeStr of this class (returns a string).

See also

ConsoleOpen()
ConsoleLastError
BACKGROUND* Properties
FOREGROUND* Properties
ConsoleTextModeStr

Example

Dim con As Object
Dim lngResult As Long
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

lngResult = con.ConsoleWrite("ConsoleTextMode before: " & con.ConsoleTextModeStr & vbCrLf)
con.ConsoleTextMode = con.FOREGROUND_RED Or con.FOREGROUND_INTENSITY Or _
con.BACKGROUND_GREEN
If con.ConsoleLastError <> 0 Then MsgBox "Error setting textmode"
llngResult = con.ConsoleWrite("ConsoleTextMode after: " & con.ConsoleTextModeStr)

End If


ConsoleTextModeStr As String

Class Console

Saturday, June 17, 2000

ConsoleTextModeStr As String

Property (read only)

Return value

Returns in string format the foreground (text) and background color attributes to be used for characters that are written to a screen buffer by the ConsoleWrite (...) function of this class, or echoed to a screen buffer by the ConsoleRead (...) function of this class. The return value can be one or more of the following strings seeperated by a semicolon:

"FOREGROUND_BLUE"
"FOREGROUND_GREEN"
"FOREGROUND_RED"
"FOREGROUND_INTENSITY"
"BACKGROUND_BLUE"
"BACKGROUND_GREEN"
"BACKGROUND_RED"
"BACKGROUND_INTENSITY"

You have to open a console with function ConsoleOpen before using this properties. To determine, whether the reading of this property was successfully, see the Property ConsoleLastError of this class. This property can be an VB or an API error number. If the function succeeds, ConsoleLastError is 0. For setting the consoles text mode, use ConsoleTextMode of this class.

See also

ConsoleOpen()
ConsoleLastError
ConsoleTextMode
BACKGROUND* Properties
FOREGROUND* Properties

Example

Dim con As Object
Dim lngResult As Long
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

lngResult = con.ConsoleWrite("ConsoleTextMode before: " & con.ConsoleTextModeStr & vbCrLf)
con.ConsoleTextMode = con.FOREGROUND_RED Or con.FOREGROUND_INTENSITY Or _
con.BACKGROUND_GREEN
If con.ConsoleLastError <> 0 Then MsgBox "Error setting textmode"
llngResult = con.ConsoleWrite("ConsoleTextMode after: " & con.ConsoleTextModeStr)

End If


BACKGROUND_

Class Console

Saturday, June 17, 2000

BACKGROUND_RED As Long
BACKGROUND_GREEN As Long
BACKGROUND_BLUE As Long
BACKGROUND_INTENSITY As Long

FOREGROUND_RED As Long
FOREGROUND_GREEN As Long
FOREGROUND_BLUE As Long
FOREGROUND_INTENSITY As Long

Properties (read only)

Return value

The properties are used to set the property ConsoleTextMode in this class or to execute the function FillConsoleWithAttribute (...) of this class. They return background and foreground color attributes of console text. Any combination of the properties can be specified with the 'Or' or the '+' operator. But at first you have to open a console with function ConsoleOpen () of this class.

See also

ConsoleOpen()
ConsoleTextMode
FillConsoleWithAttribute(...)

Example

Dim con As Object
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

con.ConsoleTextMode = con.BACKGROUND_GREEN or con.FOREGROUND_BLUE
con.ConsoleWrite("Now see the attributes of the displayed text")

End If


ConsoleScreenBufferSizeX As IntegerConsoleScreenBufferSizeY As Integer

Class Console

Saturday, June 17, 2000

ConsoleScreenBufferSizeX As Integer
ConsoleScreenBufferSizeY As Integer

Properties

Return value

Return or set the size in rows and columns of the console screen buffer. The specified width and height cannot be less than the width and height of the screen buffer's window ( ConsoleWindowPos* properties ). The specified dimensions also cannot be less than the minimum size allowed by the system. This minimum depends on the current font size for the console (selected by the user) and the minimum and maximum size of a window in the system.

You have to open a console with function ConsoleOpen before using this properties.

To set several console window properties, look under 'See also'. To see, whether the setting or reading of the properties was successfull, see the property ConsoleLastError . This property can be an VB or an API error number. In case of success, ConsoleLastError is 0.

See also

ConsoleOpen()
ConsoleLastError
ConsoleWindowPosTop, Left, Bottom, Right
ConsoleMaxWindowSizeX, Y

Example

Dim con As Object
Dim lngResult As Long
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

'increasing the size
'Remarks: if you want to decrease the screen buffer less than the window size, at first
'decrease the window size with properties ConsoleWindowPos*
con.ConsoleScreenBufferSizeX = con.ConsoleScreenBufferSizeX + 10
If con.ConsoleLastError <> 0 Then MsgBox "Error setting X"
con.ConsoleScreenBufferSizeY = con.ConsoleScreenBufferSizeY + 10
If con.ConsoleLastError <> 0 Then MsgBox "Error setting Y"

End If


ConsoleCursorPosX As IntegerConsoleCursorPosY As Integer

Class Console

Saturday, June 17, 2000

ConsoleCursorPosX As Integer
ConsoleCursorPosY As Integer

Properties

Return value

Return or set the cursor position in the console screen buffer. The properties specifiy the column and row of a screen buffer character cell. The coordinates must be within the boundaries of the screen buffer. To see, whether the setting or reading of the cursor position succeeds, see the property ConsoleLastError . This property can be an VB or an API error number. If the function succeeds, ConsoleLastError is 0. The cursor position specifies, where text in the console is displayed, which is written by the function ConsoleWrite (...) or echoed by the function ConsoleRead (...) of this class. You have to open a console with function ConsoleOpen before using this properties.

See also

ConsoleOpen()
ConsoleLastError
ConsoleCursorSize
ConsoleCursorVisible
ConsoleRead
ConsoleWrite

Example

Dim con As Object
Dim lngResult As Long
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

con.ConsoleCursorPosX = 10
If con.ConsoleLastError <> 0 Then Exit Sub
con.ConsoleCursorPosY = 10
If con.ConsoleLastError <> 0 Then Exit Sub
lngResult = con.ConsoleWrite("Now see the text at the current cursor position: " & con.ConsoleCursorPosX & _
"/" & con.ConsoleCursorPosY)

End If


ConsoleCursorSize As Long

Class Console

Saturday, June 17, 2000

ConsoleCursorSize As Long

Property

Return value

Returns or set the cursor size of a console. This is a number between 1 and 100, indicating the percentage of the character cell that is filled by the cursor. The cursor appearance varies, ranging from completely filling the cell to showing up as a horizontal line at the bottom of the cell. To see, whether the setting or reading of the cursor size succeeds, see the property ConsoleLastError . This property can be an VB or an API error number. If the function succeeds, ConsoleLastError is 0. You have to open a console with function ConsoleOpen before using this property.

See also

ConsoleOpen()
ConsoleLastError
ConsoleCursorPosX, Y
ConsoleCursorVisible

Example

Dim con As Object
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

con.ConsoleCursorSize = 100
If con.ConsoleLastError <> 0 Then Exit Sub
MsgBox con.ConsoleCursorSize

End If


ConsoleCursorVisible As Boolean

Class Console

Saturday, June 17, 2000

ConsoleCursorVisible As Boolean

Property

Return value

Returns or sets the cursor visibility of a console. If ConsoleCursorVisible is True or set True, the cursor is visible. Otherwise ConsoleCursorVisible is False or must be set False. To see, whether the setting or reading of the cursor size succeeds, see the property ConsoleLastError . This property can be an VB or an API error number. If the property succeeds, ConsoleLastError is 0. You have to open a console with function ConsoleOpen before using this property.

See also

ConsoleOpen()
ConsoleLastError
ConsoleCursorPosX, Y
ConsoleCursorSize

Example

Dim con As Object
Dim lngResult As Long
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

con.ConsoleCursorVisible = False
If con.ConsoleLastError <> 0 Then Exit Sub
lngResult = con.ConsoleWrite(con.ConsoleCursorVisible)

End If


ConsoleMouseButtons As Long

Class Console

Saturday, June 17, 2000

ConsoleMouseButtons As Long

Property (read only)

Return value

Returns the number of buttons on the mouse used by the current console. You have to open a console with function ConsoleOpen before using the property. To see, whether the reading of the property succeeds, see the property ConsoleLastError . This property can be an VB or an API error number. If the reading succeeds, ConsoleLastError is 0.

See also

ConsoleOpen()
ConsoleLastError

Example

Dim con As Object
Dim lngResult as Long
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

lngResult = con.ConsoleWrite("ConsoleMouseButtons: " & con.ConsoleMouseButtons)

End If


ConsoleInputCP As Long

Class Console

Saturday, June 17, 2000

ConsoleInputCP As Long

Property

Return value

Returns or sets the input code page used by the console associated with the calling process. A console uses its input code page to translate keyboard input into the corresponding character value. By setting the property, specify the identifier of the code page to set. The identifiers of the code pages available on the local computer are stored in the registry under the following key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage

A code page maps 256 character codes to individual characters. Different code pages include different special characters, typically customized for a language or a group of languages.

You have to open a console with function ConsoleOpen before using the property. To see, whether the setting or reading of the input codepage succeeds, see the property ConsoleLastError . This property can be an VB or an API error number. If the function succeeds, ConsoleLastError is 0.

See also

ConsoleOpen()
ConsoleLastError
ConsoleRead(...)
ConsoleOutputCP

Example

Dim con As Object
Dim lngResult As Long
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

con.ConsoleInputCP = 437
If con.ConsoleLastError <> 0 Then Exit Sub
lngResult = con.ConsoleWrite("ConsoleInputCP: " & con.ConsoleInputCP)

End If


ConsoleOutputCP As Long

Class Console

Saturday, June 17, 2000

ConsoleOutputCP As Long

Property

Return value

Returns or sets the output code page used by the console associated with the calling process. A console uses its output code page to translate the character values written by the various output functions into the images displayed in the console window. By setting the property, specify the identifier of the code page to set. The identifiers of the code pages available on the local computer are stored in the registry under the following key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage

A code page maps 256 character codes to individual characters. Different code pages include different special characters, typically customized for a language or a group of languages.

You have to open a console with function ConsoleOpen before using the property. To see, whether the setting or reading of the input codepage succeeds, see the property ConsoleLastError . This property can be an VB or an API error number. If the function succeeds, ConsoleLastError is 0.

See also

ConsoleOpen()
ConsoleLastError
ConsoleInputCP
ConsoleWrite(...)

Example

Dim con As Object
Dim lngResult As Long
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

con.ConsoleOutputCP = 437
If con.ConsoleLastError <> 0 Then Exit Sub
lngResult = con.ConsoleWrite("ConsoleOutputCP: " & con.ConsoleOutputCP)

End If


ConsoleInputMode As Long

Class Console

Saturday, June 17, 2000

ConsoleInputMode As Long

Property

Return value

Returns or sets the input mode of a console's input buffer.

Explanation

A console consists of an input buffer and one or more screen buffers (in this version of class Consoler, only one ScreenBuffer is supplied). The mode of a console buffer determines how the console behaves during input and output (I/O) operations. One set of flag constants is used with input handles, and another set is used with screen buffer (output) handles. Setting the output modes of one screen buffer does not affect the output modes of other screen buffers.

For setting the property, use the ENABLE_* properties of this class. When a console is created, all input modes except ENABLE_WINDOW_INPUT are enabled by default. See the help of this properties (which compinations are allowed in which property).

You have to open a console with function ConsoleOpen before using the property. To see, whether the setting or reading of the input mode succeeds, see the property ConsoleLastError . This property can be an VB or an API error number. If the function succeeds, ConsoleLastError is 0. For better reading the input mode settings of a console, you can use ConsoleInputModeStr of this class (returns a string).

For setting and reading the output modes, use the property ConsoleOutputMode and ConsoleOutputModeStr .

See also

ConsoleOpen()
ConsoleLastError
ConsoleInputModeStr
ConsoleOutputMode
ConsoleOutputModeStr
ENABLE* Properties
ConsoleRead(...)

Example

Dim con As Object
Dim lngResult As Long
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

lngResult = con.ConsoleWrite("ConsoleInputMode before: " & con.ConsoleInputModeStr & vbCrLf)
con.ConsoleInputMode = con.ConsoleInputMode And Not con.ENABLE_PROCESSED_INPUT
If con.ConsoleLastError <> 0 Then Exit Sub
llngResult = con.ConsoleWrite("ConsoleInputMode after: " & con.ConsoleInputModeStr)

End If


ConsoleInputModeStr As String

Class Console

Saturday, June 17, 2000

ConsoleInputModeStr As String

Property (read only)

Return value

Returns the input mode of a console's input buffer by a string. This property is only supplied for a better reading the input mode and has no importance for setting the mode. The property may return any combination of the following strings, separated by a semicolon:

"ENABLE_ECHO_INPUT"
"ENABLE_LINE_INPUT"
"ENABLE_MOUSE_INPUT"
"ENABLE_PROCESSED_INPUT"
"ENABLE_WINDOW_INPUT"

You have to open a console with function ConsoleOpen before using the property.

To see, whether the reading of the property succeeds, see the property ConsoleLastError . This property can be an VB or an API error number. If the reading succeeds, ConsoleLastError is 0.

For setting the input mode of a console, use the property ConsoleInputMode . For reading the output modes, use the property ConsoleOutputModeStr .

See also

ConsoleOpen()
ConsoleLastError
ConsoleInputMode
ConsoleOutputMode
ConsoleOutputModeStr
ENABLE* Properties

Example

Dim con As Object
Dim lngResult As Long
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

lngResult = con.ConsoleWrite("ConsoleInputMode before: " & con.ConsoleInputModeStr & vbCrLf)
con.ConsoleInputMode = con.ConsoleInputMode And Not con.ENABLE_PROCESSED_INPUT
If con.ConsoleLastError <> 0 Then Exit Sub
llngResult = con.ConsoleWrite("ConsoleInputMode after: " & con.ConsoleInputModeStr)

End If


ConsoleOutputMode As Long

Class Console

Saturday, June 17, 2000

ConsoleOutputMode As Long

Property

Return value

Returns or sets the output mode of a console's ScreenBuffer.

Explanation

A console consists of an input buffer and one or more screen buffers (in this version of class Consoler, only one ScreenBuffer is supplied). The mode of a console buffer determines how the console behaves during input and output (I/O) operations. One set of flag constants is used with input handles, and another set is used with screen buffer (output) handles. Setting the output modes of one screen buffer does not affect the output modes of other screen buffers.

For setting the property, use the ENABLE_* properties of this class. When a screen buffer is created, both output modes are enabled by default. See the help of this properties (which compinations are allowed in which property).

You have to open a console with function ConsoleOpen before using the property.

To see, whether the setting of the output mode succeeds, see the property ConsoleLastError . This property can be an VB or an API error number. If the function succeeds, ConsoleLastError is 0.

For better reading the ouput mode settings of a console, you can use ConsoleOutputModeStr of this class (returns a string). For setting and reading the input modes, use the properties ConsoleInputMode and ConsoleInputModeStr .

See also

ConsoleOpen()
ConsoleLastError
ConsoleInputMode
ConsoleOutputModeStr
ENABLE* Properties
ConsoleWrite(...)

Example

Dim con As Object
Dim lngResult As Long
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

lngResult = con.ConsoleWrite("ConsoleOutputMode before: " & con.ConsoleOutputModeStr & vbCrLf)
con.ConsoleOutputMode = con.ConsoleOutputMode And Not con.ENABLE_WRAP_AT_EOL_OUTPUT
If con.ConsoleLastError <> 0 Then Exit Sub
llngResult = con.ConsoleWrite("ConsoleOutputMode after: " & con.ConsoleOutputModeStr)

End If


ConsoleOutputModeStr As String

Class Console

Saturday, June 17, 2000

ConsoleOutputModeStr As String

Property (read only)

Return value

Returns the output mode of a console's screen buffer by a string. This property is only supplied for a better reading the output mode and has no importance for setting the mode. To see, whether the reading of the output mode succeeds, see the property ConsoleLastError . This property can be an VB or an API error number.The property ConsoleOutputModeStr may return any combination of the following strings, separated by a semicolon:

"ENABLE_PROCESSED_OUTPUT"
"ENABLE_WRAP_AT_EOL_OUTPUT"

You have to open a console with function ConsoleOpen before using the property. For reading the input modes, use the property ConsoleInputModeStr . For setting the ouput mode of a console, use the property ConsoleOutputMode .

See also

ConsoleOpen()
ConsoleLastError
ConsoleInputMode
ConsoleOutputMode
ENABLE* Properties

Example

Dim con As Object
Dim lngResult As Long
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

lngResult = con.ConsoleWrite("ConsoleOutputMode before: " & con.ConsoleOutputModeStr & vbCrLf)
con.ConsoleOutputMode = con.ConsoleOutputMode And Not con.ENABLE_WRAP_AT_EOL_OUTPUT
If con.ConsoleLastError <> 0 Then Exit Sub
llngResult = con.ConsoleWrite("ConsoleOutputMode after: " & con.ConsoleOutputModeStr)

End If


ENABLE_

Class Console

Saturday, June 17, 2000

ENABLE_ECHO_INPUT As Long
ENABLE_LINE_INPUT As Long
ENABLE_MOUSE_INPUT As Long
ENABLE_PROCESSED_INPUT As Long
ENABLE_WINDOW_INPUT As Long

ENABLE_PROCESSED_OUTPUT As Long
ENABLE_WRAP_AT_EOL_OUTPUT As Long

Properties (read only)

Return value

The properties are used like constants in the properties ConsoleInputMode and ConsoleOutputMode to set the modes of a console. Use only the *_INPUT properties to set the property ConsoleInputMode and use only the *_OUTPUT properties to set the property ConsoleOutputMode .

You have to open a console with function ConsoleOpen before using the properties. When a console is created, all input modes except ENABLE_WINDOW_INPUT are enabled by default and both output modes are enabled by default. You can use one or more of this properties. Using more than one mode, combine the properties with the 'Or' or '+' operator.

ENABLE_ECHO_INPUT
Characters read by the ConsoleRead (...) function of this class are written to the active screen buffer as they are read. This mode can be used only if the ENABLE_LINE_INPUT mode is also enabled.
ENABLE_LINE_INPUT
The ConsoleRead (...) function of this class returns only when a carriage return character is read. If this mode is disabled, the functions return when one or more characters are available.
ENABLE_MOUSE_INPUT
If the mouse pointer is within the borders of the console window and the window has the keyboard focus, mouse events generated by mouse movement and button presses are placed in the input buffer. These events are discarded by the ConsoleRead (...) function of this class, even when this mode is enabled. But Information about these events can be read from the input buffer by applications using the function InitConsoleEvents (...) of this class
ENABLE_PROCESSED_INPUT
CTRL+C is processed by the system and is not placed in the input buffer. If the input buffer is being read by the ConsoleRead (...) function of this class, other control keys are processed by the system and are not returned in the ConsoleRead (...) buffer. If the ENABLE_LINE_INPUT mode is also enabled, backspace, carriage return, and linefeed characters are handled by the system.
ENABLE_WINDOW_INPUT
User interactions that change the size of the console screen buffer are reported in the console's input buffer. Information about these events can be read from the input buffer by applications using the function InitConsoleEvents (...) of this class, but not by those using ConsoleRead (...).

ENABLE_PROCESSED_OUTPUT
Characters written by the ConsoleWrite (...) function of this classs or echoed by the ConsoleRead (...) function of this class are examined for ASCII control sequences and the correct action is performed. Backspace, tab, bell, carriage return, and linefeed characters are processed.
ENABLE_WRAP_AT_EOL_OUTPUT
When writing with ConsoleWrite (...) or echoing with ConsoleRead (...), the cursor moves to the beginning of the next row when it reaches the end of the current row. This causes the rows displayed in the console window to scroll up automatically when the cursor advances beyond the last row in the window. It also causes the contents of the screen buffer to scroll up (discarding the top row of the screen buffer) when the cursor advances beyond the last row in the screen buffer. If this mode is disabled, the last character in the row is overwritten with any subsequent characters.

See also

ConsoleOpen()
ConsoleInputMode
ConsoleOutputMode
InitConsoleEvents
ConsoleRead(...)
ConsoleWrite(...)

Example

Dim con As Object
Dim lngResult As Long
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

lngResult = con.ConsoleWrite("ConsoleOutputMode before: " & con.ConsoleOutputModeStr & vbCrLf)
con.ConsoleOutputMode = con.ConsoleOutputMode And Not con.ENABLE_WRAP_AT_EOL_OUTPUT
If con.ConsoleLastError <> 0 Then Exit Sub
llngResult = con.ConsoleWrite("ConsoleOutputMode after: " & con.ConsoleOutputModeStr & vbCrLf)

lngResult = con.ConsoleWrite("ConsoleInputMode before: " & con.ConsoleInputModeStr & vbCrLf)
con.ConsoleInputMode = con.ConsoleInputMode And Not con.ENABLE_PROCESSED_INPUT
If con.ConsoleLastError <> 0 Then Exit Sub
llngResult = con.ConsoleWrite("ConsoleInputMode after: " & con.ConsoleInputModeStr)

End If


ConsoleMaxWindowSizeX As IntegerConsoleMaxWindowSizeY As Integer

Class Console

Saturday, June 17, 2000

ConsoleMaxWindowSizeX As Integer
ConsoleMaxWindowSizeY As Integer

Properties (read only)

Return value

Return the maximum size of the console window, given the current screen buffer size and font and the screen size. You have to open a console with function ConsoleOpen before using this properties. To set several console window properties, look under 'See also'. To see, whether the reading of the properties succeeds, see the property ConsoleLastError . This property can be an VB or an API error number. If the reading succeeds, ConsoleLastError is 0.

See also

ConsoleOpen()
ConsoleScreenBufferSizeX, Y
ConsoleWindowPosTop, Left, Bottom, Right

Example

Dim con As Object
Dim lngResult As Long
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

lngResult = con.ConsoleWrite("ConsoleMaxWindowSizeX/Y: " & _
con.ConsoleMaxWindowSizeX & "/" & con.ConsoleMaxWindowSizeY)

End If


ConsoleWindowPosTop As IntegerConsoleWindowPosLeft As IntegerConsoleWindowPosBottom As IntegerConsoleWindowPosRight As Integer

Class Console

Saturday, June 17, 2000

ConsoleWindowPosTop As Integer
ConsoleWindowPosLeft As Integer
ConsoleWindowPosBottom As Integer
ConsoleWindowPosRight As Integer

Properties

Return value

Return or set the current size and position of a console screen buffer's window. The properties fail if the specified window rectangle extends beyond the boundaries of the screen buffer. This means that the Top and Left members of the properties cannot be less than zero. Similarly, the Bottom and Right members cannot be greater than screen ConsoleScreenBufferSizeY - 1 and ConsoleScreenBufferSizeX - 1, respectively.

The properties also fail if the Right member is less than or equal to the Left member or if the Bottom member is less than or equal to the Top member.

For consoles with more than one screen buffer, changing the window location for one screen buffer does not affect the window locations of the other screen buffers. In this version of class Consoler, only one screen buffer is supported.

To determine the current size and position of a screen buffer's window, use the properties ConsoleScreenBufferSizeX and ConsoleScreenBufferSizeY . To determine the maximum size of the window, use the properties ConsoleMaxWindowSizeX and ConsoleMaxWindowSizeY of this class.

The ConsoleWindowsPos* properties can be used to scroll the contents of the screen buffer by shifting the position of the window rectangle without changing its size.

You have to open a console with function ConsoleOpen before using this properties. To set several console window properties, look under 'See also'. To see, whether the setting or reading of the properties was successfull, see the property ConsoleLastError . This property can be an VB or an API error number. In case of success, ConsoleLastError is 0.

See also

ConsoleOpen()
ConsoleLastError
ConsoleScreenBufferSizeX, Y
ConsoleMaxWindowSizeX, Y

Example

Dim con As Object
Dim lngResult As Long
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

con.ConsoleWindowPosTop = 0
msgbox "ConsoleLastError: " & con.ConsoleLastError
con.ConsoleWindowPosLeft = 0
msgbox "ConsoleLastError: " & con.ConsoleLastError
con.ConsoleWindowPosBottom = 19
msgbox "ConsoleLastError: " & con.ConsoleLastError
con.ConsoleWindowPosRight = 39
msgbox "ConsoleLastError: " & con.ConsoleLastError

End If


ConsoleRead(...) As String

Class Console

Saturday, June 17, 2000

ConsoleRead ([strDefault As String = "unknown"]) As String

Function

Return value

The function reads character input from the console input buffer and removes it from the buffer. It returns strDefault, if an error occurs. In addition, to see, whether the reading succeeded, you can read the property ConsoleLastError . This property can be an VB or an API error number. If the console reading succeeds, ConsoleLastError is 0.

The function echoes consoleinputs from the current cursor position. The ConsoleCursorPos* properties set or return the current cursor position. The function does not return until at least one input record has been read. Use the property ConsoleUnread to determine, whether there are input records to read.

Characters are echoed using the foreground and background color attributes associated with the screen buffer. The property ConsoleTextMode changes or returns these colors.

You have to open a console with function ConsoleOpen before using the function.

See also

ConsoleOpen()
ConsoleLastError
ConsoleUnread
ConsoleInputMode
ConsoleInputCP
ConsoleTextMode
ConsoleCursorPosX, Y
ConsoleWrite(...)

Example

Dim con As Object
Dim lngResult As Long
Dim s As String
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

lngResult = con.ConsoleWrite("Now enter a few chars and press ENTER")
s = con.ConsoleRead()
If con.ConsoleLastError <> 0 Then MsgBox "Error reading from console"
MsgBox s

End If


ConsoleWrite(...) As Long

Class Console

Saturday, June 17, 2000

ConsoleWrite (ByVal strString As String) As Long

Function

Return value

The function writes a string to the console output buffer. It returns 0 in case of success, otherwise a nonzero value if an error occurs. This property can be an VB or an API error number.

You have to open a console with function ConsoleOpen before using the function.

The function writes to the current cursor position. The cursor position advances as characters are written. The ConsoleCursorPos* properties set or return the current cursor position. Characters are written using the foreground and background color attributes associated with the screen buffer. The property ConsoleTextMode changes or returns these colors.

See also

ConsoleOpen()
ConsoleOutputMode
ConsoleOutputCP
ConsoleTextMode
ConsoleCursorPosX, Y
ConsoleWrite(...)

Example

Dim con As Object
Dim lngResult As Long
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

lngResult = con.ConsoleWrite("Writing to my test console application")
If lngResult <> 0 Then MsgBox "Error writing"

End If


FillConsoleWithChar(...) As Long

Class Console

Saturday, June 17, 2000

FillConsoleWithChar (strChar As String, lngRepeat As Long, [intPosX As Integer], [intPosY As Integer]) As Long

Function

Return value

The function writes a character to the screen buffer a specified number of times, beginning at the specified coordinates in a screen buffer. If the number of characters to write to extends beyond the end of the specified row in the screen buffer, characters are written to the next row. If the number of characters to write to extends beyond the end of the screen buffer, the characters are written up to the end of the screen buffer. The attribute values at the positions written are not changed.

The function returns the number of chars written to the console.

To see, whether the function succeeded, you can read the property ConsoleLastError . This property can be an VB or an API error number. If the console reading succeeds, ConsoleLastError is 0. You have to open a console with function ConsoleOpen before using the function.

Parameters

strChar
specifies the char to write to the screen buffer

lngRepeat
specifies the number of chars to write

intPosX, IntPosY
specify the coordinates to begin. If this parameters are omitted, 0 (zero) is the default value.

See also

ConsoleOpen()
ConsoleLastError
ConsoleOutputCP
ConsoleInputCP
FillConsoleWithAttribute(...)

Example

Dim con As Object
Dim lngResult As Long
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

lngResult = con.FillConsoleWithChar("@", con.ConsoleScreenBufferSizeX * con.ConsoleScreenBufferSizeY)
If lngResult <> 0 Then MsgBox "Error filling chars"

End If


FillConsoleWithAttribute(...) As Long (

Class Console

Saturday, June 17, 2000

FillConsoleWithAttribute (lngAttribute As Long, lngRepeat As Long, [intPosX As Integer], [intPosY As Integer]) As Long

Function

Return value

The function sets the text and background color attributes for a specified number of character cells, beginning at the specified coordinates in a screen buffer.

The function returns the number of the cells setting with the specified attributes. If the number of character cells whose attributes are to be set extends beyond the end of the specified row in the screen buffer, the cells of the next row are set. If the number of cells to write to extends beyond the end of the screen buffer, the cells are written up to the end of the screen buffer. The character values at the positions written to are not changed.

To see, whether the setting succeeded, you can read the property ConsoleLastError . This property can be an VB or an API error number. If the console reading succeeds, ConsoleLastError is 0. You have to open a console with function ConsoleOpen before using the function.

Parameters

lngAttribute
specifies the attributes and can be one or more of the BACKGROUND_* and FOREGROUND_* properties

lngRepeat
specifies the number of cells to set with the attributes

intPosX, IntPosY
specify the coordinates to begin setting the attributes. If this parameters are omitted, 0 (zero) is the default value.

See also

ConsoleOpen()
BACKGROUND* Properties
FOREGROUND* Properties
ConsoleLastError
ConsoleTextMode
FillConsoleWithChar(...)

Example

Dim con As Object
Dim lngResult As Long
Set con = CreateObject("ntXdll.Consoler")
If con.ConsoleOpen() = 0 Then

lngResult = con.FillConsoleWithAttribute(con.BACKGROUND_GREEN Or con.BACKGROUND_RED, _
con.ConsoleScreenBufferSizeX * con.ConsoleScreenBufferSizeY)
If lngResult <> 0 Then MsgBox "Error setting attributes"

End If


ConsoleUnread As Long

Class Console

Saturday, June 17, 2000

ConsoleUnread As Long

Property (read only)

Return value

Returns the number of console events, which are buffered for reading in the consoles screenbuffer. Console events are members of the collection ConsoleEvents of the class Consoler. You have to execute the function InitConsoleEvents (...) of this class before reading the collection. With the property ConsoleUnread, you are able to determine, how much members would be in the collection before executing the function InitConsoleEvents (...).

You have to open a console with function ConsoleOpen before using the property. To determine, whether the reading of this property was successfully, see the Property ConsoleLastError of this class. This property can be an VB or an API error number. If the function succeeds, ConsoleLastError is 0.

See also

ConsoleOpen()
ConsoleLastError
InitConsoleEvents(...)
ConsoleEvents
ConsoleEventType
ConsoleEventsFlush()

Example

Look at the example at the help of the function InitConsoleEvents()


InitConsoleEvents(...) As Long

Class Console

Saturday, June 17, 2000

InitConsoleEvents([booPeek As Boolean]) As Long

Function

Return value

The function inits the collection ConsoleEvents of this class. It returns 0 in case of success, otherwise a nonzero value if an error occurs. This property can be an VB or an API error number.

Console events can be of the type KEY_EVENT , MOUSE_EVENT , WINDOW_BUFFER_SIZE_EVENT , MENU_EVENT or FOCUS_EVENT . Depend on the type of the event, different properties of the class are filled with information. For example, if a KEY_EVENT happens in the console, the ConsoleEventMouse* properties are empty.

You have to execute the function InitConsoleEvents(...) of this class before reading the collection ConsoleEvents . You have to open a console before executing InitConsoleEvents(...). With property ConsoleUnread , you can discover, whether any console events are to read in the console buffer.

Parameters

booPeek
if you assign this parameter as True, the function doesn't remove the event records from the console screen buffer. So, the property ConsoleUnread isn't 0 (zero) after executing InitConsoleEvents(...). It has the same value before and after executing the function.

See also

ConsoleOpen()
ConsoleUnread
ConsoleEventType
ConsoleEventsFlush()

Example

Dim con As Object, con1 As Object, dll As Object
Dim lRes As Long, s As String
Set con = CreateObject("ntXdll.Consoler")
Set dll = CreateObject("ntXdll.DllClass")

lRes = con.ConsoleOpen()
If lRes <> 0 Then Exit Sub

'set mode, so that changes of window screen buffer is reported in the input buffer
con.ConsoleInputMode = con.ConsoleInputMode Or con.ENABLE_WINDOW_INPUT
If con.ConsoleLastError <> 0 Then Exit Sub

'set a control handler to handle a CTRL+C signal
lRes = con.SetControlHandler()
If lRes <> 0 Then Exit Sub

'loop until CANCEL is pressed (Ctrl+C)
'now move the mouse over the console with pressed or non pressed mouse button or control key or
'press any key on the keyboard with pressed or non pressed control key (SHIFT or someting else) or
'set and release the focus of the console or
'open and close the consoles menu or
'change the size of the consoles windowbuffer
Do

dll.Sleeping 500
If con.ConsoleUnread > 0 Then

lRes = con.InitConsoleEvents(False)
If lRes <> 0 Then Exit Sub
For Each con1 In con.ConsoleEvents

dll.Sleeping 500

Select Case con1.ConsoleEventType

Case "KEY_EVENT"

If con1.ConsoleEventKey = "CANCEL" Then s = "Exit loop"
lRes = con.ConsoleWrite(con1.ConsoleEventKey & vbCrLf & _
con1.ConsoleEventKeyDown & vbCrLf & _
con1.ConsoleEventKeyRepeat & vbCrLf & _
con1.ConsoleEventControlKey)

Case "MOUSE_EVENT"

lRes = con.ConsoleWrite(con1.ConsoleEventMouse & vbCrLf & _
con1.ConsoleEventMouseButtonState & vbCrLf & _
con1.ConsoleEventX & "/" & con1.ConsoleEventY & vbCrLf & _
con1.ConsoleEventControlKey)

Case "WINDOW_BUFFER_SIZE_EVENT"

lRes = con.ConsoleWrite("Window buffersize " & _
con1.ConsoleEventX & "/" & con1.ConsoleEventY)

Case "MENU_EVENT"

'In this version of ntXdll - see the remarks to the help of
'property ConsoleEventCommandID
lRes = con.ConsoleWrite("MenuID: " & _ con1.ConsoleEventCommandID)

Case "FOCUS_EVENT"

lRes = con.ConsoleWrite("Focus: " & con1.ConsoleEventFocus)

End Select
lRes = con.ConsoleWrite(vbCrLf & vbCrLf)

Next

End If

Loop Until s = "Exit loop"
lRes = con.ConsoleEventsFlush()
lRes = con.ReleaseControlHandler()


ConsoleEvents As Collection

Class Console

Saturday, June 17, 2000

ConsoleEvents As Collection

Property (read only)

Return value

Returns a collection of console events. The key of each member in this collection is a number. Console events can be of the type KEY_EVENT , MOUSE_EVENT , WINDOW_BUFFER_SIZE_EVENT , MENU_EVENT or FOCUS_EVENT . Depend on the type of the event, different properties of the class are filled with information.

For example, if a KEY_EVENT happens in the console, the ConsoleEventMouse* properties are empty. You have to execute the function InitConsoleEvents (...) of this class before reading the collection.

You have to open a console with function ConsoleOpen before executing InitConsoleEvents (...). With property ConsoleUnread , you can discover, whether any console events are to read in the console buffer.

See also

ConsoleOpen()
ConsoleUnread
InitConsoleEvents(...)
ConsoleEventType
ConsoleEventsFlush()

Example

Look at the example at the help of the function InitConsoleEvents()


ConsoleEventType As String

Class Console

Saturday, June 17, 2000

ConsoleEventType As String

Property (read only)

Return value

Returns the type of a member (item) of the collection ConsoleEvents . Console events can be of the type

"KEY_EVENT"
"MOUSE_EVENT"
"WINDOW_BUFFER_SIZE_EVENT"
"MENU_EVENT"
"FOCUS_EVENT"

Every member (item) of the collection ConsoleEvents has this property. Dependend of this value, you can read the properties of the conole events. Because, for example, if a KEY_EVENT happens in the console, the ConsoleEventMouse* properties are empty. You have to execute the function InitConsoleEvents (...) of this class before reading the collection.

You have to open a console with function ConsoleOpen before executing InitConsoleEvents (...). With property ConsoleUnread , you can discover, whether any console events are to read in the console buffer.

See also

ConsoleOpen()
ConsoleUnread
InitConsoleEvents(...)
ConsoleEvents
ConsoleEventsFlush()

Example

Look at the example at the help of the function InitConsoleEvents()


ConsoleEventsFlush() As Long

Class Console

Saturday, June 17, 2000

ConsoleEventsFlush As Long

Function

Return value

Returns 0 (zero) if the functio succeeds, otherwise a nonzero value. This can be an VB or an API error number. The function empties the consoles input buffer. This means, that all unread console events are discarded and are no longer available for reading. You can execute the function any time after opening a console with function ConsoleOpen . It doesn't matter, whether records of console events are in the buffer or not. You can use the function for example to flush console events after initializing the collection ConsoleEvents with the Peek option.

See also

ConsoleOpen()
ConsoleUnread
InitConsoleEvents(...)
ConsoleEvents
ConsoleEventType
ConsoleEvent* properties

Example

Look at the example at the help of the function InitConsoleEvents()


ConsoleEventX As IntegerConsoleEventY As Integer

Class Console

Saturday, June 17, 2000

ConsoleEventX As Integer
ConsoleEventY As Integer

Properties (read only)

Return value

Return the new window buffer size if a console event of type WINDOW_BUFFER_SIZE_EVENT happens in the console buffer. But the properties are also filled with information, when an event of type MOUSE_EVENT occurs. Then, the new position of the mouse pointer is returned.

Console events are members of the collection ConsoleEvents of the class Consoler. You can find out the type of the console event with the collection member-property ConsoleEventType . You have to execute the function InitConsoleEvents (...) of this class before reading the collection.

You have to open a console with function ConsoleOpen before executing InitConsoleEvents (...). With property ConsoleUnread , you can discover, whether any console events are to read in the console buffer.

See also

ConsoleOpen()
ConsoleUnread
InitConsoleEvents(...)
ConsoleEvents
ConsoleEventType
ConsoleEventsFlush()
ConsoleEventMouse

Example

Look at the example at the help of the function InitConsoleEvents()


ConsoleEventCommandID As Long

Class Console

Saturday, June 17, 2000

ConsoleEventCommandID As Long

Property (read only)

Return value

Returns the id of a command of a console event of type MENU_EVENT . If you click on the menu of a console a menu event is created.

Console events are members of the collection ConsoleEvents of the class Consoler. You can find out the type of the console event with the collection member ConsoleEventType . You have to execute the function InitConsoleEvents (...) of this class before reading the collection.

You have to open a console with function ConsoleOpen before executing InitConsoleEvents (...). With property ConsoleUnread , you can discover, whether any console events are to read in the console buffer.

Remarks

In last minute, setting this this property by Win32 API was deactivated, because it causes a memory exception in Msvbvm60.dll, if the ntXdll is compiled in native code. I don't want to compile ntXdll in p-code, so I decided to set this property manually - in this version of ntXdll, the property is manually set to -9999 in case of a eventtype "MENU_EVENT". You can see, whether a menu event occurred, but you can't see the right command ID. I will look for a solution of this problem.

See also

ConsoleOpen()
ConsoleUnread
InitConsoleEvents(...)
ConsoleEvents
ConsoleEventType
ConsoleEventsFlush()

Example

Look at the example at the help of the function InitConsoleEvents()


ConsoleEventControlKey As String

Class Console

Saturday, June 17, 2000

ConsoleEventControlKey As String

Property (read only)

Return value

Returns the ControlKeyState of a console event of type KEY_EVENT or MOUSE_EVENT . When you press a key when the console has the focus or when you move or click the mouse in the border of a console which has the focus, a key or a mouse event is created. In this moment, a control key can be pressed.

Console events are members of the collection ConsoleEvents of the class Consoler. You can find out the type of the console event with the collection member ConsoleEventType . You have to execute the function InitConsoleEvents (...) of this class before reading the collection.

You have to open a console before executing InitConsoleEvents (...). With property ConsoleUnread , you can discover, whether any console events are to read in the console buffer.

The property can be one or more of the following strings (more than one strings are separated by the plus character '+'):

"NO_CONTROLKEY_PRESSED"
"RIGHT_ALT_PRESSED"
"LEFT_ALT_PRESSED"
"RIGHT_CTRL_PRESSED"
"LEFT_CTRL_PRESSED"
"SHIFT_PRESSED"
"NUMLOCK_ON"
"SCROLLLOCK_ON"
"CAPSLOCK_ON"
"ENHANCED_KEY"

See also

ConsoleOpen()
ConsoleUnread
InitConsoleEvents(...)
ConsoleEvents
ConsoleEventType
ConsoleEventsFlush()

Example

Look at the example at the help of the function InitConsoleEvents()


ConsoleEventFocus As Boolean

Class Console

Saturday, June 17, 2000

ConsoleEventFocus As Boolean

Property (read only)

Return value

Returns the value of a console event of type FOCUS_EVENT . If a console gets or loses the focus, a focus event is created.

Console events are members of the collection ConsoleEvents of the class Consoler. You can find out the type of the console event with the collection member ConsoleEventType . You have to execute the function InitConsoleEvents (...) of this class before reading the collection.

You have to open a console with function ConsoleOpen before executing InitConsoleEvents (...). With property ConsoleUnread , you can discover, whether any console events are to read in the console buffer.

See also

ConsoleOpen()
ConsoleUnread
InitConsoleEvents(...)
ConsoleEvents
ConsoleEventType
ConsoleEventsFlush()

Example

Look at the example at the help of the function InitConsoleEvents()


ConsoleEventKey As String

Class Console

Saturday, June 17, 2000

ConsoleEventKey As String

Property (read only)

Return value

Returns the value of a console event of type KEY_EVENT . If you press a key when the console has the input focus, a key event is created. The value of ConsoleEventKey can be a char (string with len = 1) or a special description if a control key or a enhaced key is pressed (Shift or Ctrl or Ctrl+C or F1 etc.).

Console events are members of the collection ConsoleEvents of the class Consoler. You can find out the type of the console event with the collection member ConsoleEventType . You have to execute the function InitConsoleEvents (...) of this class before reading the collection.

You have to open a console before executing InitConsoleEvents (...). With property ConsoleUnread , you can discover, whether any console events are to read in the console buffer.

See also

ConsoleOpen()
ConsoleUnread
InitConsoleEvents(...)
ConsoleEvents
ConsoleEventType
ConsoleEventsFlush()
ConsoleEventKeyDown
ConsoleEventKeyRepeat
ConsoleEventControlKey

Example

Look at the example at the help of the function InitConsoleEvents()


ConsoleEventKeyDown As Boolean

Class Console

Saturday, June 17, 2000

ConsoleEventKeyDown As Boolean

Property (read only)

Return value

Returns the value of a console event of type KEY_EVENT . If you press a key when the console has the input focus, a key event is created. The value of ConsoleEventKeyDown is True, if the key is pressed, False, if the key is released.

Console events are members of the collection ConsoleEvents of the class Consoler. You can find out the type of the console event with the collection member ConsoleEventType . You have to execute the function InitConsoleEvents (...) of this class before reading the collection.

You have to open a console with function ConsoleOpen before executing InitConsoleEvents (...). With property ConsoleUnread , you can discover, whether any console events are to read in the console buffer.

See also

ConsoleOpen()
ConsoleUnread
InitConsoleEvents(...)
ConsoleEvents
ConsoleEventType
ConsoleEventsFlush()
ConsoleEventKey
ConsoleEventKeyRepeat
ConsoleEventControlKey

Example

Look at the example at the help of the function InitConsoleEvents()


ConsoleEventKeyRepeat As Long

Class Console

Saturday, June 17, 2000

ConsoleEventKeyRepeat As Long

Property (read only)

Return value

Returns the value of a console event of type KEY_EVENT . If you press a key when the console has the input focus, a key event is created. The value of ConsoleEventKeyRepeat specifies a count indicating that a key is being held down.

For example, when a key is held down, you might get five events with this member equal to 1, one event with this member equal to 5, or multiple events with this member greater than or equal to 1.

Console events are members of the collection ConsoleEvents of the class Consoler. You can find out the type of the console event with the collection member ConsoleEventType . You have to execute the function InitConsoleEvents (...) of this class before reading the collection.

You have to open a console with function ConsoleOpen before executing InitConsoleEvents (...). With property ConsoleUnread , you can discover, whether any console events are to read in the console buffer.

See also

ConsoleOpen()
ConsoleUnread
InitConsoleEvents(...)
ConsoleEvents
ConsoleEventType
ConsoleEventsFlush()
ConsoleEventKey
ConsoleEventKeyDown
ConsoleEventControlKey

Example

Look at the example at the help of the function InitConsoleEvents()


ConsoleEventMouse As String

Class Console

Saturday, June 17, 2000

ConsoleEventMouse As String

Property (read only)

Return value

Returns the value of a console event of type MOUSE_EVENT . When you press a mouse botton in the console window or when you move the mouse over the console window when the console has the input focus, a mouse event is created. The value of ConsoleEventMouse can be one of the following strings:

"DOUBLE_CLICK"
"MOUSE_MOVED"
"MOUSE_WHEELED"
"MOUSE_EVENT"

Console events are members of the collection ConsoleEvents of the class Consoler. You can find out the type of the console event with the collection member ConsoleEventType . You have to execute the function InitConsoleEvents (...) of this class before reading the collection.

You have to open a console with function ConsoleOpen before executing InitConsoleEvents (...). With property ConsoleUnread , you can discover, whether any console events are to read in the console buffer.

See also

ConsoleOpen()
ConsoleUnread
InitConsoleEvents(...)
ConsoleEvents
ConsoleEventType
ConsoleEventsFlush()
ConsoleEventMouseButtonState
ConsoleEventControlKey

Example

Look at the example at the help of the function InitConsoleEvents()


ConsoleEventMouseButtonState As String

Class Console

Saturday, June 17, 2000

ConsoleEventMouseButtonState As String

Property (read only)

Return value

Returns a string value specifying the button state of the mouse in the moment of an event of type MOUSE_EVENT . When you press a mouse botton in the console window or when you move the mouse over the console window when the console has the input focus, a mouse event is created. It can be one of the following strings:

"FROM_LEFT_1ST_BUTTON_PRESSED"
"RIGHTMOST_BUTTON_PRESSED"
"FROM_LEFT_2ND_BUTTON_PRESSED"
"FROM_LEFT_3RD_BUTTON_PRESSED"
"FROM_LEFT_4TH_BUTTON_PRESSED"
"UNKNOWNW"

Console events are members of the collection ConsoleEvents of the class Consoler. You can find out the type of the console event with the collection member ConsoleEventType . You have to execute the function InitConsoleEvents (...) of this class before reading the collection.

You have to open a console with function ConsoleOpen before executing InitConsoleEvents (...). With property ConsoleUnread , you can discover, whether any console events are to read in the console buffer.

See also

ConsoleOpen()
ConsoleUnread
InitConsoleEvents(...)
ConsoleEvents
ConsoleEventType
ConsoleEventsFlush()
ConsoleEventMouse
ConsoleEventControlKey

Example

Look at the example at the help of the function InitConsoleEvents()


SetControlHandler() As Long

Class Console

Saturday, June 17, 2000

SetControlHandler() As Long

Function

Return value

The function sets a control handler for a opened console. It returns 0 in case of success, otherwise a nonzero value if an error occurs. This property can be an VB or an API error number.

You have to open a console with function ConsoleOpen before using the function.

With setting a control handler, you are able to handle events like closing, logging off, shutting down or ctrl+break by the console without involving the calling process. For detailed information, see the explanations in the help of property ConsoleLastCTRLEvent .

See also

ConsoleOpen()
ConsoleLastCTRLEvent
ConsoleInputMode
ConsoleOutputMode
ENABLE* Properties
ReleaseControlHandler()

Example

Look at the example at the help of the function InitConsoleEvents()


ConsoleLastCTRLEvent As String

Class Console

Saturday, June 17, 2000

ConsoleLastCTRLEvent As String

Property (read only)

Return value

Returns the last control event, if an control handler is set by the function SetControlHandler () of this class. The property can be one of the following strings:

"CTRL_C_EVENT"
"CTRL_BREAK_EVENT"
"CTRL_CLOSE_EVENT"
"CTRL_LOGOFF_EVENT"
"CTRL_SHUTDOWN_EVENT"

You have to open a console with function ConsoleOpen before using the property. Then you have to execute the function SetControlHandler () of this class.

With setting a controlhandler, you are able to handle events like closing, logging off, shutting down or ctrl+break by the console without involving the calling process.

Explanation

Each console process has its own list of application-defined HandlerRoutine functions that handle CTRL+C and CTRL+BREAK signals. The handler functions also handle signals generated by the system when the user closes the console, logs off, or shuts down the system. A console process adds or removes additional handler functions by calling the SetControlHandler () function, which does not affect the list of handler functions for other processes. When a console process receives any of the control signals, its handler functions are called on a last-registered, first-called basis until one of the handlers returns TRUE. If none of the handlers returns TRUE, the default handler is called. For console processes, the CTRL+C and CTRL+BREAK key combinations are typically treated as signals (CTRL_C_EVENT and CTRL_C_BREAK_EVENT). When a console window with the keyboard focus receives CTRL+C or CTRL+BREAK, the signal is typically passed to all processes sharing that console. CTRL+BREAK is always treated as a signal, but typical CTRL+C behavior can be changed in three ways that prevent the handler functions from being called:

  • The property ConsoleInputMode of this class can disable the ENABLE_PROCESSED_INPUT mode for a console's input buffer, so CTRL+C is reported as keyboard input rather than as a signal.
  • If a console process is being debugged and CTRL+C signals have not been disabled, the kernel generates a DBG_CONTROL_C exception. This exception is raised only for the benefit of the debugger, and an application should never use an exception handler to deal with it. If the debugger handles the exception, an application will not notice the CTRL+C, with one exception: alertable waits will terminate. If the debugger passes the exception on unhandled, CTRL+C is passed to the console process and treated as a signal, as previously discussed.

The system generates CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, and CTRL_SHUTDOWN_EVENT signals when the user closes the console, logs off, or shuts down the system so that the process has an opportunity to clean up before termination. Console functions, or any C run-time functions that call console functions, may not work reliably during processing of any of the three signals mentioned previously. The reason is that some or all of the internal console cleanup routines may have been called before executing the process signal handler

See also

ConsoleOpen()
SetControlHandler ()
 ReleaseControlHandler ()
 ConsoleInputMode
ConsoleOutputMode
ENABLE* Properties

Example

Dim con As Object
Dim lRes As Long, s As String
Set con = CreateObject("ntXdll.Consoler")
lRes = con.SetControlHandler()
If con.ConsoleOpen() = 0 Then

Do

s = con.ConsoleLastCTRLEvent
lRes = con.ConsoleWrite(s)

Loop Until s = "CTRL_C_EVENT"

End If


ReleaseControlHandler() As Long

Class Console

Saturday, June 17, 2000

ReleaseControlHandler() As Long

Function

Return value

The function releases a control handler set by the function SetControlHandler () of this class. It returns 0 in case of success, otherwise a nonzero value if an error occurs. This property can be an VB or an API error number.

You have to open a console with function ConsoleOpen before using the function.

With setting a control handler, you are able to handle events like closing, logging off, shutting down or ctrl+break by the console without involving the calling process. For detailed information, see the explanations in the help of property ConsoleLastCTRLEvent .

See also

ConsoleOpen()
SetControlHandler()
ConsoleLastCTRLEvent
ConsoleInputMode
ConsoleOutputMode
ENABLE* Properties

Example

Look at the example at the help of the function InitConsoleEvents()


Class Service

Saturday, June 17, 2000

Class Service

This class uses Win32 API functions to query or set service properties on the local or a remote system and needs Windows NT® 4.0 Service Pack 4 or higher.

In this version of ntXdll, creating services is not supported.

The class uses the ANSI versions of the Windows NT® APIs.

To query or set service properties, you have to initialize Service objects at first. Function GetServiceInfo initializes a single Service object, which represents a single service or device on the local or a remote computer. After executing the function without error, you have a Valid Service object. You can access the properties of the requested service through the object instance, you called the function GetServiceInfo from.

Function InitServices initializes a collection Services , which represents all services or devices on the local or a remote computer. After executing the function without error, all collection members are Valid Service objects. You can access the properties of the requested services only through the object instances of the collection members.

You can control (starting, stopping, pausing and continuing) services or devices by changing the property CurrentState of this class.

You can change service properties by assigning a value of the right type to the property (syntax: <service object>.<property> = <value>). You only can change properties within a Valid Service object. This means, that you have to initialize a Service object with the functions above.

If you want to change a property of a single service, you should initialize only a single object with function GetServiceInfo . Otherwise, you would have to run through all collection members with a search criteria until you find the right service.

All properties, you can change (except property DisplayName ), require a restart of the service, for that changes take effect.

In this version of ntXdll, you only can change the following properties (alphabetical order):

BinaryPathName
CurrentState
DisplayName
ServiceDBLocked
ServicePassword
ServiceStartName
ServiceType
StartType

With function InitServiceDB , you get some information about the service database of a computer.

There are some additional functions, which you can use seperate and which require no Valid Service objects. These functions are:

GetDisplayName
GetServiceName
RemoveService

You get detailed information in the help of each function or property.


GetServiceInfo(...) As Long

Class Service

Thursday, December 20, 2001

GetServiceInfo

(strServiceName As String,
[strComputer As String],
[strDefault As String])

As Long

Function

Return value

Returns a non zero value in case of success, otherwise 0 (zero). If 0 is returned, the property LastError of this class is set to an error number. This value can be an internal, a VB or an API error. To get the description of an API error, use function FormatAPIMessage of class DllClass (see the example).

The function initializes the properties of a Service object. This means that the properties of a Service object instance, through which you call this function are filled with the informations of a service or device, you want to query on the local or a remote machine. After executing the function without error, the object instance, you call the function from, is a Valid Service object.

To initialize the properties of multiple services on a machine, use the function InitServices of this class.

You have to call this function (or InitServices for multiple services) before you want modifiy properties of a service.

Parameters

strServiceName
specifies the name of the service or device, you want to get the infos from. This must not the same as the service display name, which is shown in the service control manager. If you do not know the service name, use function GetServiceName to get the service name from the corresponding display name. The parameter is not case sensitive.

strComputer (optional)
specifies the name of the computer where the service or device exists from which you want to get the infos. Do not use leading backslashs ('\\'). If you omitt the parameter, the local machine is used.

strDefault (optional)
specifies, which string will be assigned to the properties, which are empty after executing the function. If you omitt the parameter, the string "unknown" will be used. You can assign an empty string.

See also

GetServiceName
InitServices
Valid
LastError
FormatAPIMessage

Example (early binding)

Dim svc As New Service, dll As New DllClass
Dim lRes As Long
Dim s As String

MsgBox svc.GetServiceInfo("Modem", "RemoteComputer", "")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

Debug.Print "ServiceName: " & svc.ServiceName
Debug.Print "DisplayName: " & svc.DisplayName
Debug.Print "Computer: " & svc.Computer
Debug.Print "BinaryPathName: " & svc.BinaryPathName
Debug.Print "CurrentState: " & svc.CurrentState
Debug.Print "Dependencies: " & svc.Dependencies
Debug.Print "CheckPoint: " & svc.CheckPoint
Debug.Print "ControlsAccepted: " & svc.ControlsAccepted
Debug.Print "ErrorControl: " & svc.ErrorControl
Debug.Print "LoadOrderGroup: " & svc.LoadOrderGroup
Debug.Print "ProcessID: " & svc.ProcessID
Debug.Print "ServiceFlags: " & svc.ServiceFlags
Debug.Print "ServiceSpecificExitCode: " & svc.ServiceSpecificExitCode
Debug.Print "ServiceStartName: " & svc.ServiceStartName
Debug.Print "ServiceType: " & svc.ServiceType
Debug.Print "StartType: " & svc.StartType
Debug.Print "TagID: " & svc.TagID
Debug.Print "WaitHint: " & svc.WaitHint
Debug.Print "Win32ExitCode: " & svc.Win32ExitCode
Debug.Print "Valid: " & svc.Valid


InitServices(...) As Long

Class Service

Saturday, June 17, 2000

InitServices

(lngServiceType As Long,
[strComputer As String],
[strDefault As String])

As Long

Function

Return value

Initializes the collection Services of services on a computer with all its properties. With this function of Class Service you can not get information of one special service but only information of a collection of services which belong to a special service type.

Returnes 0 in case of an error, otherwise a non zero value. If 0 is returned, the property LastError of this class is set to an error number. This value can be an internal, a VB or an API error. To get the description of an API error, use function FormatAPIMessage of class DllClass (see the example).

The function initializes the properties, referred to the collection Services on a computer. The members of this collection represent Valid Service objects.

To get information about one single service, use function GetServiceInfo of this class.

Parameters

lngServiceType
can one of the properties SV_WIN32 or SV_DRIVER of this class. Specifies, which type of services should be queried.

strComputer
Optional. If you want to connect to a remote computer, assign the name of the machine without leading backslashs. If you omitt strComputer, the local Services will be inspected.

strDefault
Optional. The string properties of the Service, which would return an empty string, return now strDefault. If you omitt strDefault, the empty string properties will return "unknown".

See also:

SV_DRIVER, SV_WIN32
Services
LastError
Valid
GetServiceInfo
ServiceName
DisplayName
ServiceType
CurrentState
ControlsAccepted
Win32ExitCode
ServiceSpecificExitCode
CheckPoint
WaitHint
ProcessID
ServiceFlags
StartType
ErrorControl
BinaryPathName
LoadOrderGroup
TagID
Dependencies
ServiceStartName
FormatAPIMessage

Example (late binding)

Dim sv1 As Object, sv2 As Object, dll As Object
Dim lngResult As Long

Set sv1 = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lngResult = sv1.InitServices(sv1.SV_DRIVER, "WorkstationName", "NULL")
lngResult = sv.LastError
MsgBox dll.FormatAPIMessage(lngResult, CStr(lngResult))

For Each sv2 In sv1.Services

MsgBox sv2.DisplayName

Next


SV_* Properties

Class Service

Saturday, June 17, 2000

SV_DRIVER
SV_WIN32

Properties (read only)

Return value

Return the service types needed as parameters in function InitServices (...) of this class.

See also:

InitServices (...)
 Services

Example

Dim sv1 As Object, sv2
    As Object
Dim lngResult As Long
Set sv1 = CreateObject("ntXdll.Service")
Set sv2 = CreateObject("ntXdll.Service")
lngResult = sv1.InitServices(sv1.SV_WIN32,
    "WorkstationName")
For Each sv2 In sv1.Services

Debug.Print sv2.DisplayName

Next


Services As Collection

Class Service

Saturday, June 17, 2000

Services As Collection

Properties (read only)

Return value

Returnes the Services Collection of a computer, which is initialized from InitServices (...). Each object in this collection has the properties of the Service object, exept the ServiceDB* properties. In the Class Service you can not get information of one special service but only information of a collection of services which belong to a special service type. The key for each element in the collection is the ServiceName . So you must not query the information with the For Each - loop if you know the ServiceName (Example2).

See also:

InitServices (...)
 SV_WIN32, SV_DRIVER

Example 1

Dim sv1 As Object, sv2
    As Object
Dim lngResult As Long
Set sv1 = CreateObject("ntXdll.Service")
Set sv2 = CreateObject("ntXdll.Service")
lngResult = sv1.InitServices(sv1.SV_WIN32, "WorkstationName",
    "unknown")
For Each sv2 In sv1.Services

Debug.Print sv2.ServiceName

Next

Example2

Dim sv As Object
Dim lngResult As Long
Set sv = CreateObject("ntXdll.Service")
lngResult = sv.InitServices(sv.SV_WIN32, "WorkstationName",
    "unknown")
Debug.Print sv.Services("Alerter").ServiceFlags


Computer As String

Class Service

Friday, December 14, 2000

Computer As String

Property (read only)

Return value

Returns the computername of a Service object (without leading backslashs '\\'). This is the name of the computer, where the service exists. Before you can get the value, you must initialize a Valid Service object with one of the functions InitServices , GetServiceInfo or InitServiceDB of this class.

If you omitt the parameter strComputer of these functions, the property will be completed with the name of the local computer. If you query the property from a collection Services , the property has the same value for all collection members (example 2).

See also

InitServices
GetServiceInfo
InitServiceDB
Valid
GetServiceName

Example1 (query the property from one object, early binding)

Dim svc As New Service
Dim dll As New DllClass
Dim sName As String
Dim lRes As Long

'operation on the local computer
sName = svc.GetServiceName("task scheduler")
lRes = svc.GetServiceInfo(sName)

If lRes = 0 Then

lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes), "netmsg.dll"))

End If

MsgBox svc.Computer

Example2 (query the property from a collection of service objects, late binding)

Dim svc, svcMember
Dim dll
Dim lRes
Dim fso, ts
Dim strFile

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")
Set fso = CreateObject("Scripting.FileSystemObject")

strFile = "d:\temp\services.txt"
If fso.FileExists(strFile) Then fso.DeleteFile strFile

Set ts = fso.OpenTextFile(strFile, ForWriting, True)

'working on a remote computer
MsgBox svc.InitServices(svc.SV_WIN32, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

For Each svcMember In svc.Services

ts.WriteLine ("ServiceName: " & svcMember.ServiceName)
ts.WriteLine ("DisplayName: " & svcMember.DisplayName)
ts.WriteLine ("Computer: " & svcMember.Computer)
ts.WriteLine ("BinaryPathName: " & svcMember.BinaryPathName)
ts.WriteLine ("CurrentState: " & svcMember.CurrentState)
ts.WriteLine ("Dependencies: " & svcMember.Dependencies)
ts.WriteLine ("CheckPoint: " & svcMember.CheckPoint)
ts.WriteLine ("ControlsAccepted: " & svcMember.ControlsAccepted)
ts.WriteLine ("ErrorControl: " & svcMember.ErrorControl)
ts.WriteLine ("LoadOrderGroup: " & svcMember.LoadOrderGroup)
ts.WriteLine ("ProcessID: " & svcMember.ProcessID)
ts.WriteLine ("ServiceFlags: " & svcMember.ServiceFlags)
ts.WriteLine ("ServiceSpecificExitCode: " & svcMember.ServiceSpecificExitCode)
ts.WriteLine ("ServiceStartName: " & svcMember.ServiceStartName)
ts.WriteLine ("ServiceType: " & svcMember.ServiceType)
ts.WriteLine ("StartType: " & svcMember.StartType)
ts.WriteLine ("TagID: " & svcMember.TagID)
ts.WriteLine ("WaitHint: " & svcMember.WaitHint)
ts.WriteLine ("Win32ExitCode: " & svcMember.Win32ExitCode)
ts.WriteLine ("Valid: " & svcMember.Valid)
ts.WriteLine ("****************************************************************")

Next

ts.Close


Valid As Boolean

Class Service

Saturday, December 22, 2001

Valid As Boolean

Property (read only)

Return value

Returns whether a Service object represents an existing service or device on the local or a remote computer.

To get the property, you have to init the properties of a Service object at first with functions GetServiceInfo (example 1) or InitServices (example 2) of this class. If you have executed this functions without error, the properties of the Service objects are filled with information and all of these objects represent existing services or devices.

The properties of this class, which can be set (which are not read only), can only be set within a Valid Service object (except, it is explicitly remarked in the help of the property, that the object must not be Valid).

See also

GetServiceInfo
InitServices
Services

Example1 (early binding)

Dim svc As New Service, dll As New DllClass
Dim lRes As Long

MsgBox svc.GetServiceInfo("Netlogon", "RemoteComputer", "")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

Debug.Print "Valid: " & svc.Valid

Example2 (late binding)

Dim sv1 As Object, sv2 As Object
Dim lngResult As Long

Set sv1 = CreateObject("ntXdll.Service")
Set sv2 = CreateObject("ntXdll.Service")

lngResult = sv1.InitServices(sv1.SV_WIN32, "WorkstationName", "unknown")
For Each sv2 In sv1.Services

Debug.Print sv2.Valid

Next


ServiceName As String

Class Service

Saturday, June 17, 2000

ServiceName As String

Property (read only)

Return value

Returnes the ServiceName of a service. This is the internal name of the service, which is used to identify the service in the system. The ServiceName must not be the same as the name of the service, which is displayed in the service control manager (property DisplayName of this class).

If an error occurs or the string would be empty, the optional parameter strDefault of the functions GetServiceInfo (...) or InitServices (...) will be returned. Then, in case of an error, property LastError of this class is set to an error number. This value can be an internal, a VB or an API error. Otherwise, in case of success, LastError is 0 (zero). To get the description of an API error, use function FormatAPIMessage of class DllClass (see the example).

The property is accessable over the collection Services of this class. Then, the property shows the ServiceName of each Valid member of the collection (which represents a service or device on the local or a remote computer). At first, execute function InitServices (...) to initialize the collection. For devices, you have to assign the value SV_DRIVER to parameter lngServiceType of function InitServices .

The property is also accessable over one single object, which is initialized with function GetServiceInfo (...) of this class. This Valid object represents a single service or device on the local or a remote computer.

Remarks:

To get the ServiceName from the DisplayName , you can use the function GetServiceName of this class.

See also:

InitServices
GetServiceInfo
ServiceName
SV_WIN32, SV_DRIVER
Services
Valid
LastError
FormatAPIMessage
GetServiceName

Example1 - querying the property from all services on a computer (late binding)

Dim svc, svcMember, dll
Dim lngResult

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lngResult = svc.InitServices(svc.SV_WIN32, "WorkstationName")
lngResult = svc.LastError
MsgBox dll.FormatAPIMessage(lngResult, CStr(lngResult))

For Each svcMember In svc.Services

Debug.Print svcMember.ServiceName

Next

Example2 - querying the property from a single service on a computer (late binding)

Dim svc, dll
Dim lRes
Dim sv

sv = "SampleService"

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lRes = svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

MsgBox "ServiceName: " & svc.ServiceName


DisplayName As String

Class Service

Saturday, June 17, 2000

DisplayName As String

Property

Return value

Returns or sets the in the SCM (Service Control Manager) displayed name of a service or device on the local or a remote computer. This must not be the same as the internal name of a service on the system (property ServiceName of this class). If an error occurs or the string would be empty, the optional parameter strDefault of the functions GetServiceInfo (...) or InitServices (...) will be returned.

The property is accessable over the collection Services of this class. Then, the property shows the DisplayName of each Valid member of the collection (which represents a service or device on the local or a remote computer). At first, execute function InitServices (...) to initialize the collection. For devices, you have to assign the value SV_DRIVER to parameter lngServiceType of function InitServices .

The property is also accessable over one single object, which is initialized with function GetServiceInfo (...) of this class. This Valid object represents a single service or device on the local or a remote computer.

If you set the property, you can assign a DisplayName to the service or device. You only can set the property within a Valid Service object. You get Valid Service objects with functions InitServices (...) or GetServiceInfo (...) of this class.

DisplayName is the only property of this class, which you can set without restarting the service for that the changes take effect.

If an error occurs while changing the property, property LastError of this class is set to an error number. This value can be an internal, a VB or an API error. Otherwise, in case of success, LastError is 0 (zero). To get the description of an API error, use function FormatAPIMessage of class DllClass (see the example).

Remarks:

To get the DisplayName of a service from the ServiceName , you can use the function GetDisplayName of this class.

See also:

InitServices
GetServiceInfo
ServiceName
SV_WIN32, SV_DRIVER
Services
Valid
LastError
FormatAPIMessage
GetDisplayName

Example1 - querying the property (late binding)

Dim sv1 As Object, sv2 As Object
Dim lngResult As Long

Set sv1 = CreateObject("ntXdll.Service")
Set sv2 = CreateObject("ntXdll.Service")

lngResult = sv1.InitServices(sv1.SV_WIN32, "WorkstationName", "unknown")

For Each sv2 In sv1.Services

Debug.Print sv2.DisplayName

Next

Example2 - setting the property (early binding)

Dim svc As New Service, dll As New DllClass
Dim lRes As Long
Dim s As String, sv As String

sv = "SampleService"

lRes = svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

MsgBox "DisplayName: " & svc.DisplayName

'setting the property
svc.DisplayName = "New Sample Service"

MsgBox "DisplayName: " & svc.DisplayName

lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))


ProcessID As Long

Class Service

Saturday, June 17, 2000

ProcessID As Long

Property (read only)

Return value

Returnes the ProcessID of a service. This is the process identifier of the service.

The property is accessable over the collection Services of this class. Then, the property shows the ProcessID of each Valid member of the collection (which represents a service or device on the local or a remote computer). At first, execute function InitServices (...) to initialize the collection. For devices, you have to assign the value SV_DRIVER to parameter lngServiceType of function InitServices (...).

The property is also accessable over one single object, which is initialized with function GetServiceInfo (...) of this class. This Valid object represents a single service or device on the local or a remote computer.

See also:

InitServices
GetServiceInfo
Valid
SV_WIN32, SV_DRIVER
Services
LastError
FormatAPIMessage

Example1 - querying the property from all services on a computer (late binding)

Dim svc, svcMember, dll
Dim lngResult

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lngResult = svc.InitServices(svc.SV_WIN32, "WorkstationName")
lngResult = svc.LastError
MsgBox dll.FormatAPIMessage(lngResult, CStr(lngResult))

For Each svcMember In svc.Services

Debug.Print svcMember.ProcessID

Next

Example2 - querying the property from a single service on a computer (late binding)

Dim svc, dll
Dim lRes
Dim sv

sv = "SampleService"

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lRes = svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

MsgBox "ProcessID: " & svc.ProcessID


ServiceStartName As String

Class Service

Saturday, June 17, 2000

ServiceStartName As String

Property

Return value

Returnes or sets the ServiceStartName of a service. This is the account, in which context the service runs. You can configure a service (only a service, not a device) to run under the LocalSystem account or under an account from the local computer or a domain. If an error occurs or the string would be empty, the optional parameter strDefault of the functions InitServices (...) or GetServiceInfo (....) will be returned.

The property is accessable over the collection Services of this class. Then, the property shows the ServiceStartName of each Valid member of the collection (which represents a service or device on the local or a remote computer). At first, execute function InitServices (...) to initialize the collection. For devices (if you assign the value SV_DRIVER to parameter lngServiceType of function InitServices ), the property is always an empty string, because you cannot configure the ServiceStartName of devices.

The property is also accessable over one single object, which is initialized with function GetServiceInfo (...) of this class. This Valid object represents a single service or device on the local or a remote computer.

If you set the property, you can assign a user account to the service. You only can set the property within a Valid Service object. You get Valid Service objects with functions InitServices (...) or GetServiceInfo (...) of this class.

You only can set an account to services, but not to devices. This account must have the privilege "Logon as a service" on the machine, where you want to change the service. You can set privileges on local or remote computers with function AddPolicyRight of class LocalSecurer.

You only can set an account to services, which have the type

"SERVICE_WIN32_OWN_PROCESS"
or
"SERVICE_WIN32_OWN_PROCESS_INTERACTIVE"

For more information, see the help to property ServiceType .

You must specify the account in the notation "<domain>\<account name>" (except the account LocalSystem - see example 4). If you want to use an account (only users are allowed, but not groups), which is stored in the local security database of the local or remote computer, use the notation ".\<account name>".

You always must set the property in combination with property ServicePassword of this class. Even, if you only want to change one of the two properties. If you set the first of the two properties, LastError of this class signals the internal error -8989. This means, you have to set the second property, before the changes take effect. Then, if you set the second property, LastError is back to 0 (zero).

You always should stop the service, before changing the property. Then, set the value and property ServicePassword and then, at last, start the servicve again. You can stop and start services with property CurrentState of this class.

If an error occurs while changing the property, the property LastError of this class will be set to an error number. This value can be an internal, a VB or an API error. Otherwise, in case of success, LastError is 0 (zero). To get the description of an API error, use function FormatAPIMessage of class DllClass (see the example 3).

If the account is not correct, an error will be returned.

See also:

InitServices (...)
 GetServiceInfo (...)
 SV_WIN32, SV_DRIVER
Services
Valid
ServiceType
ServicePassword
CurrentState
AddPolicyRight
LastError
FormatAPIMessage

Example1 - setting user and password to a service, which runs interactive with the local system (late binding)

Dim svc, dll
Dim lRes
Dim sv

Set svc = CreateObject("ntXdll.Service")
Set svc = CreateObject("ntXdll.DllClass")

sv = "sampleservice"

'initializing a valid service object:
lRes = svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

'stopping the service
svc.CurrentState = "SERVICE_STOP_PENDING"
MsgBox "Service stopped: " & svc.LastError
MsgBox "CurrentState: " & svc.CurrentState

'changing the service type from "SERVICE_WIN32_OWN_PROCESS_INTERACTIVE" to "SERVICE_WIN32_OWN_PROCESS"
svc.ServiceType = "SERVICE_WIN32_OWN_PROCESS"
MsgBox "ServiceType changed: " & svc.LastError

'setting the user from the domain
svc.ServiceStartName = "MyDomain\ServiceUser"
MsgBox "ServiceStartName set: " & svc.LastError

'setting the password:
svc.ServicePassword = "f!7hg."
MsgBox "ServicePassword set: " & svc.LastError

'starting the service"
svc.CurrentState = "SERVICE_START_PENDING"
MsgBox "Service started: " & svc.LastError
MsgBox "CurrentState: " & svc.CurrentState

Example2 - setting user and password to a service, which runs non interactive with the local system (late binding)

'This would be the same as example 1, except that the service type must not be changed.

Example3 - setting only the password to a service, which runs already with a user (late binding)

Dim svc, dll
Dim lRes
Dim sv

Set svc = CreateObject("ntXdll.Service")
Set svc = CreateObject("ntXdll.DllClass")

sv = "sampleservice"

'initializing a valid service object:
lRes = svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

'stopping the service
svc.CurrentState = "SERVICE_STOP_PENDING"
MsgBox "Service stopped: " & svc.LastError
MsgBox "CurrentState: " & svc.CurrentState

'you must specify the user, even, if you only
'want to change the password. But you can take
'the current value of the property
svc.ServiceStartName = svc.ServiceStartName
MsgBox "ServiceStartName set: " & svc.LastError

'setting the password:
svc.ServicePassword = "f!7hg."
MsgBox "ServicePassword set: " & svc.LastError

'starting the service"
svc.CurrentState = "SERVICE_START_PENDING"
MsgBox "Service started: " & svc.LastError
MsgBox "CurrentState: " & svc.CurrentState

Example4 - setting a service, which runs already with an user, to interactive with the local system (late binding)

Dim svc, dll
Dim lRes
Dim sv

Set svc = CreateObject("ntXdll.Service")
Set svc = CreateObject("ntXdll.DllClass")

sv = "sampleservice"

'initializing a valid service object:
lRes = svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

'stopping the service
svc.CurrentState = "SERVICE_STOP_PENDING"
MsgBox "Service stopped: " & svc.LastError
MsgBox "CurrentState: " & svc.CurrentState

'setting the user LocalSystem
svc.ServiceStartName = "LocalSystem"
MsgBox "ServiceStartName set: " & svc.LastError

'setting the password - it must be empty:
svc.ServicePassword = ""
MsgBox "ServicePassword set: " & svc.LastError

'changing the service type from "SERVICE_WIN32_OWN_PROCESS" to "SERVICE_WIN32_OWN_PROCESS_INTERACTIVE"
svc.ServiceType = "SERVICE_WIN32_OWN_PROCESS_INTERACTIVE"
MsgBox "ServiceType changed: " & svc.LastError

'starting the service"
svc.CurrentState = "SERVICE_START_PENDING"
MsgBox "Service started: " & svc.LastError
MsgBox "CurrentState: " & svc.CurrentState


ServicePassword As String

Class Service

Wednesday, December 25, 2001

ServicePassword As String

Property

Return value

Returnes or sets the ServicePassword of a service. This is the passwod to the account, in which context the service runs. You can configure a service (only a service, not a device) to run under the LocalSystem account or under an account from the local computer or a domain. The property always returnes the string "**************". The real password is not will not be displayed.

The property is accessable over the collection Services of this class. Then, the property shows the ServicePassword of each Valid member of the collection (which represents a service or device on the local or a remote computer). At first, execute function InitServices (...) to initialize the collection.

The property is also accessable over one single object, which is initialized with function GetServiceInfo (...) of this class. This Valid object represents a single service or device on the local or a remote computer.

If you set the property, you can assign the password of the user account of the service. You only can set the property within a Valid Service object. You get Valid Service objects with functions InitServices (...) or GetServiceInfo (...) of this class.

You only can set an account and the password to services, but not to devices.

You always must set the property in combination with property ServiceStartName of this class. Even, if you only want to change one of the two properties. If you set the first of the two properties, LastError of this class signals the internal error -8989. This means, you have to set the second property, before the changes take effect. Then, if you set the second property, LastError is back to 0 (zero).

You always should stop the service, before changing the property. Then, set the value and property ServiceStartName and then, at last, start the service again. You can stop and start services with property CurrentState of this class.

If an error occurs while changing the property, the property LastError of this class will be set to an error number. This value can be an internal, a VB or an API error. Otherwise, in case of success, LastError is 0 (zero). To get the description of an API error, use function FormatAPIMessage of class DllClass (see the example 3).

ntXdll will not verify, whether the password is correct or not. But you will notice the error, if you want to start the service.

See also:

InitServices (...)
 GetServiceInfo (...)
 Services
Valid
ServiceType
ServiceStartName
CurrentState
LastError
FormatAPIMessage

Example

'Please look at the help to property ServiceStartName of this class.


BinaryPathName As String

Class Service

Saturday, June 17, 2000

BinaryPathName As String

Property

Return value

Returnes or sets the path of the service executive file of a service or device on the local or a remote computer. If an error occurs or the string would be empty, the optional parameter strDefault of the functions InitServices (...) or GetServiceInfo (...) will be returned.

The property is accessable over the collection Services of this class. Then, the property shows the BinaryPathName of each Valid member of the collection (which represents a service or device on the local or a remote computer). At first, execute function InitServices (...) to initialize the collection. For devices, you have to assign the value SV_DRIVER to parameter lngServiceType of function InitServices .

The property is also accessable over one single object, which is initialized with function GetServiceInfo (...) of this class. This Valid object represents a single service or device on the local or a remote computer.

If you set the property, you can assign a BinaryPathName to the service or device. You only can set the property within a Valid Service object. You get Valid Service objects with functions InitServices (...) or GetServiceInfo (...) of this class.

You should stop the service or device before setting BinaryPathName. Then after changing it, start the service for that the changes take effect. You can control (stop and start) a service with property CurrentState of this class.

If an error occurs while changing the property, property LastError of this class is set to an error number. This value can be an internal, a VB or an API error. Otherwise, in case of success, LastError is 0 (zero). To get the description of an API error, use function FormatAPIMessage of class DllClass (see the example).

See also:

InitServices
GetServiceInfo
SV_WIN32, SV_DRIVER
Services
Valid
LastError
FormatAPIMessage
CurrentState

Example1 - querying the property from each service on a computer (late binding)

Dim sv1 As Object, sv2 As Object
Dim lngResult As Long

Set sv1 = CreateObject("ntXdll.Service")
Set sv2 = CreateObject("ntXdll.Service")

lngResult = sv1.InitServices(sv1.SV_WIN32, "WorkstationName", "error")
lngResult = svc.LastError
MsgBox dll.FormatAPIMessage(lngResult, CStr(lngResult))

For Each sv2 In sv1.Services

Debug.Print sv2.BinaryPathName

Next

Example2 - setting the property (early binding)

Dim svc As New Service, dll As New DllClass
Dim lRes As Long
Dim sv As String

sv = "sampleservice"

MsgBox svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

Debug.Print "BinaryPathName: " & svc.BinaryPathName

'stopping the service
svc.CurrentState = "SERVICE_STOP_PENDING"
dll.Sleeping svc.WaitHint

svc.BinaryPathName = "%SystemRoot%\system32\sampserv.exe"

'starting the service
svc.CurrentState = "SERVICE_START_PENDING"
dll.Sleeping svc.WaitHint

MsgBox svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

Debug.Print "ServiceType: " & svc.BinaryPathName


CurrentState As String

Class Service

Saturday, June 17, 2000

CurrentState As String

Property

Return value

Returnes or sets the current state of a service. If an error occurs or the string would be empty, the optional parameter strDefault of the functions InitServices (...) or GetServiceInfo (....) will be returned. The string can be one of the following strings:

"SERVICE_STOPPED"
"SERVICE_START_PENDING"
"SERVICE_STOP_PENDING"
"SERVICE_RUNNING"
"SERVICE_CONTINUE_PENDING"
"SERVICE_PAUSE_PENDING"
"SERVICE_PAUSED"

The property is accessable over the collection Services of this class. Then, the property shows the CurrentState of each Valid member of the collection (which represents a service or device on the local or a remote computer). At first execute function InitServices (...) to initialize the collection (example 1).

The property is also accessable over one single object, which is initialized with function GetServiceInfo (...) of this class. This Valid object represents a single service or device on the local or a remote computer (example 2).

If you set the property, you can control a service or device on the local or a remote computer. This means starting, stopping, pausing or continuing a service or device. You only can set the property within a Valid Service object. You get Valid Service objects with functions InitServices (...) or GetServiceInfo (...) of this class. You only can set one of the following strings to the property:

"SERVICE_START_PENDING" | This means, the service will be started
"SERVICE_STOP_PENDING" | This means, the service will be stopped
"SERVICE_PAUSE_PENDING" | This means, the service will be paused
"SERVICE_CONTINUE_PENDING" | This means, the service will be continued

The property will be refreshed automatically, but the task of changing the CurrentState does not wait for the completion. So, it is possible, that the property has the value "*_PENDING" after setting it. For the functionality, that you can wait for the completion, you have to make a loop after setting the property (see example 3).

If an error occurs while setting it, the property LastError of this class will be set to an error number. This value can be an internal, a VB or an API error. Otherwise, in case of success, LastError is 0 (zero). To get the description of an API error, use function FormatAPIMessage of class DllClass (see the example 3).

See also:

InitServices (...)
 SV_WIN32, SV_DRIVER
GetServiceInfo
Services
Valid
LastError
FormatAPIMessage

Example1 - initializing a collection (late binding)

Dim sv1 As Object, sv2 As Object
Dim lngResult As Long

Set sv1 = CreateObject("ntXdll.Service")
Set sv2 = CreateObject("ntXdll.Service")

lngResult = sv1.InitServices(sv1.SV_WIN32, "WorkstationName", "unknown")
For Each sv2 In sv1.Services

Debug.Print sv2.CurrentState

Next

Example2 - initializing a single object (early binding)

Dim svc As New Service, dll As New DllClass
Dim lRes As Long

MsgBox svc.GetServiceInfo("Modem", "RemoteComputer", "")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

Debug.Print "ServiceName: " & svc.ServiceName
Debug.Print "DisplayName: " & svc.DisplayName
Debug.Print "Computer: " & svc.Computer
Debug.Print "BinaryPathName: " & svc.BinaryPathName
Debug.Print "CurrentState: " & svc.CurrentState
Debug.Print "Dependencies: " & svc.Dependencies
Debug.Print "ServiceStartName: " & svc.ServiceStartName
Debug.Print "ServiceType: " & svc.ServiceType
Debug.Print "StartType: " & svc.StartType

Example3 - setting the property and waiting for the completion (late binding)

Dim svc, dll
Dim lRes
Dim sv

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

sv = "protectedstorage"

'at first initializing a valid service object
MsgBox svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

'printing the property before setting it
Debug.Print "CurrentState: " & svc.CurrentState

'setting the property
svc.CurrentState = "SERVICE_START_PENDING"

'waiting for the end of the task
Do While svc.CurrentState = "SERVICE_START_PENDING"

lRes = svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
Debug.Print "Win32ExitCode: " & svc.Win32ExitCode
Debug.Print "ServiceSpecificExitCode: " & svc.ServiceSpecificExitCode
Debug.Print "CheckPoint: " & svc.CheckPoint
dll.Sleeping svc.WaitHint / 10

Loop

If svc.CurrentState = "SERVICE_RUNNING" Then

Debug.Print "Service started successfully"

Else

Debug.Print "Service not started. Exitcode:" & svc.Win32ExitCode
Debug.Print "ServiceSpecificExitCode:" & svc.ServiceSpecificExitCode

End If

'printing the property after setting it
MsgBox svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))
Debug.Print "CurrentState: " & svc.CurrentState

lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))


ServiceType As String

Class Service

Saturday, June 17, 2000

ServiceType As String

Property

Return value

Returnes or sets the ServiceType of a service or device on the local or a remote computer. If an error occurs or the string would be empty, the optional parameter strDefault of the functions InitServices (...) or GetServiceInfo (....) will be returned. The returned value can be one of the following strings.

"SERVICE_WIN32_OWN_PROCESS"
"SERVICE_WIN32_OWN_PROCESS_INTERACTIVE"
"SERVICE_WIN32_SHARE_PROCESS"
"SERVICE_WIN32_SHARE_PROCESS_INTERACTIVE"
"SERVICE_KERNEL_DRIVER"
"SERVICE_FILE_SYSTEM_DRIVER"
"SERVICE_ADAPTER"
"SERVICE_RECOGNIZER_DRIVER"

The property is accessable over the collection Services of this class. Then, the property shows the ServiceType of each Valid member of the collection (which represents a service or device on the local or a remote computer). At first, execute function InitServices (...) to initialize the collection.

The property is also accessable over one single object, which is initialized with function GetServiceInfo (...) of this class. This Valid object represents a single service or device on the local or a remote computer.

You can set the property. Setting the ServiceType is the most complex task of this class, because you have to bear in mind some things. You should not set the type of devices (for example, do not change the type "SERVICE_KERNEL_DRIVER" to "SERVICE_FILE_SYSTEM_DRIVER").

You only can set the property within a Valid Service object. You get Valid Service objects with functions InitServices (...) or GetServiceInfo (...) of this class. You set the property by assigning a string. You should only assign one of the following strings to a service (not a device):

"SERVICE_WIN32_OWN_PROCESS"
"SERVICE_WIN32_OWN_PROCESS_INTERACTIVE"
"SERVICE_WIN32_SHARE_PROCESS"
"SERVICE_WIN32_SHARE_PROCESS_INTERACTIVE"

And you only should set the ServiceType in one of the following sequences (look the examples):

  1. from "SERVICE_WIN32_SHARE_PROCESS" to "SERVICE_WIN32_SHARE_PROCESS_INTERACTIVE" or vice versa. Shared services are only running with the LocalSystem account (look at property ServiceStartName ).
  2. from "SERVICE_WIN32_OWN_PROCESS" (running with the LocalSystem) to "SERVICE_WIN32_OWN_PROCESS_INTERACTIVE" (running with the LocalSystem) or vice versa.
  3. from "SERVICE_WIN32_OWN_PROCESS" or "SERVICE_WIN32_OWN_PROCESS_INTERACTIVE" (running with the LocalSystem) to "SERVICE_WIN32_OWN_PROCESS" (running with a special user - services, which are running with a special user, are never interactive to the desktop), or vice versa. For setting a special user (and the password), use the properties ServiceStartName and ServicePassword of this class.

You always should stop a service before changing the type. Use the property CurrentState for stopping and starting services.

If an error occurs while changing the property, property LastError of this class is set to an error number. This value can be an internal, a VB or an API error. Otherwise, in case of success, LastError is 0 (zero). To get the description of an API error, use function FormatAPIMessage of class DllClass (see the example).

If you set an user account for a service, the account must have the privilege to log on as a service on the computer, where you want to change the service. You can add privileges on the local or a remote computer with function AddPolicyRight of class LocalSecurer .

If you only want to change the account or the password without changing the ServiceType, you only have to use the properties ServiceStartName and ServicePassword .

See also:

InitServices
GetServiceInfo
Services
Valid
ServiceStartName
ServicePassword
CurrentState
AddPolicyRight
LocalSecurer
WaitHint

Example 1a
"SERVICE_WIN32_SHARE_PROCESS" to "SERVICE_WIN32_SHARE_PROCESS_INTERACTIVE" (early binding)

Dim svc As New Service, dll As New DllClass
Dim lRes As Long
Dim sv As String

'the service type of the netlogon service should not be changed
'it is only an example for a shared service
sv = "netlogon"

MsgBox svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

Debug.Print "CurrentState: " & svc.CurrentState
Debug.Print "ServiceType: " & svc.ServiceType

'stopping the service
svc.CurrentState = "SERVICE_STOP_PENDING"
dll.Sleeping svc.WaitHint

svc.ServiceType = "SERVICE_WIN32_SHARE_PROCESS_INTERACTIVE"

'starting the service
svc.CurrentState = "SERVICE_START_PENDING"
dll.Sleeping svc.WaitHint

MsgBox svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

Debug.Print "CurrentState: " & svc.CurrentState
Debug.Print "ServiceType: " & svc.ServiceType

Example 1b
"SERVICE_WIN32_SHARE_PROCESS_INTERACTIVE" to "SERVICE_WIN32_SHARE_PROCESS" (early binding)

'the same as in example 1a ...

'...

svc.ServiceType = "SERVICE_WIN32_SHARE_PROCESS"

'...

'the same as in example 1a ...

Example 2a
"SERVICE_WIN32_OWN_PROCESS" with LocalSystem to "SERVICE_WIN32_OWN_PROCESS_INTERACTIVE" with LocalSystem
(early binding)

Dim svc As New Service, dll As New DllClass
Dim lRes As Long
Dim sv As String

'the service type of the MSDTC service should not be changed
'it is only an example for a service with own process
sv = "MSDTC"

MsgBox svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

Debug.Print "CurrentState: " & svc.CurrentState
Debug.Print "ServiceType: " & svc.ServiceType

'stopping the service
svc.CurrentState = "SERVICE_STOP_PENDING"
dll.Sleeping svc.WaitHint

svc.ServiceType = "SERVICE_WIN32_OWN_PROCESS_INTERACTIVE"

'starting the service
svc.CurrentState = "SERVICE_START_PENDING"
dll.Sleeping svc.WaitHint

MsgBox svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

Debug.Print "CurrentState: " & svc.CurrentState
Debug.Print "ServiceType: " & svc.ServiceType

Example 2b
"SERVICE_WIN32_OWN_PROCESS_INTERACTIVE" with LocalSystem to "SERVICE_WIN32_OWN_PROCESS" with LocalSystem
(early binding)

'the same as in example 2a ...

'...

svc.ServiceType = "SERVICE_WIN32_OWN_PROCESS"

'...

'the same as in example 2a ...

Example 3a
"SERVICE_WIN32_OWN_PROCESS_INTERACTIVE" with LocalSystem to "SERVICE_WIN32_OWN_PROCESS" with a special user
(early binding)

Dim svc As New Service, dll As New DllClass
Dim lRes As Long
Dim sv As String

'the service type of the Visual Studio Analyzer RPC bridge
'service should not be changed
'it is only an example for a service with own process
sv = "Visual Studio Analyzer RPC bridge"

MsgBox svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

Debug.Print "CurrentState: " & svc.CurrentState
Debug.Print "ServiceType: " & svc.ServiceType

'stopping the service
svc.CurrentState = "SERVICE_STOP_PENDING"
dll.Sleeping svc.WaitHint

svc.ServiceType = "SERVICE_WIN32_OWN_PROCESS"
svc.ServiceStartName = "MyDomain\ServiceAccount"
svc.ServicePassword = "gs5!x<"

'starting the service
svc.CurrentState = "SERVICE_START_PENDING"
dll.Sleeping svc.WaitHint

MsgBox svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

Debug.Print "CurrentState: " & svc.CurrentState
Debug.Print "ServiceType: " & svc.ServiceType

Example 3b
"SERVICE_WIN32_OWN_PROCESS" with LocalSystem to "SERVICE_WIN32_OWN_PROCESS" with a special user
(early binding)

'the same as in example 3a ...

Example 3c
"SERVICE_WIN32_OWN_PROCESS" with a special user to "SERVICE_WIN32_OWN_PROCESS" with LocalSystem
(early binding)

'the same as in example 3a ...

'...

'The service type must not be changed
'svc.ServiceType = "SERVICE_WIN32_OWN_PROCESS"
svc.ServiceStartName = "LocalSystem"
'the password must be blank
svc.ServicePassword = ""

'...

'the same as in example 3a ...

Example 3d
"SERVICE_WIN32_OWN_PROCESS" with a special user to "SERVICE_WIN32_OWN_PROCESS_INTERACTIVE" with LocalSystem
(early binding)

'the same as in example 3a ...

'...

'the type must be changed after changing the account
'and password (difference to example 3a)
svc.ServiceStartName = "LocalSystem"
'the password must be blank
svc.ServicePassword = ""
svc.ServiceType = "SERVICE_WIN32_OWN_PROCESS_INTERACTIVE"

'...

'the same as in example 3a ...

"Example 4 - querying the property (late binding)

Dim sv1 As Object, sv2 As Object
Dim lngResult As Long

Set sv1 = CreateObject("ntXdll.Service")
Set sv2 = CreateObject("ntXdll.Service")

lngResult = sv1.InitServices(sv1.SV_WIN32, "WorkstationName", "unknown")

For Each sv2 In sv1.Services

Debug.Print sv2.ServiceType

Next


ServiceFlags As String

Class Service

Saturday, June 17, 2000

ServiceFlags As String

Property (read only)

Return value

Returns the ServiceFlags of a service. If an error occurs or the string would be empty, the optional parameter strDefault of the functions GetServiceInfo (...) or InitServices (...) will be returned. Then, in case of an error, property LastError of this class is set to an error number. This value can be an internal, a VB or an API error. Otherwise, in case of success, LastError is 0 (zero). To get the description of an API error, use function FormatAPIMessage of class DllClass (see the example).

The returned value can be one of the following strings:

"SERVICE_STOPPED"
"SERVICE_RUNS_IN_SYSTEM_PROCESS"

A returned value "SERVICE_STOPPED" must not necessarily mean, that the service is not running (see the example 2). The value has two meanings. Either, the service is really not running or it is running, but not in a system process (then, property ProcessID of this class would be non zero).

The property is accessable over the collection Services of this class. Then, the property shows the ServiceFlags of each Valid member of the collection (which represents a service or device on the local or a remote computer). At first, execute function InitServices (...) to initialize the collection. For devices, you have to assign the value SV_DRIVER to parameter lngServiceType of function InitServices (...).

The property is also accessable over one single object, which is initialized with function GetServiceInfo (...) of this class. This Valid object represents a single service or device on the local or a remote computer.

See also:

InitServices
GetServiceInfo
Valid
SV_WIN32, SV_DRIVER
Services
LastError
FormatAPIMessage

Example1 - querying the property from all services on a computer (late binding)

Dim svc, svcMember, dll
Dim lngResult

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lngResult = svc.InitServices(svc.SV_WIN32, "WorkstationName")
lngResult = svc.LastError
MsgBox dll.FormatAPIMessage(lngResult, CStr(lngResult))

For Each svcMember In svc.Services

Debug.Print svcMember.ServiceFlags

Next

Example2 - querying the property from a single service on a computer (late binding)

Dim svc, dll
Dim lRes
Dim sv

sv = "SampleService"

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lRes = svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

If svc.ServiceFlags = "SERVICE_STOPPED" Then

If svc.ProcessID <> 0 Then

MsgBox "Service is running in a process, that is not a system process"

Else

MsgBox "Service is not running"

End If

Else

MsgBox "ServiceFlags: " & svc.ServiceFlags

End If


StartType As String

Class Service

Saturday, June 17, 2000

StartType As String

Property

Return value

Returnes or sets the StartType of a service. If an error occurs or the string would be empty, the optional parameter strDefault of the functions InitServices (...) or GetServiceInfo (...) will be returned. The returned value can be one of the following strings.

"SERVICE_BOOT_START"
"SERVICE_SYSTEM_START"
"SERVICE_AUTO_START"
"SERVICE_DEMAND_START"
"SERVICE_DISABLED"

The property is accessable over the collection Services of this class. Then, the property shows the StartType of each Valid member of the collection (which represents a service or device on the local or a remote computer). At first, execute function InitServices (...) to initialize the collection. For devices, you have to assign the value SV_DRIVER to parameter lngServiceType of function InitServices .

The property is also accessable over one single object, which is initialized with function GetServiceInfo (...) of this class. This Valid object represents a single service or device on the local or a remote computer.

If you set the property, you can assign a StartType to the service or device. You only can set the property within a Valid Service object. You get Valid Service objects with functions InitServices (...) or GetServiceInfo (...) of this class. You set the property by assigning one of the strings shown above to it.

You can set all of the strings above to a device, but only the following strings to a service:

"SERVICE_AUTO_START"
"SERVICE_DEMAND_START"
"SERVICE_DISABLED"

You should stop the service or device before setting StartType. Then after changing it, start the service for that the changes take effect. You can control (stop and start) a service with property CurrentState of this class.

If an error occurs while changing the property, property LastError of this class is set to an error number. This value can be an internal, a VB or an API error. Otherwise, in case of success, LastError is 0 (zero). To get the description of an API error, use function FormatAPIMessage of class DllClass (see the example).

See also:

InitServices
GetServiceInfo
SV_WIN32, SV_DRIVER
Services
Valid
CurrentState
LastError
FormatAPIMessage

Example1 - querying the property from a single service on a computer (late binding)

Dim sv As Object
Dim lngResult As Long

Set sv = CreateObject("ntXdll.Service")

lngResult = sv.GetServiceInfo("netlogon", "WorkstationName", "NULL")
lngResult = svc.LastError
MsgBox dll.FormatAPIMessage(lngResult, CStr(lngResult))

MsgBox sv2.StartType

Example2 - setting the property (early binding)

Dim svc As New Service, dll As New DllClass
Dim lRes As Long
Dim sv As String

sv = "sampleservice"

MsgBox svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

Debug.Print "BinaryPathName: " & svc.StartType

'stopping the service
svc.CurrentState = "SERVICE_STOP_PENDING"
dll.Sleeping svc.WaitHint

svc.StartType = "SERVICE_AUTO_START"

'starting the service
svc.CurrentState = "SERVICE_START_PENDING"
dll.Sleeping svc.WaitHint

MsgBox svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

Debug.Print "ServiceType: " & svc.StartType


Dependencies As String

Class Service

Saturday, June 17, 2000

Dependencies As String

Property (read only)

Return value

Returnes the dependencies to other services or service groups of a service. A service or device can depend on one or more other services or devices. A service can also depend on a service group. The property returns a string in which all services or groups, the service depends on, are seperated by a semicolon. Service groups are leaded by a plus (+).

If an error occurs or the string would be empty, the optional parameter strDefault of the functions GetServiceInfo (...) or InitServices (...) will be returned. Then, property LastError of this class is set to an error number. This value can be an internal, a VB or an API error. Otherwise, in case of success, LastError is 0 (zero). To get the description of an API error, use function FormatAPIMessage of class DllClass (see the example).

The property is accessable over the collection Services of this class. Then, the property shows the Dependencies of each Valid member of the collection (which represents a service or device on the local or a remote computer). At first, execute function InitServices (...) to initialize the collection. For devices, you have to assign the value SV_DRIVER to parameter lngServiceType of function InitServices (...).

The property is also accessable over one single object, which is initialized with function GetServiceInfo (...) of this class. This Valid object represents a single service or device on the local or a remote computer.

See also:

InitServices
GetServiceInfo
Valid
SV_WIN32, SV_DRIVER
Services
LastError
FormatAPIMessage

Example1 - querying the property from all services on a computer (late binding)

Dim svc, svcMember, dll
Dim lngResult

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lngResult = svc.InitServices(svc.SV_WIN32, "WorkstationName")
lngResult = svc.LastError
MsgBox dll.FormatAPIMessage(lngResult, CStr(lngResult))

For Each svcMember In svc.Services

Debug.Print svcMember.Dependencies

Next

Example2 - querying the property from a single service on a computer (late binding)

Dim svc, dll
Dim lRes
Dim sv

sv = "SampleService"

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lRes = svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

MsgBox "Dependencies: " & svc.Dependencies


LoadOrderGroup As String

Class Service

Saturday, June 17, 2000

LoadOrderGroup As String

Property (read only)

Return value

Returnes the LoadOrderGroup of a service. Look at the explanations for further informations.

If an error occurs or the string would be empty, the optional parameter strDefault of the functions GetServiceInfo (...) or InitServices (...) will be returned.

The property is accessable over the collection Services of this class. Then, the property shows the LoadOrderGroup of each Valid member of the collection (which represents a service or device on the local or a remote computer). At first, execute function InitServices (...) to initialize the collection. For devices, you have to assign the value SV_DRIVER to parameter lngServiceType of function InitServices (...).

The property is also accessable over one single object, which is initialized with function GetServiceInfo (...) of this class. This Valid object represents a single service or device on the local or a remote computer.

Explanation

In the registry, there exist a list of groups of services at:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ServiceGroupOrder

A service can be a member of one of these groups or not. The system uses this list to load services in a specified order with respect to the other groups in the list. You can place a service in a group so that another service can depend on the group.

The order in which a service starts is determined by the following criteria:

  1. The order of groups in the registry's load-ordering group list. Services in groups in the load-ordering group list are started first, followed by services in groups not in the load-ordering group list and then services that do not belong to a group.
  2. The service's dependencies listed in the property Dependencies of this class and the dependencies of other services dependent on the service

See also:

InitServices
GetServiceInfo
Valid
SV_WIN32, SV_DRIVER
Services
LastError
FormatAPIMessage

Example1 - querying the property from all services on a computer (late binding)

Dim svc, svcMember, dll
Dim lngResult

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lngResult = svc.InitServices(svc.SV_WIN32, "WorkstationName")
lngResult = svc.LastError
MsgBox dll.FormatAPIMessage(lngResult, CStr(lngResult))

For Each svcMember In svc.Services

Debug.Print svcMember.LoadOrderGroup

Next

Example2 - querying the property from a single service on a computer (late binding)

Dim svc, dll
Dim lRes
Dim sv

sv = "SampleService"

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lRes = svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

MsgBox "LoadOrderGroup: " & svc.LoadOrderGroup


ControlsAccepted As String

Class Service

Saturday, June 17, 2000

ControlsAccepted As String

Property (read only)

Return value

Returnes the accepted control(s) of a service. Specifies the control codes that the service will accept and process in its Handler function. A user interface process can control a service by specifying a control command in a specific function.

If an error occurs or the string of the property would be empty, the optional parameter strDefault of the functions GetServiceInfo (...) or InitServices (...) will be returned. Then, property LastError of this class is set to an error number. This value can be an internal, a VB or an API error. Otherwise, in case of success, LastError is 0 (zero). To get the description of an API error, use function FormatAPIMessage of class DllClass (see the example).

The string can be builted from one or more of the following strings:

"SERVICE_ACCEPT_STOP"
"SERVICE_ACCEPT_PAUSE_CONTINUE"
"SERVICE_ACCEPT_SHUTDOWN"
"SERVICE_ACCEPT_PARAMCHANGE"
"SERVICE_ACCEPT_NETBINDCHANGE"

The property is accessable over the collection Services of this class. Then, the property shows the ControlsAccepted of each Valid member of the collection (which represents a service or device on the local or a remote computer). At first, execute function InitServices (...) to initialize the collection. For devices, you have to assign the value SV_DRIVER to parameter lngServiceType of function InitServices (...).

The property is also accessable over one single object, which is initialized with function GetServiceInfo (...) of this class. This Valid object represents a single service or device on the local or a remote computer.

See also:

InitServices
GetServiceInfo
Valid
SV_WIN32, SV_DRIVER
Services
LastError
FormatAPIMessage

Example1 - querying the property from all services on a computer (late binding)

Dim svc, svcMember, dll
Dim lngResult

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lngResult = svc.InitServices(svc.SV_WIN32, "WorkstationName")
lngResult = svc.LastError
MsgBox dll.FormatAPIMessage(lngResult, CStr(lngResult))

For Each svcMember In svc.Services

Debug.Print svcMember.ControlsAccepted

Next

Example2 - querying the property from a single service on a computer (late binding)

Dim svc, dll
Dim lRes
Dim sv

sv = "SampleService"

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lRes = svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

MsgBox "ControlsAccepted: " & svc.ControlsAccepted


Win32ExitCode As Long

Class Service

Saturday, June 17, 2000

Win32ExitCode As Long

Property (read only)

Return value

Returnes the Win32ExitCode of a service. Specifies an Win32 error code that the service uses to report an error that occurs when it is starting or stopping. You can use the property CurrentState of this class to start and stop services.

To return an error code specific to the service, the service must set this value to ERROR_SERVICE_SPECIFIC_ERROR to indicate that the ServiceSpecificExitCode member contains the error code. The service should set this value to NO_ERROR (0) when it is running and when it terminates normally.

If you want to get the right value, if an error occurs while starting or stopping the service, you have to wait for the completion of changing the property CurrentState (this is not the default behavior of this property) and you have to call GetServiceInfo (...) to refresh the property. For this feature, look at example 3.

The property is accessable over the collection Services of this class. Then, the property shows the Win32ExitCode of each Valid member of the collection (which represents a service or device on the local or a remote computer). At first, execute function InitServices (...) to initialize the collection. For devices, you have to assign the value SV_DRIVER to parameter lngServiceType of function InitServices .

The property is also accessable over one single object, which is initialized with function GetServiceInfo (...) of this class. This Valid object represents a single service or device on the local or a remote computer.

See also:

InitServices (...)
 SV_WIN32, SV_DRIVER
Services
ServiceSpecificExitCode
ERROR_SERVICE_SPECIFIC_ERROR

Example1 - querying the property from all services on a computer (late binding)

Dim svc, svcMember, dll
Dim lngResult

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lngResult = svc.InitServices(svc.SV_WIN32, "WorkstationName")
lngResult = svc.LastError
MsgBox dll.FormatAPIMessage(lngResult, CStr(lngResult))

For Each svcMember In svc.Services

Debug.Print svcMember.Win32ExitCode

Next

Example2 - querying the property from a single service on a computer (late binding)

Dim svc, dll
Dim lRes
Dim sv

sv = "SampleService"

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lRes = svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

MsgBox "Win32ExitCode: " & svc.Win32ExitCode

Example3

'look at example 3 of property CurrentState


ServiceSpecificExitCode As Long

Class Service

Saturday, June 17, 2000

ServiceSpecificExitCode As Long

Property (read only)

Return value

Returns the ServiceSpecificExitCode of a service. The property specifies a service-specific error code that the service returns when an error occurs while the service is starting or stopping. You can use the property CurrentState of this class to start and stop services. This value is ignored unless the Win32ExitCode property returns ERROR_SERVICE_SPECIFIC_ERROR .

If you want to get the right value, if an error occurs while starting or stopping the service, you have to wait for the completion of changing the property CurrentState (this is not the default behavior of this property) and you have to call GetServiceInfo (...) to refresh the property. For this feature, look at example 3.

The property is accessable over the collection Services of this class. Then, the property shows the ServiceSpecificExitCode of each Valid member of the collection (which represents a service or device on the local or a remote computer). At first, execute function InitServices (...) to initialize the collection. For devices, you have to assign the value SV_DRIVER to parameter lngServiceType of function InitServices .

The property is also accessable over one single object, which is initialized with function GetServiceInfo (...) of this class. This Valid object represents a single service or device on the local or a remote computer.

See also:

InitServices
GetServiceInfo
ServiceName
SV_WIN32, SV_DRIVER
Services
Valid
LastError
FormatAPIMessage
CurrentState
Win32ExitCode
ERROR_SERVICE_SPECIFIC_ERROR

Example1 - querying the property from all services on a computer (late binding)

Dim svc, svcMember, dll
Dim lngResult

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lngResult = svc.InitServices(svc.SV_WIN32, "WorkstationName")
lngResult = svc.LastError
MsgBox dll.FormatAPIMessage(lngResult, CStr(lngResult))

For Each svcMember In svc.Services

Debug.Print svcMember.ServiceSpecificExitCode

Next

Example2 - querying the property from a single service on a computer (late binding)

Dim svc, dll
Dim lRes
Dim sv

sv = "SampleService"

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lRes = svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

MsgBox "ServiceSpecificExitCode: " & svc.ServiceSpecificExitCode

Example3

'look at example 3 of property CurrentState


ERROR_SERVICE_SPECIFIC_ERROR As Long

Class Service

Saturday, June 17, 2000

ERROR_SERVICE_SPECIFIC_ERROR As Long

Property (read only)

Return value

For more information, look to 'See also'. The property is used like a constant to query, whether the property Win32ExitCode is referring to the property ServiceSpecificExitCode .

See also:


ErrorControl As String

Class Service

Saturday, June 17, 2000

ErrorControl As String

Property (read only)

Return value

Returnes the ErrorControl of a service. This is the severity of the error if this service fails to start during startup, and determines the action taken by the startup program if failure occurs.

If an error occurs or the string would be empty, the optional parameter strDefault of the functions GetServiceInfo (...) or InitServices (...) will be returned. Then, in case of an error, property LastError of this class is set to an error number. This value can be an internal, a VB or an API error. Otherwise, in case of success, LastError is 0 (zero). To get the description of an API error, use function FormatAPIMessage of class DllClass (see the example).

The returned value can be one of the following strings:

"SERVICE_ERROR_IGNORE"
"SERVICE_ERROR_NORMAL"
"SERVICE_ERROR_SEVERE"
"SERVICE_ERROR_CRITICAL"

The property is accessable over the collection Services of this class. Then, the property shows the ErrorControl of each Valid member of the collection (which represents a service or device on the local or a remote computer). At first, execute function InitServices (...) to initialize the collection. For devices, you have to assign the value SV_DRIVER to parameter lngServiceType of function InitServices (...).

The property is also accessable over one single object, which is initialized with function GetServiceInfo (...) of this class. This Valid object represents a single service or device on the local or a remote computer.

See also:

InitServices
GetServiceInfo
Valid
SV_WIN32, SV_DRIVER
Services
LastError
FormatAPIMessage

Example1 - querying the property from all services on a computer (late binding)

Dim svc, svcMember, dll
Dim lngResult

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lngResult = svc.InitServices(svc.SV_WIN32, "WorkstationName")
lngResult = svc.LastError
MsgBox dll.FormatAPIMessage(lngResult, CStr(lngResult))

For Each svcMember In svc.Services

Debug.Print svcMember.ErrorControl

Next

Example2 - querying the property from a single service on a computer (late binding)

Dim svc, dll
Dim lRes
Dim sv

sv = "SampleService"

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lRes = svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

MsgBox "ErrorControl: " & svc.ErrorControl


WaitHint As Long

Class Service

Saturday, June 17, 2000

WaitHint As Long

Property (read only)

Return value

Returnes the WaitHint of a service. WaitHint is an estimate of the amount of time, in milliseconds, that the service expects a pending start, stop, or continue operation to take before the service makes its next call to set the state with either an incremented CheckPoint property or a change in current state. You can use the property CurrentState of this class to start and stop services.

If the amount of time specified by WaitHint passes, and CheckPoint has not been incremented or CurrentState has not changed, the service control manager or service control program can assume that an error has occurred.

If you want to get the right value, if an error occurs while starting or stopping the service, you have to wait for the completion of changing the property CurrentState (this is not the default behavior of this property) and you have to call GetServiceInfo (...) to refresh the property. For this feature, look at example 3.

The property is accessable over the collection Services of this class. Then, the property shows the WaitHint of each Valid member of the collection (which represents a service or device on the local or a remote computer). At first, execute function InitServices (...) to initialize the collection. For devices, you have to assign the value SV_DRIVER to parameter lngServiceType of function InitServices .

The property is also accessable over one single object, which is initialized with function GetServiceInfo (...) of this class. This Valid object represents a single service or device on the local or a remote computer.

See also:

InitServices
GetServiceInfo
ServiceName
SV_WIN32, SV_DRIVER
Services
Valid
LastError
FormatAPIMessage
CurrentState

Example1 - querying the property from all services on a computer (late binding)

Dim svc, svcMember, dll
Dim lngResult

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lngResult = svc.InitServices(svc.SV_WIN32, "WorkstationName")
lngResult = svc.LastError
MsgBox dll.FormatAPIMessage(lngResult, CStr(lngResult))

For Each svcMember In svc.Services

Debug.Print svcMember.WaitHint

Next

Example2 - querying the property from a single service on a computer (late binding)

Dim svc, dll
Dim lRes
Dim sv

sv = "SampleService"

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lRes = svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

MsgBox "WaitHint: " & svc.WaitHint

Example3

'look at example 3 of property CurrentState


TagID As Long

Class Service

Saturday, June 17, 2000

TagID As Long

Property (read only)

Return value

Returns the TagID of a service. The property specifies a unique tag value for this service in the group specified by the LoadOrderGroup property. A value of zero indicates that the service has not been assigned a tag. Service application or system use a tag for ordering service startup within a load order group by specifying a tag order vector in the registry located at:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\GroupOrderList.

Tags are only evaluated for SERVICE_KERNEL_DRIVER and SERVICE_FILE_SYSTEM_DRIVER type services that have SERVICE_BOOT_START or SERVICE_SYSTEM_START start types.

The property is accessable over the collection Services of this class. Then, the property shows the TagID of each Valid member of the collection (which represents a service or device on the local or a remote computer). At first, execute function InitServices (...) to initialize the collection. For devices, you have to assign the value SV_DRIVER to parameter lngServiceType of function InitServices .

The property is also accessable over one single object, which is initialized with function GetServiceInfo (...) of this class. This Valid object represents a single service or device on the local or a remote computer.

See also:

InitServices
GetServiceInfo
ServiceName
SV_WIN32, SV_DRIVER
Services
Valid
LastError
FormatAPIMessage
LoadOrderGroup

Example1 - querying the property from all services on a computer (late binding)

Dim svc, svcMember, dll
Dim lngResult

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lngResult = svc.InitServices(svc.SV_WIN32, "WorkstationName")
lngResult = svc.LastError
MsgBox dll.FormatAPIMessage(lngResult, CStr(lngResult))

For Each svcMember In svc.Services

Debug.Print svcMember.TagID

Next

Example2 - querying the property from a single service on a computer (late binding)

Dim svc, dll
Dim lRes
Dim sv

sv = "SampleService"

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lRes = svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

MsgBox "TagID: " & svc.TagID


CheckPoint As Long

Class Service

Saturday, June 17, 2000

CheckPoint As Long

Property (read only)

Return value

Returnes the checkpoint of a service. Checkpoint is a value that the service increments periodically to report its progress during a lengthy start, stop, or continue operation. For example, the service should increment this value as it completes each step of its initialization when it is starting up.

The user interface program that invoked the operation on the service uses this value to track the progress of the service during a lengthy operation. This value should be zero when the service does not have a start, stop, or continue operation pending.

The property is accessable over the collection Services of this class. Then, the property shows the CheckPoint of each Valid member of the collection (which represents a service or device on the local or a remote computer). At first, execute function InitServices (...) to initialize the collection. For devices, you have to assign the value SV_DRIVER to parameter lngServiceType of function InitServices (...).

The property is also accessable over one single object, which is initialized with function GetServiceInfo (...) of this class. This Valid object represents a single service or device on the local or a remote computer.

See also:

InitServices
GetServiceInfo
Valid
SV_WIN32, SV_DRIVER
Services
LastError
FormatAPIMessage

Example1 - querying the property from all services on a computer (late binding)

Dim svc, svcMember, dll
Dim lngResult

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lngResult = svc.InitServices(svc.SV_WIN32, "WorkstationName")
lngResult = svc.LastError
MsgBox dll.FormatAPIMessage(lngResult, CStr(lngResult))

For Each svcMember In svc.Services

Debug.Print svcMember.CheckPoint

Next

Example2 - querying the property from a single service on a computer (late binding)

Dim svc, dll
Dim lRes
Dim sv

sv = "SampleService"

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lRes = svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

MsgBox "CheckPoint: " & svc.CheckPoint


LastError As Long

Class Service

Friday, December 21, 2001

LastError As Long

Property (read only)

Return value

The property returns an error number which is set by different functions and properties of this class. A value of 0 means no error. Otherwise the error number can be an internal, a VB or an API error. It is documented in the help of the methods which set this property. To get the description of an API error, use function FormatAPIMessage of class DllClass (see the example).

See also

FormatAPIMessage

Example1 - setting a service property (late binding)

Dim svc, dll
Dim lRes
Dim sv

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

sv = "protectedstorage"

'at first initializing a valid service object
MsgBox svc.GetServiceInfo(sv, "RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

'printing the property before setting it
Debug.Print "CurrentState: " & svc.CurrentState

'setting the property
svc.CurrentState = "SERVICE_STOP_PENDING"

'printing the property after setting it
Debug.Print "CurrentState: " & svc.CurrentState

lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

Example2 - executing a function (early binding)

Dim svc As New Service, dll As New DllClass
Dim lRes As Long

MsgBox svc.GetServiceInfo("Modem", "RemoteComputer", "")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

Debug.Print "DisplayName: " & svc.DisplayName


InitServiceDB(...) As Long

Class Service

Saturday, June 17, 2000

InitServiceDB([strComputer As String], [strDefault As String]) As Long

Function

Return value

Returnes 0 in case of an error, otherwise a non zero value. If 0 is returned, the property LastError of this class is set to an error number. This value can be an internal, a VB or an API error. To get the description of an API error, use function FormatAPIMessage of class DllClass (see the example).

The function initialices the properties, referred to the Service Database on a computer. Then, you have a ValidDB Service object.

Parameters

strComputer
if you want to connect to a remote computer, assign the name without leading backslashs. If you omitt strComputer, the local Service Database will be inspected.

strDefault
the string properties of the Service Database, which would return an empty string, return now strDefault. If you omitt strDefault, the empty string properties will return "unknown".

See also:

LastError
FormatAPIMessage
ValidDB
ServiceDBLocked
ServiceDBLockOwner
ServiceDBLockDuration

Example (late binding)

Dim sv As Object, dll As Object
Dim lngResult As Long

Set sv = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lngResult = sv.InitServiceDB()
lngResult = sv.LastError
MsgBox dll.FormatAPIMessage(lngResult, CStr(lngResult))

Debug.Print sv.ServiceDBLocked
Debug.Print sv.ServiceDBLockOwner
Debug.Print sv.ServiceDBLockDuration


ValidDB As Boolean

Class Service

Saturday, December 22, 2001

ValidDB As Boolean

Property (read only)

Return value

Returns whether a Service object represents an existing service database on the local or a remote computer.

To get the property, you have to init the properties of a Service object at first with function InitServiceDB of this class. If you have executed this function without error, the properties ServiceDB* of the Service object are filled with information and the object represents an existing service database.

The property ServiceDBLocked of this class, which can be set (which is not read only), can only be set within a Valid Service object.

See also

InitServiceDB
ServiceDBLocked
ServiceDBLockOwner
ServiceDBLockDuration

Example (early binding)

Dim svc As New Service, dll As New DllClass
Dim lRes As Long

MsgBox svc.InitServiceDB("RemoteComputer", "NULL")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

Debug.Print "Valid: " & svc.ValidDB


ServiceDBLocked As Boolean

Class Service

Saturday, June 17, 2000

ServiceDBLocked As Boolean

Property

Return value

Returnes or sets, whether a service database of a computer is locked or not. These locks are sometimes necessary, if one or more services must be configured and if it must be guaranteed, that any of the services will not be started until the configuration is completed.

You have to execute the function InitServiceDB (...) at first to initialize the property. Then, you have a ValidDB Service object, which represents a service database on the local or a remote computer. The property is only accessable over object, through which the function InitServiceDB (...) was called.

If an error occurs while executing InitServiceDB , the property LastError of this class is set to an error number. This value can be an internal, a VB or an API error. Otherwise, in case of success, LastError is 0 (zero). To get the description of an API error, use function FormatAPIMessage of class DllClass (see the example).

If you want to set the property, you have to assign a boolean value (True or False) to the property. You only can set the property within a ValidDB Service object. You get ValidDB Service objects with function InitServiceDB (...) of this class.

When you lock a service database by assigning True to the property, a lock handle is stored internally in the ValidDB Service object. Therefore, you only can unlock the database withing the same Service object. So, be carefully and do not remove the Service object from memory until you have not unlocked the database (for example with the command "Set svc = Nothing", if svc is a ValidDB Service object) .Otherwise you would have to restart the computer to unlock the database.

If an error occurs while changing the property, property LastError of this class is set to an error number. This value can be an internal, a VB or an API error. Otherwise, in case of success, LastError is 0 (zero). To get the description of an API error, use function FormatAPIMessage of class DllClass (see the example).

See also:

InitServiceDB
ValidDB
LastError
FormatAPIMessage

Example - querying the property (late binding)

Dim sv, dll
Dim lngResult

Set sv = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lngResult = sv.InitServiceDB()
lngResult = sv.LastError
MsgBox dll.FormatAPIMessage(lngResult, CStr(lngResult))

Debug.Print sv.ServiceDBLocked

Example - setting the property (early binding)

Dim svc As New Service, dll As New DllClass
Dim lRes As Long
Dim s As String

lRes = svc.InitServiceDB(InputBox("Computer"),
    InputBox("Default"))
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

MsgBox svc.ServiceDBLocked

MsgBox "Database will now be locked"

svc.ServiceDBLocked = True
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

MsgBox svc.ServiceDBLocked

MsgBox "Database will now be unlocked"

svc.ServiceDBLocked = False
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

MsgBox svc.ServiceDBLocked


ServiceDBLockDuration As Long

Class Service

Saturday, June 17, 2000

ServiceDBLockDuration As Long

Property (read only)

Return value

Returnes the ServiceDBLockDuration of a service database of a computer in milliseconds. If the service database is not locked, 0 (zero) will be returned.

You have to execute the function InitServiceDB (...) at first to initialize the property. Then, you have a ValidDB Service object, which represents a service database on the local or a remote computer. The property is only accessable over object, through which the function InitServiceDB (...) was called.

The property will be not refreshed automatically. To refresh it, you have to execute InitServiceDB (...) again.

See also:

InitServiceDB
ValidDB
LastError
FormatAPIMessage

Example (late binding)

Dim sv As Object, dll As Object
Dim lngResult As Long

Set sv = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lngResult = sv.InitServiceDB()
lngResult = sv.LastError
MsgBox dll.FormatAPIMessage(lngResult, CStr(lngResult))

MsgBox "ServiceDBLockDuration: " & sv.ServiceDBLockDuration


ServiceDBLockOwner As String

Class Service

Saturday, June 17, 2000

ServiceDBLockOwner As String

Property (read only)

Return value

Returnes the ServiceDBLockOwner of a locked service database of a computer. This is the name of the user who acquired the lock. If the service database is not locked or in case of an error "unknown" or the parameter strDefault of the function InitServiceDB (...) of this class will be returned.

You have to execute the function InitServiceDB (...) at first to initialize the property. Then, you have a ValidDB Service object, which represents a service database on the local or a remote computer. The property is only accessable over object, through which the function InitServiceDB (...) was called.

See also:

InitServiceDB (...)
 ValidDB
LastError
FormatAPIMessage

Example (late binding)

Dim sv, dll
Dim lngResult

Set sv = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

lngResult = sv.InitServiceDB()
lngResult = sv.LastError
MsgBox dll.FormatAPIMessage(lngResult, CStr(lngResult))

MsgBox "ServiceDBLockOwner: " & sv.ServiceDBLockOwner


GetServiceName(...) As Long

Class Service

Friday, December 21, 2001

GetDisplayName

(strServiceName As String,
[strComputer],
[strDefault As String)

As String

Function

Return value

Returns the display name of a service or device, which corresponds to the specified parameter strServiceName.

In some cases, the service name, which is the internal name of a service or device in the system, differs from the display name, which is shown in the service control manager.

If there occurs an error whithin the function, the function returns a string, you assigned to parameter strDefault and the property LastError of this class is set to an error number. This value can be an internal, a VB or an API error. Otherwise, in case of success, LastError is 0 (zero). To get the description of an API error, use function FormatAPIMessage of class DllClass (see the example).

To get the service name from a corresponding display name, use function GetServiceName of this class.

Parameters

strServiceName
specifies the name of the service or device, you want to get the display name from. The service name is the internal name of a service or device in the system and is stored in the name of a subkey in HKLM\SYSTEM\CurrentControlSet\Services. The parameter is not case sensitive.

strComputer (optional)
specifies the name of the computer where the service or device exists from which you want to get the display name from. Do not use leading backslashs ('\\'). If you omitt the parameter, the local machine is used.

strDefault (optional)
specifies, which string will be retuned in case of an error. If you omitt the parameter, the string "unknown" will be used. You can assign an empty string.

See also

LastError
FormatAPIMessage
GetServiceName

Example (late binding)

Dim svc, dll
Dim lRes
Dim s

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

s = svc.GetDisplayName("netlogon", "RemoteComputer", "Error")
MsgBox s

lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))


GetServiceName(...) As Long

Class Service

Friday, December 21, 2001

GetServiceName

(strDisplayName As String,
[strComputer],
[strDefault As String)

As String

Function

Return value

Returns the service name of a service or device, which corresponds to the specified parameter strDisplayName.

In some cases, the service name, which is the internal name of a service or device in the system, differs from the display name, which is shown in the service control manager.

If there occurs an error whithin the function, the function returns a string, you assigned to parameter strDefault and the property LastError of this class is set to an error number. This value can be an internal, a VB or an API error. Otherwise, in case of success, LastError is 0 (zero). To get the description of an API error, use function FormatAPIMessage of class DllClass (see the example).

To get the display name from a corresponding service name, use function GetDisplayName of this class.

Parameters

strDisplayName
specifies the display name of the service or device, you want to get the service name from. The display name is the name, which is shown in the service control manager and is stored in the REG_SZ registry value "DisplayName" in the corresponding subkey in HKLM\SYSTEM\CurrentControlSet\Services. The parameter is not case sensitive.

strComputer (optional)
specifies the name of the computer where the service or device exists from which you want to get the service name from. Do not use leading backslashs ('\\'). If you omitt the parameter, the local machine is used.

strDefault (optional)
specifies, which string will be retuned in case of an error. If you omitt the parameter, the string "unknown" will be used. You can assign an empty string.

See also

LastError
FormatAPIMessage
GetDisplayName

Example (late binding)

Dim svc, dll
Dim lRes
Dim s

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

s = svc.GetServiceName("protected storage", "RemoteComputer", "Error")
MsgBox s

lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))


RemoveService(...) As Long

Class Service

Saturday, December 22, 2001

RemoveService

(strServiceName As String,
[strComputer])

As String

Function

Return value

Returns a non zero value in case of success, otherwise 0 (zero). If 0 is returned, the property LastError of this class is set to an error number. This value can be an internal, a VB or an API error. To get the description of an API error, use function FormatAPIMessage of class DllClass (see the example).

The function deletes a service or device from the local or a remote computer. But the service will be not deleted immediately after executing the function. The specified service will only be remarked for deletion. In the moment, when the services stopps and when all handles to the service are closed, the services will be completely deleted.

You should stop the service at first with property CurrentState of this class, before executing the function.

Parameters

strServiceName
specifies the name of the service or device, you want to delete. The service name is the internal name of a service or device in the system and must not be the same as the display name, which is displayed in the service control manager. To get the service name from a display name, use function GetServiceName of this class.

strComputer (optional)
specifies the name of the computer where the service or device exists which you want to delete.

See also

LastError
FormatAPIMessage
CurrentState
GetServiceName

Example (late binding)

Dim svc, dll
Dim lRes
Dim s

Set svc = CreateObject("ntXdll.Service")
Set dll = CreateObject("ntXdll.DllClass")

s = svc.GetServiceName("protected storage", "RemoteComputer")

lRes = svc.GetServiceInfo(s, "RemoteComputer")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

If svc.Valid Then

'stopping the service
svc.CurrentState = "SERVICE_STOP_PENDING"
'deleting the service
lRes = svc.RemoveService(s, "RemoteComputer")
lRes = svc.LastError
MsgBox dll.FormatAPIMessage(lRes, CStr(lRes))

End If


Class Stringer

Tuesday, January 15, 2002

Class Stringer

This class provides some functions and properties to handle or transform strings. Please read the help of each element to get detailed information.

A special function is InitSeperator , which initializes the collection SepStrings . Each member of this collection has property SepString , which represents one of the strings, separated by a specified character in another string.


GetCharEx(...) As String

Class Stringer

Sunday, June 18, 2000

GetCharEx(bteKeyCode As Byte) As String

Function

Return value

Returns a string, which specifies the char of the assigned btnKeyCode. There are only non DBCS systems supported (only 0 up to 255 = 256 keycodes are supported).

There is no errorhandling implemented in this function.

For keycodes of special controlkeys or enhanced keys, a string is returned, which translates the key to a description for better understanding. Otherwise the standard character is returned.

A character, which is transmittted to the system, depends on the keycode and the current state of the SHIFT or ALT key (pressed or not pressed). So, a keycode must not necessary correspond to the same character as the equal ASCII code.

Example

Dim str As Object
Set str = CreateObject("ntXdll.Stringer")
MsgBox str.GetCharEx(97)
'A msgbox with "NUMPAD_1" is displayed
MsgBox str.GetCharEx(13)
'A msgbox with "ENTER" is displayed
MsgBox str.GetCharEx(112)
'A msgbox with "F1" is displayed


ByteArrayToHexString(...) As String

Class Stringer

Sunday, June 18, 2000

ByteArrayToHexString

(bteArray As Variant, strSeperator As String, intSectionLen As Integer, strLineSeperator As String) As String

Function

Return value

Returns a string, which specifies the HEX values of each byte in the parameter bteArray. This parameter has to be an array of bytes. Otherwise, the function will not work. Each HEX value has the length 2 and is seperated with the character(s) which is (are) specified in parameter strSeperator. Each section has the length, which is specified by parameter intSectionLen and each section is seperated by parameter strLineSeperator.

If an error occurs, the property LastError of this class is set to a nonzero number, which is a VB error number.

See also:

LastError

Example

Dim str As New Stringer
Dim bteA() As Byte
Dim l As Long

For l = 0 To 255

bteA(l) = l

Next

MsgBox str.ByteArrayToHexString(bteA, " ", 8, vbCr)

MsgBox str.LastError


StringToANSIByteArray(...) As Variant

Class Stringer

Sunday, June 18, 2000

StringToANSIByteArray(strString As String) As Variant

Function

Return value

The function converts a string (parameter strString) to an array of bytes (the return value), but only with one byte per character. Normally, if you assign a string to an array of bytes, each character will have two bytes reserved in the array.

If an error occurs, the property LastError of this class is set to a nonzero number, which is a VB error number.

See also:

LastError

Example

Dim str As New Stringer
Dim bteA() As Byte
Dim l As Long

bteA = str.StringToANSIByteArray("[AÄBCDEFGHIJKLMNOÖPQRSTUÜVWXYZ]")

MsgBox str.LastError

For l = 0 To UBound(bteA)

Debug.Print bteA(l)

Next


ReplaceEnvVars(...) As String

Class Stringer

Sunday, June 18, 2000

ReplaceEnvVars(strString As String, strDefault As String) As String

Function

Return value

A modified string. Replaces all in "%" enclosed expressions within the string strString with the environment variables. If the variable doesn't exist, the expression will be replaced by strDefault, if an error occurs, strDefault will be returned by the function.

Example

Dim str As Object, s As String
Set str = CreateObject("ntXdll.Stringer")
s = dll.ReplaceEnvVars ("The path %SystemDrive% is not the same as %SystemRoot%", "Unknown error")
s will have the value "The path C: is not the same as C:\WINNT"


ReplaceString(...) As String

Class Stringer

Sunday, June 18, 2000

ReplaceString

(strString As String, strReplaceString As String, [strToReplace As String], [lngPosition As Long], [lngCaseSens As Long], [lngStart As Long], [lngStop As Long]) As String

Function

Return value

Replaces strings within the string strString by using parameters.

If an error occurs or if you have assigned bad parameters or if there are no matches of strStringToReplace within strString, the unchanged strString will be returned.

There are not yet wildcards like "*" or "?" considered

Parameters

strString
is the string in which to search.

strReplaceString
is the string, which replaces matched strings.

strToReplace
(optional) is the string to search.

lngPosition
(optional) can be one of the properties REPLACE_ALL (all matched strings are replaced) or REPLACE_LAST (the last of the matched strings are replaced) or any value from 1 up to the length of strString. For example, if lngPosition = 2, the second matched string will be replaced.

lngCaseSens
(optional) can be one of the properties CASE_SENSITIVE or NOT_CASE_SENSITIVE (default).

lngStart, lngStop
(optional). If you assign this parameter (lngStart from 1 to the length of strString), the string between this positions will be replaced. If you assign strToReplace, the parameters lngStart and lngStop will be ignored. You have to omitt the parameter strToReplace to assign lngStart and lngStop.

See also:

REPLACE_* Properties
CASE_* Properties

Example

Dim str As Object, s As String
Set str = CreateObject("ntXdll.Stringer")
s = str.ReplaceString("bbbbAa Aabbbbaa aabbbbaa aabbbb", "ccccc", _
"Aa Aa",str.REPLACE_ALL,str.CASE_SENSITIVE)
MsgBox s
s = str.ReplaceString("bbbbaaaabbbbaaaabbbbaaaabbbb","ccc","aaaa",str.REPLACE_LAST)
MsgBox s
s = str.ReplaceString("aaaabbbbaaAabbbbaaAabbbb", "cCc", "aaaa", str.REPLACE_LAST, _ str.NOT_CASE_SENSITIVE)
MsgBox s
s = str.ReplaceString("aaaabbbbaaaabbbbaaaa","ccccc","aaaa",str.REPLACE_LAST)
MsgBox s
s = str.ReplaceString("aaaabbbbaaaabbbbaaaabbbb","ccc","aaaa",2)
MsgBox s
s = str.ReplaceString("123456789","ccccc",,,2,8)
MsgBox s
s = str.ReplaceString("123456789","ccccc",,,-5,12)
MsgBox s


CASE_* Properties

Class Stringer

Sunday, June 18, 2000

CASE_SENSITIVE
NOT_CASE_SENSITIVE

Properties (read only)

Return value

The properties are used like constants in string functions. Look under 'See also'.

See also

ReplaceString (...)

Example

Dim str As Object, l As Long
Set str = CreateObject("ntXdll.Stringer")
l = str.CASE_SENSITIVE


REPLACE_* Properties

Class Stringer

Sunday, June 18, 2000

REPLACE_ALL
REPLACE_LAST

Properties (read only)

Return value

The properties are used like constants in string functions. Look under 'See also'.

See also

ReplaceString (...)

Example

Dim str As Object, l As Long
Set str = CreateObject("ntXdll.Stringer")
l = str.REPLACE_ALL


ReverseString(...) As String

Class Stringer

Sunday, June 18, 2000

ReverseString

(strString As String, strDefault As String, [lngLength As Long]) As String

Function

Return value

Returns the turned over string (case sensitive) from parameter strString. If an error occurs, strDefault will be returned.
If you assign the optional parameter lngLength, the reversion will be executed in steps with this length (lngLength must be higher than 1 and lower than the length of strString). See the examples 2 and 3.

Example1

Dim str As Object, s As String
Set str = CreateObject("ntXdll.Stringer")
s = str.ReverseString("this is the STRING", "Error")
's has the value "GNIRTS eht si siht"

Example2

Dim str As Object, s As String
Set str = CreateObject("ntXdll.Stringer")
s = str.ReverseString("abcdefghi", "Error", 3)
's has the value "ghidefabc"

Example3

Dim str As Object, s As String
Set str = CreateObject("ntXdll.Stringer")
s = str.ReverseString("abcdefghi", "Error", 2)
's has the value "ighefcdab"


InitSeperator(...) As Long

Class Stringer

Sunday, June 18, 2000

InitSeperator

(strString As String, strSeperator As String, [booEmptyStrings As Boolean]) As Long

Function

Return value

Returns 0 if the function succeeds, otherwise a non zero value. The function inits the collection SepStrings , containing the strings, which are seperated by parameter strSeperator in parameter strString. If strString contains no seperator, only this string will be added to the collection. The seperator can be a character, ";" for example or a string of several characters. But it must at least contain one character. If you omitt the optional parameter booEmptyStrings, Empty string are added to the collection, otherwise only strings with len > 0.

See also

SepStrings
SepString

Example1

Dim str As Object, str1 As Object
Set str = CreateObject("ntXdll.Stringer")
Set str1 = CreateObject("ntXdll.Stringer")
Debug.Print str.InitSeperator(";;aaaaa;aaaaa;", ";")
Debug.Print str.SepStrings.Count
For Each str1 In str.SepStrings

Debug.Print str1.SepString

Next

Example2

Dim str As Object, str1 As Object
Set str = CreateObject("ntXdll.Stringer")
Set str1 = CreateObject("ntXdll.Stringer")
Debug.Print str.InitSeperator("aaaaa;;aaaaa;;", ";;", False)
Debug.Print str.SepStrings.Count
For Each str1 In str.SepStrings

Debug.Print str1.SepString

Next


SepStrings As Collection

Class Stringer

Sunday, June 18, 2000

SepStrings As Collection

Property (read only)

Return value

Contains the strings, seperated with a specific seperator you assigned in the function InitSeperator (...). The keys of the elements in the collection are the sign "#" and a number <= SepStrings.Count. At first, you have to execute the function InitSeperator (...) to fill the collection. You can access the elements in the collection over a For Each construct or over the key (see Example2). But you can access any seperated string only over the collection.

See also

InitSeperator
SepString

Example1

Dim str As Object, str1 As Object
Set str = CreateObject("ntXdll.Stringer")
Set str1 = CreateObject("ntXdll.Stringer")
Debug.Print str.InitSeperator(";;aaaaa;aaaaa;", ";")
Debug.Print str.SepStrings.Count
For Each str1 In str.SepStrings

Debug.Print str1.SepString

Next

Example2

Dim str As Object
Set str = CreateObject("ntXdll.Stringer")
Debug.Print str.InitSeperator("aaaaa;;aaaaa;;", ";;", False)
Debug.Print str.SepStrings.Count
Debug.Print str.SepStrings("#3").SepString


SepString As String

Class Stringer

Sunday, June 18, 2000

SepString As String

Property (read only)

Return value

Contains the string which is an member in the collection SepStrings . Look at 'See also' for more information.

See also

InitSeperator
SepStrings

Example1

Dim str As Object, str1 As Object
Set str = CreateObject("ntXdll.Stringer")
Set str1 = CreateObject("ntXdll.Stringer")
Debug.Print str.InitSeperator(";;aaaaa;aaaaa;", ";")
Debug.Print str.SepStrings.Count
For Each str1 In str.SepStrings

Debug.Print str1.SepString

Next

Example2

Dim str As Object
Set str = CreateObject("ntXdll.Stringer")
Debug.Print str.InitSeperator("aaaaa;;aaaaa;;", ";;", False)
Debug.Print str.SepStrings.Count
Debug.Print str.SepStrings("#3").SepString


LastError As Long

Class Stringer

Tuesday, December 05, 2000

LastError As Long

Property (read only)

Return value

The property returns a number, which specifies a VB or an API error. The property is set from some (not all) functions of this class. Where the property is set, is documented in the help of these functions.

Example

Dim str As New Stringer
Dim bteA() As Byte
Dim l As Long

For l = 0 To 255

bteA(l) = l

Next

MsgBox str.ByteArrayToHexString(bteA, " ", 8, vbCr)
MsgBox str.LastError


CBase(...) As String

Class DllClass

Saturday, June 17, 2000

Class DllClass

This class offers functions and properties, which are not categorized and for which are no special class is planed yet. Please look at the help of each function to get detailed information. The most of the function names inform you about, for which purpose you can use the function.


GetLicence(...) As String

Class DllClass

Monday, December 11, 2000

GetLicence

([strLineSeperator As String = "|"]) As String

Function

Return value

Returns the licence string according to the ntXdll software on your machine. Unregistered versions return 'Demo'.

Parameters

strLineSeperator (optional)
specifies, how the different parts of the licence string (owner, type, licence number and so on) are seperated. If you omitt the parameters, the parts are seperated by '|'.

Example (early binding)

Dim dll
Set dll = CreateObject("ntXdll.DllClass")

MsgBox dll.GetLicence(vbCrLf)


CBase(...) As String

Class DllClass

Saturday, June 17, 2000

CBase(lngNumber As Long, lngBase As Long, lngLen As Long, strDefault As String) As String

Function

Return value

Returns the converted number of lngNumber on the base of lngBase. The return value is a string. If the len of the string would be shorter than lngLen, the returned string will be filled up with zeros on the left side. If an error occurs, strDefault will be returned. lngBase can be up to 36. A value of 16 for example means conversion to Hex.

See also

CBaseToNum

Example1

Dim dll As Object, s As String
Set dll = CreateObject("ntXdll.DllClass")
s = dll.CBase(12, 16, 3, "Unknown error")
's will have the value "00C"

Example2

Dim dll As Object, s As String
Set dll = CreateObject("ntXdll.DllClass")
s = dll.CBase(25, 2, 8, "Unknown error")
's will have the value "00001101"


CBaseToNum(...) As Long

Class DllClass

Saturday, December 09, 2000

CBaseToNum(strBaseStr As String, strBase As String) As Double

Function

Return value

Returns the number converted from a string, which contains a number to the base strBase. strBase can be one of the letters from "0" up to "Z". "F" for example means a conversion from a Hex number, "7" a conversion from Oct or "1" a conversion from binary. Remember, that only positive numbers are converted. The letters in strBaseStr can't be higher than the letter strBase. If an error occurs or if invalid parameters assigned, a negative number will be returned.

See also

CBase

Examples

Dim dll As Object, d As Double
Set dll = CreateObject("ntXdll.DllClass")
d = dll.CBaseToNum("FF", "F")
' d will have the value 255
d = dll.CBaseToNum("1234567", "7")
' d will have the value 342391
d = dll.CBaseToNum("1001101", "1")
' d will have the value 77
d = dll.CBaseToNum("AHKVW", "Z")
' d will have the value 17616380


SysTimeToTzLocTime(...) As Date

Class DllClass

Saturday, June 17, 2000

SysTimeToTzLocTime(dteDateTime As Date) As Date

Function

Return value

The function converts a Coordinated Universal Time (UTC) to a specified time zone's corresponding local time. The only parameter dteDateTime is the DateTime to convert. The DateTime string must be in the regional specific format. Otherwise the function can not interpret the parameter. The difference from UTC to local time depends on the bias.

See also:

GetBias()

Example

Dim dll As Object
Set dll = CreateObject("ntXdll.DllClass")
MsgBox dll.SysTimeToTzLocTime("12/31/1999 23:59:59")
MsgBox dll.SysTimeToTzLocTime("31.12.1999 23:59:59")


FileTimeToDateTime(...) As Date

Class DllClass

Saturday, June 17, 2000

FileTimeToDateTime(lngLowDateTime As Long, lngHighDateTime As Long) As Date

Function

Return value

Returns the date which is corresponding to a FILETIME structure. The FILETIME structure is in the form of

Type FILETIME

dwLowDateTime As Long
dwHighDateTime As Long

End Type

The function converts this type to a datetime type. If an error occurs, the date 01/01/1900 will be returned.

Parameters

lngLowDateTime
corresponds to the member dwLowDateTime of the FILETIME structure

lngHighDateTime
corresponds to the member dwHighDateTime of the FILETIME structure

See also

FileTimeToLocFileTime

Example

Dim reg As New DllClass
Dim dteDate as Date
Dim ft As FILETIME

'now the code which modifies the ft variable...

dteDate = FileTimeToDateTime(ft.dwLowDateTime, ft.dwHighDateTime)


FileTimeToLocFileTime(...) as Date

Class DllClass

Saturday, June 17, 2000

FileTimeToLocFileTime(dteDateTime As Date) As Date

Function

Return value

The function converts a time based on the Coordinated Universal Time (UTC) to a local file time. The time to convert must not necessary be a filetime but the name of the function leans against an API function.

The function uses the current settings for the time zone and daylight saving time. Therefore, if it is daylight saving time, this function will take daylight saving time into account, even if the time you are converting is in standard time.

If an error occurs, the date 01/01/1900 will be returned.

See also:

FileTimeToDateTime

Example:

Dim reg As New DllClass
Dim dteDate as Date
Dim dteConverted as Date

'now the code which modifies the dteDate variable...

dteConverted = FileTimeToLocFileTime(dteDate)


GetBias() As Long

Class DllClass

Saturday, June 17, 2000

GetBias() As Long

Function

Return value

Returns the current bias, in minutes, for local time translation on the local computer. The bias is the difference, in minutes, between Coordinated Universal Time (UTC) and local time. All translations between UTC and local time are based on the following formula:

UTC = local time + bias

so, if you want to get the local time from UTC, translate with

local time = UTC - bias

See also

SysTimeToTzLocTime(...)

Example

Dim dll as New DllClass
MsgBox dll.GetBias


FormatAPIMessage(...) As String

Class DllClass

Tuesday, December 05, 2000

FormatAPIMessage

(lngNumber As Long, [strDefault As String], [strMsgFile As String], [lngLangID As Long]) As String

Function

Return value

Returns the error description of the error number lngNumber fom an API error. The function formates the message before it returns the string. All double vbCrLf will be replaced by a single vbLf and all vbCrLf are replaced by a vbLf. The leading vbCrLf will be deleted. If the errorID is unknown or in the case that the function doesn't work, strDefault is returned. Some messages from the system use parameters like '%1', '%2' a.s.o. In this case, you can replace these parameters with strings with the function ReplaceString of the Class String because the usage of a parameter array is not supported. In this case, you can attempt to take these parameters and pass them through the function again and then insert the returned strings in the original message.

FormatAPIMessage looks for a message for languages in the following order:

  1. Language neutral
  2. Thread language, based on the thread's locale value
  3. User default language, based on the user's default locale value
  4. System default language, based on the system default locale value
  5. US English

Parameters

lngNumber
the error number you want want to get the description from.

strDefault (optional)
is returned if the errorID is unknown or in the case that the function doesn't work. If you omitt the parameter, "unknown" is returned.

strMsgFile (optional)
you can assign another MessageFile, 'rasmsg.dll' for example. If you omitt this parameter, the normal WIN32 system messages are returned.

lngLangID (optional)
you can specify another language if this language is supported. For example, &H407 is German, &H409 is US English. If the lanuage is'nt supported, an error (strDefault) is returned. If you omitt this parameter, see the following remarks:

See also

ReplaceString

Example

Dim dll As Object, s As String
Set dll = CreateObject("ntXdll.DllClass")
s = dll.FormatAPIMessage(5, "Unknown error")
's will have the value "Access denied"


GetCryptedString(...) As String

Class DllClass

Saturday, June 17, 2000

GetCryptedString(strString As String, strDefault As String) As String

Function

Return value

Encrypts the string strString with an easy algorythm. If the function failes, the Parameter strDefault will returned.

See also:

GetDecryptedString (...)

Example

Dim dll As Object
Dim s As String
Set dll = CreateObject("ntXdll.DllClass")
s = dll.GetCryptedString("This secret should be coded", "This string will be returned on an error")
MsgBox s


GetDecryptedString(...) As String

Class DllClass

Saturday, June 17, 2000

GetDecryptedString(strString As String, strDefault As String) As String

Function

Return value

Decrypts the strString with the easy algorythm of the function GetCryptedString . If the function failes, the Parameter strDefault will returned.

See also:

GetCryptedString (...)

Example

Dim dll As Object
Dim c As String, d As String
Set dll = CreateObject("ntXdll.DllClass")
c = dll.GetCryptedString("This secret should be coded", "This string will be returned on an error")
MsgBox c
d = dll.GetDecryptedString(c, "This string will be returned on an error")
MsgBox d


GetDomSID(...) As String

Class DllClass

Saturday, June 17, 2000

GetDomSID(strMachine As String, strObject As String, strDefault As String) As String

Property (read only)

Return value

Returns the SID of an object strObject in the domain of the Computer strMachine. If the property failes, the Parameter strDefault will returned.

Example

Dim dll As Object
Dim sid As String
Set dll = CreateObject("ntXdll.DllClass")
sid = dll.GetDomSID("PDCName", "UserXY", "This string will be returned on an error")
MsgBox sid


GetDomSIDArray(...) As Variant

Class DllClass

Wednesday, November 21, 2001

GetDomSIDArray

(strMachine As String,
strObject As String)

As Variant

Property (read only)

Return value

Returns an array of long values which represents a SID of an object strObject in the domain of the Computer strMachine. If the property failes, the property LastError of this class will be set to an error number. This can be a VB or an API error.

The property is probably only usefull for programmers, who want to get a pointer to a SID in an easy way (see the example). Normal administrators, who want to get a SID in textual form, should use property GetDomSID of this class.

See also:

LastError
GetDomSID

Example (early binding)

Dim dll As New DllClass, SidBuffer() As Long, pSID As Long

SidBuffer = dll.GetDomSIDArray("ComputerName", "AccountName")
'get the pointer to the sid:
pSID = VarPtr(SidBuffer(0))


GetDomName(...) As String

Class DllClass

Monday, December 11, 2000

GetDomName

(strMachine As String, strSID As String, strDefault As String) As String

Function

Return value

Returns the name of an account according to a textual SID. SIDs have a textual format like 'S-1-5-21-6217631-7183289371-1045'. Each account on a machine has a unique SID (Security Identifier).

In case of an error, the parameter strDefault will be returned. In addition, the property LastError of this class is set to a nonzero number, if an error occurs. This can be a VB or an API error.

If you want to get the textual SID according to an account, use function GetDomSID of this class.

Parameters

strMachine
specifies the machine where you want to search for the account name. You have to specify a machine (without backslashs '\\') because otherwise the function would have to search on each machine in a domain or workgroup.

strSID
specifies the textual SID to which the account referres.

strDefault
specifies the value which is returned on an error.

See also

LastError
GetDomSID

Example (early binding)

Dim dll As New DllClass
MsgBox = dll.GetDomName("TheComputer", "S-1-5-21-6651623-2734627-2345", "Error)


GetLocalIP(...) As Long

Class DllClass

Saturday, June 17, 2000

GetLocalIP(strDefault As String) As String

Function

Return value

Returns the IP Address of the local machine in the Format 255.255.255.255. If the function failes, the Parameter strDefault will returned.

Example

Dim dll As Object
Dim tcp As String
Set dll = CreateObject("ntXdll.DllClass")
tcp = dll.GetLocalIP("This string will
    be returned on an error")
MsgBox tcp


GetMacAddress(...) As String

Class DllClass

Saturday, June 17, 2000

GetMacAddress(strDefault) As String

Function

Return value

Returns the adapter address of the local machine in the Format XX-XX-XX-XX-XX-XX. If the function failes, the Parameter strDefault will returned.

Example

Dim dll As Object
Dim mac As String
Set dll = CreateObject("ntXdll.DllClass")
mac = dll.GetMacAddress("This string
    will be returned on an error")
MsgBox mac


GetRasConnections(...) As Long

Class DllClass

Saturday, June 17, 2000

GetRasConnections

(lngEntries As Variant, lngTotalEntries As Variant, strName As Variant) As Long

Function

Return value

The function modifies its parameters. If lngTotalEntries RAS connections are active, lngEntries increments from 1 to lngTotalEntries by every call of the function and strName is the Name of the current connection. The function returns Zero on success and Non Zero on Fail.

Example 1

Dim dll As Object
Dim lngEntries As Long, lngTotalEntries As Long, strName As
    String
Dim lngResult As Long
Set dll = CreateObject("ntXdll.DllClass")
lngEntries = 0
lngTotalEntries = 0
strName = ""
Do

lngResult = dll.GetRasConnections(lngEntries, lngTotalEntries, strName)

If lngResult = 0 Then

If lngEntries > 0 Then

MsgBox CStr(lngEntries) & " of " & CStr( lngTotalEntries) & _" RAS connections: " & strName

End If

Else

MsgBox "Error"

End If

Until lngEntries = lngTotalEntries

Example 2

Dim dll As Object
Dim lngEntries As Long, lngTotalEntries As Long, strName As
    String
Dim lngResult As Long
Set dll = CreateObject("ntXdll.DllClass")
lngEntries = 0
lngTotalEntries = 0
strName = ""
lngResult = dll.GetRasConnections(lngEntries,
    lngTotalEntries, strName)
If lngEntries > 0 Then

MsgBox "You have logged on over RAS"

End If


ShowNetConnectionDialog(...) As Long

Class DllClass

Saturday, June 17, 2000

ShowNetConnectionDialog(lngType As Long) As Long

Function

Return value

Shows the NT dialog to connect a network drive. The function returns Zero on success, otherwise NonZero. For the parameter lngType, you can use the property RESOURCETYPE_DISK .

The other RESOURCETYPE_* Properties will not work under WINNT.

See also:

RESOURCETYPE_* Properties
ShowNetDisconnectDialog (...)

Example

Dim dll As Object, ret As Long
Set dll = CreateObject("ntXdll.DllClass")
ret = dll.ShowNetConnectionDialog(dll.RESOURCETYPE_DISK)


ShowNetDisconnectDialog(...) As Long

Class DllClass

Saturday, June 17, 2000

ShowNetDisconnectDialog(lngType As Long) As Long

Function

Return value

Shows the NT dialog to disconnect a network drive. The function returns Zero on success, otherwise NonZero. For the parameter lngType, you can use the property RESOURCETYPE_DISK .

The other RESOURCETYPE_* Properties will not work under WINNT.

See also:

RESOURCETYPE_DISK, RESOURCETYPE_ANY, RESOURCETYPE_PRINT, RESOURCETYPE_RESERVED, RESOURCETYPE_UNKNOWN
ShowNetConnectionDialog (...)

Example

Dim dll As Object, ret As Long
Set dll = CreateObject("ntXdll.DllClass")
ret = dll.ShowNetDisconnectDialog(dll.RESOURCETYPE_DISK)


ShowPrinterConnectionDialog() As Long

Class DllClass

Wednesday, January 03, 2001

ShowPrinterConnectionDialog() As Long

Function

Return value

Returns 0 in case of success, otherwise a nonzero value. This value can be a VB or an API error. Also, in case of clicking on the CANCEL button on the dialog, a nonzero value is returned. The function shows the system dialog, which is used to connect to shared network printers.

Example (early binding)

Dim dll As New DllClass
Dim l As Long

l = dll.ShowPrinterConnectionDialog

If l <> 0 Then

MsgBox CStr(l)

End If


RESOURCETYPE_* Properties

Class DllClass

Saturday, June 17, 2000

RESOURCETYPE_DISK
RESOURCETYPE_ANY
RESOURCETYPE_PRINT
RESOURCETYPE_RESERVED
RESOURCETYPE_UNKNOWN

Properties (read only)

Return value

The properties are used in NT functions to access resources.

See also:

ShowNetConnectionDialog (...)
 ShowNetDisconnectDialog (...)

Example

Dim dll As Object, l As Long
Set dll = CreateObject("ntXdll.DllClass")
l = dll.RESOURCETYPE_DISK


ShowPropertyDialog(...)

Class DllClass

Saturday, June 17, 2000

ShowPropertyDialog(strObjectPath As String)

Sub

Return value

Shows the NT dialog of the properties of an object. No return value.

Example

Dim dll As Object
Set dll = CreateObject("ntXdll.DllClass")
dll.ShowPropertyDialog("c:\winnt\win.ini")


ShowMessage(...)

Class DllClass

Saturday, June 17, 2000

ShowMessage

([strCaption As String], [strFont As String], [strForeColorRGB As String], [lngFontSize As Long], [booBold As Boolean], [strAlignment As String], [strText As String])

Sub

Return value

Shows a message in the center of the screen. All parameters are optional.

The sub doesn't work in scripts, only in applications yet.

The Parameter strFont must be a existing Font in the system. The parameter strAlignment can be "Center", "Right", or "Left". Calling the sub severeral times with other parameters will change the existing message.

See also:

UnloadMessage

Example

Dim dll As Object
Set dll = CreateObject("ntXdll.DllClass")
dll.ShowMessage "Caption", "Arial", "255,0,0", 16, , "Center", "My Text" & vbCrLf & "New Line"


UnloadMessage

Class DllClass

Saturday, June 17, 2000

UnloadMessage

Sub

Return value

No returns. The sub unloads the message, created by the sub ShowMessage (...)

See also:

ShowMessage (...)

Example

Dim dll As Object
Set dll = CreateObject("ntXdll.DllClass")
dll.UnloadMessage


SystemDefaultLCID As Long

Class DllClass

Saturday, June 17, 2000

SystemDefaultLCID As Long

Property (Read only)

Return value

Returns the systems locale identifier. In case on an error, 0 will be returned. The identifier supplied in an LCID is a standard international numeric abbreviation. This LCID has the components necessary to uniquely identify one of the installed system-defined locales. For example, us english is identified by Hex 0x0409.

See also:

UserDefaultLCID

Example

Dim dll As Object
Set dll = CreateObject("ntXdll.DllClass")
Debug.Print dll.SystemDefaultLCID


UserDefaultLCID

Class DllClass

Tuesday, December 05, 2000

UserDefaultLCID

Property (Read only)

Return value

Returns the users locale identifier. In case on an error, 0 will be returned. The identifier supplied in an LCID is a standard international numeric abbreviation. This LCID has the components necessary to uniquely identify one of the installed system-defined locales. For example, us english is identified by Hex 0x0409.

See also:

SystemDefaultLCID

Example

Dim dll As Object
Set dll = CreateObject("ntXdll.DllClass")
Debug.Print dll.UserDefaultLCID


Sleeping(...)

Class DllClass

Saturday, June 17, 2000

Sleeping(lngMilliSeconds As Long)

Sub

Return value

Returns no value. The method pauses a process for the with parameter lngMilliSeconds specified time. There is no errorhandling implemented in this sub.

Example

Dim dll As Object
Set dll = CreateObject("ntXdll.DllClass")
'Let the process sleep for 3 seconds
dll.Sleeping 3000


PlaySound(...) As Long

Class DllClass

Wednesday, January 03, 2001

PlaySound

(strPath As String, [lngFrom As Long], [lngTo As Long]) As Long

Function

Return value

Returns 0 on success, otherwise an error number. This can be a VB or an API error. The function plays a sound if a waveaudio device is installed on your system

Parameters

strPath (String)
the path of the audio file to play (*.wav for example are audio files)

lngFrom (Long, optional)
the position where the sound is to play from. The position must be less then the end position.

lngTo (Long, optional)
the position up to this the song is to play.

Example (early binding)

Dim dll As New DllClass
Dim sPath As String

sPath = "c:\winntsrv\media\Jungle Windows.WAV"

MsgBox dll.PlaySound(sPath, , 20000)


EndWindows(...) As Long

Class DllClass

Friday, January 12, 2001

EndWindows

([strMachine As String], [strMessage As String], [lngTimeOut As Long = 20], [booForce As Boolean = False], [booReboot As Boolean = False]) As Long

Function

Return value

Returns 0 in case of success, otherwise a nonzero value. This can be a VB or an API error . The function shuts down a local or remote machine with different options. If you only want to log off from a machine, use function EndWindowsLocal of this class.

Parameters

strMachine (optional)
specifies the machine to shutdown. If you omitt the parameter, the local machine is used. If you specifiy a machine name, do not use leading backslashs ('\\').

strMessage (optional)
specifies the message, which appears lngTimeOut seconds before the shutdown. If you omitt the parameter, no message appears. If you omitt lngTimeOut, no message appears.

lngTimeOut (optional)
specifies the time in seconds that remains until the machine shuts down. If you omitt the parameter, the machine shuts down immediately.

booForce (optional)
boolean value that specifies, whether application should be forced to close before the shutdown. If the value is True, application data can be lost. If you omitt the parameter, False is the default value.

booReboot (optional)
boolean value that specifies, whether the machine reboots after the shutdown. If you omitt the parameter, False is the default value. Then, the machine shows the NT message, that you can power off the computer.

See also

EndWindowsLocal

Example (late binding)

Dim dll As Object
Set dll = CreateObject("ntXdll.DllClass")
MsgBox = dll.EndWindows("TheComputer",
    "The system will shut down in 10 seconds!", 10)


EndWindowsLocal(...) As Long

Class DllClass

Friday, January 12, 2001

EndWindowsLocal

(strHow As String, [booForce As Boolean = False]) As Long

Function

Return value

Returns 0 in case of success, otherwise a nonzero value. This can be a VB or an API error . The function exists windows on the local machine with different options. If you want to shut down a remote machine, use function EndWindows of this class.

Parameters

strHow
specifies how the machine is to shut down. Specify one of the following strings (not case sensitive):

"LOGOFF"
"REBOOT"
"SHUTDOWN" (without reboot)
"POWEROFF" (this option must be supported from the hardware)

booForce (optional)
boolean value that specifies, whether application should be forced to close before the shutdown. If the value is True, application data can be lost. If you omitt the parameter, False is the default value.

See also

EndWindows

Example (late binding)

Dim dll As Object
Set dll = CreateObject("ntXdll.DllClass")
MsgBox = dll.EndWindowsLocal("LOGOFF",
    True)


IAmAdmin(...) As Boolean

Class DllClass

Monday, December 11, 2000

IAmAdmin () As Boolean

Function

Return value

Returns whether the current user has admin privileges on the local machine. This function cannot be used on remote machines. If any error occurs inside the function code, the property LastError of this class is set to a nonzero value. This can be a VB or an API error.

No Parameters

See also

LastError

Example (early binding)

Dim dll As New DllClass
If dll.IAmAdmin Then

MsgBox "Yes, I am Admin"

End If


LastError As Long

Class DllClass

Monday, December 11, 2000

LastError As Long

Property

Return value

Common property of this class, which is set from different functions and Properties. The property returns 0 in case of success, otherwise a nonzero value. This value can be a VB or an API error. It is documented in the help of each function which uses LastError.

Example (early binding)

Dim dll As New DllClass
Dim b As Boolean

b = dll.IAmAdmin

If dll.LastError = 0 Then

If b Then

MsgBox "Yes, I am Admin"

End If

Else

MsgBox "Error: " & CStr(dll.LastError)

End If


Class Sharer

Tuesday, January 15, 2002

Class Sharer

This class uses Win32 API functions to query or set share properties on the local or a remote system and needs Windows NT® 4.0 Service Pack 4 or higher.

To query or set share properties, you have to initialize Sharer objects at first. Function GetShareInfo initializes a single Sharer object, which represents a single share on the local or a remote computer. After executing the function without error, you have a Valid Sharer object. You can access the properties of the requested share through the object instance, you called the function GetShareInfo from.

Function InitShares initializes a collection Shares , which represents all shares on the local or a remote computer. After executing the function without error, all collection members are Valid Sharer objects. You can access the properties of the requested shares only through the object instances of the collection members.

You can change share properties by assigning a value of the right type to the property (syntax: <sharer object>.<property> = <value>). You only can change properties within a Valid Sharer object (except the properties, which are needed to create a new share with function Create ). This means, that you have to initialize a Sharer object with the functions above.

If you want to change a property of a single share, you should initialize only a single object with function GetShareInfo . Otherwise, you would have to run through all collection members with a search criteria until you find the right share.

In this version of ntXdll, you only can change the following properties (alphabetical order):

Computer
ShMaxUses
ShName
ShPassword
ShPath
ShPermissions
ShRemark
ShType

With function InitShareRights , you get a collection ShareRights . The members of this collection contain information about the access rights of a share. You have to execute the function InitShareRights within a Valid Sharer object.

There are some additional functions, which you can use seperate and which require no Valid Sharer objects. These functions are:

Create
RemoveShare
NetUse
NetUseDel

You get detailed information in the help of each function or property.


GetShareInfo(...) As Long

Class Sharer

Sunday, January 14, 2001

GetShareInfo

(strComputer As String, strShare As String) As Long

Function

Return value

Returns 0 in case of success, otherwise a nonzero value. This value can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

The function initializes the properties of a Sharer object. This means that the properties of a Sharer object instance, through which you call this function are filled with the properties of a share, you want to query. After executing the function without error, the object instance, you call the function from, is a Valid Sharer object.

To initialize the properties of multiple shares on a machine, use the function InitShares of this class.

You have to call this function (or InitShares for multiple shares or Create for new shares) before you want modifiy properties of shares.

Parameters

strComputer
specifies the name of the computer where the share exists from which you want to get the informations. Do not use leading backslashs ('\\'). If you use an empty string (""), the local machine is used.

strShare
specifies the name of the share from which you want to get the informations. You cannot use an empty string.

See also

InitShares
Create
Valid
FormatAPIMessage

Example (late binding)

Dim shr, dll
Dim lRes

Set shr = CreateObject("ntXdll.Sharer")
Set dll = CreateObject("ntXdll.DllClass")

lRes = shr.GetShareInfo("PDCName", "NETLOGON")

If lRes <> 0 Or shr.Valid = False Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Exit Sub

End If

MsgBox shr.ShPath
MsgBox shr.ShTypeStr
MsgBox shr.ShMaxUses
MsgBox shr.ShCurUses


InitShares(...) As Long

Class Sharer

Monday, January 08, 2001

InitShares (strMachine As String) As Long

Function

Return value

Returns 0 in case of success, otherwise a nonzero value. This value can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

The function initializes the collection Shares of a Sharer object and all of it's properties. This means that the properties of each member of this collection, which represents a share on a local or remote machine, are filled with information and each member of the collection should be a Valid Sharer object.

All collection members are indexed with the name of the share (property ShName of this class). You can access the properties of the collection members over the 'For Each ...' construct (example 1) or directly over the index (example 2).

All actions on the Sharer objects (setting or receiving values of properties of the object) must be done within the object instances of the collection members (example 3).

To initialize the properties of only one share on a machine, use the function GetShareInfo of this class.

You have to call this function (or GetShareInfo for only one share or Create for new shares) before you want modifiy properties of shares.

Parameters

strMachine
specifies the name of the computer, where you want to get the shares from. Do not use leading backslashs ('\\'). If you use an empty string (""), the local machine is used.

See also

Shares
GetShareInfo
Create
Valid
ShName
FormatAPIMessage

Example1 (late binding)

Dim shr, shrMember, dll, lRes

Set shr = CreateObject("ntXdll.Sharer")
Set dll = CreateObject("ntXdll.DllClass")
lRes = shr.InitShares("Machine")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Exit Sub

End If

If lRes = 0 Then

For Each shrMember In shr.Shares

MsgBox shrMember.ShName

Next

Else

MsgBox "Error could not get info of shares"

End If

Set shr = Nothing

Example2 (late binding)

Dim shr, dll, lRes

Set shr = CreateObject("ntXdll.Sharer")
Set dll = CreateObject("ntXdll.DllClass")
lRes = shr.InitShares("Machine")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
GoTo exit_sub

End If

If lRes = 0 Then

MsgBox shr.Shares("TestShare").ShPath

End If

Example3 (modifying share properties, late binding)

Dim shr, shrMember, dll, lRes

Set shr = CreateObject("ntXdll.Sharer")
Set dll = CreateObject("ntXdll.DllClass")

lRes = shr.InitShares("Machine")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
GoTo exit_sub

End If

If lRes = 0 Then

For Each shrMember In shr.Shares

If shrMember.Valid Then

shrMember.ShMaxUses = 115
If shrMember.LastError <> 0 Then MsgBox "Error changing ShMaxUses"

End If

Next

Else

MsgBox "Error could not get info of shares"

End If

Set shr = Nothing

exit_sub:


InitShareRights() As Long

Class Sharer

Monday, January 08, 2001

InitShareRights () As Long

Function

Return value

Returns 0 in case of success, otherwise a nonzero value. This value can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

The function initializes the collection ShareRights of a Sharer object and all of it's properties. This means that the properties of each member of this collection, which represents the access rights to a share on a local or remote machine, are filled with information. The collection members of ShareRights are Sharer objects, but not all of the properties of this class are initialized (only the ShRight* properties - look section 'See also').

All collection members are indexed with <domainname>\<username> or <username> if the domainname is empty (group 'Everyone' for example). You can access the properties of the collection members over the 'For Each ...' construct or directly over the index.

The function has no parameters because you only can call this function within a parent Valid Sharer object. You get Valid Sharer objects with functions GetShareInfo , InitShares or Create of this class.

See also

ShareRights
Valid
GetShareInfo
InitShares
Create
ShRightDomain
ShRightUser
ShRightTypeStr
ShRightStr
FormatAPIMessage

Example (late binding)

Dim shr, shrRight, dll
Dim lRes, s

Set shr = CreateObject("ntXdll.Sharer")
Set dll = CreateObject("ntXdll.DllClass")

lRes = shr.GetShareInfo("PDCName", "NETLOGON")

If lRes <> 0 Or shr.Valid = False Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Exit Sub

End If

lRes = shr.InitShareRights()

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Exit Sub

End If

For Each shrRight In shr.ShareRights

If shrRight.ShRightTypeStr = "ACCESS_ALLOWED_ACE_TYPE" Then

s = "User " & shrRight.ShRightDomain & "\" & shrRight.ShRightUser
s = s & " has the following access rights: "
s = s & shrRight.ShRightStr & " to share " & shr.ShName

Else

s = "Access is denied for " & shrRight.ShRightDomain & "\" & shrRight.ShRightUser
s = s & " to share " & shr.ShName

End If

MsgBox s

Next


Create() As Long

Class Sharer

Friday, January 12, 2001

Create() As Long

Function

Return value

Returns 0 in case of success, otherwise a nonzero value. This value can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

The function creates a new share on a local or remote machine or server. It has no parameters because you have to set some properties of a Sharer object before you can call the function. You have to call the function within the object instance, in which you have set these properties.

The following properties are supported when you create a user:

ShName | you must set this property
ShPath | you must set this property. Specifies the local path for the shared resource. For disks, ShPath is the path being shared. For print queues, ShPath is the name of the print queue being shared.
Computer | default: empty string (the local computer). The target computer where the share is to be created
ShRemark | default: empty string. An optional comment to the shared resource.
ShType | default: 0 that means a disk resource. Use the SHTYPE_* properties to specify this parameter.
ShMaxUses | default: -1, that means MAX_USES_UNLIMITED . The property indicates the maximum number of concurrent connections that the shared resource can accommodate.
ShPermissions | default: 0. Use the ACCESS_* properties to assign this value
ShPassword | default: empty string.

After creating the user without error, the rest of the properties of the Sharer object in which you called the functions, are filled with information and you have a Valid Sharer object.

See also

ShName
ShPath
Computer
ShRemark
ShType
ShMaxUses
ShPermissions
ShPassword
SHTYPE_*
MAX_USES_UNLIMITED
ACCESS_*
Valid
FormatAPIMessage

Example (late binding)

Dim shr, dll, lRes

Set shr = CreateObject("ntXdll.Sharer")
Set dll = CreateObject("ntXdll.DllClass")

shr.Computer = "TheComputerNameWithoutBackSlashs"
shr.ShName = "Private$"
shr.ShPath = "d:\private"
shr.ShRemark = "New Remark"
shr.ShMaxUses = 25

lRes = shr.Create

If lRes <> 0 Or shr.Valid = False Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

Set shr = Nothing


RemoveShare(...) As Long

Class Sharer

Friday, January 12, 2001

RemoveShare

(strComputer As String, strShare As String)

Function

Return value

Returns 0 in case of success, otherwise a nonzero value. This value can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

The function removes a share on a local or remote computer. The function doesn't delete the directory on which the share is based. You should always remove a share before you decide to delete a shared directory.

Parameters

strComputer
specifies the name of the computer where the share exists. Do not use leading backslashs ('\\'). If you use an empty string (""), the local machine is used.

strShare
specifies the name of the share to remove. You cannot use an empty string.

See also

FormatAPIMessage

Example (late binding)

Dim shr, dll, lRes

Set shr = CreateObject("ntXdll.Sharer")
Set dll = CreateObject("ntXdll.DllClass")

lRes = shr.RemoveShare("ComputerName", "TestShare$")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

Set shr = Nothing


NetUse(...) As Long

Class Sharer

Thursday, January 11, 2001

NetUse

(strLocal As String, strRemote As String, [strUser As String], [strPassword As String], [booRemember As Boolean = True]) As Long

Function

Return value

Returns 0 in case of success, otherwise a nonzero value. This value can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

The function connects to a network resource or redirects a local device to a network resource. The user, you connect to the resource with, has to have enough access privileges to the remote resource.

Parameters

strLocal
specifies the local device, the function has to redirect to the network resource (for example "E:" or "LPT5:" for connections to shared printers). If the string is empty, the function only connects to the resource without redirecting a local device. If strLocal is "*" and strRemote specifies a share, which is a directory or a disk, the first unused drive letter beginning with "D:" is used.

strRemote
specifies the remote resource, which can be a disk share, a shared printer or a special share like IPC$. Use UNC convention to specify the parameter.

strUser, strPassword (optional)
specify the username and password with which the function has to make the connection. If you omitt the parameters, the current user is used.

booRemember (optional)
specifies whether the connection should be stored in the users profile. In this case, the connection will be restored on the next logon. The value True is the default if you omitt the parameter. The system will only attempt to restore redirect local devices.

Remarks

To disconnect a network connection, use function NetUseDel of this class.

See also

NetUseDel
FormatAPIMessage

Example1 (early binding)

Dim shr As New Sharer
Dim lRes As Long, dll As New DllClass

lRes = shr.NetUse("z:", "\\ServerName\Share", "DomainName\UserName", "Password")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes)), "netmsg.dll")

End If

Example2 (early binding)

Dim shr As New Sharer
Dim lRes As Long, dll As New DllClass

lRes = shr.NetUse("lpt5:", "\\ServerName\SharedPrinter")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes)), "netmsg.dll")

End If

Example3 (early binding)

Dim shr As New Sharer
Dim lRes As Long, dll As New DllClass

lRes = shr.NetUse("*", "\\ServerName\Share", , , False)

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes)), "netmsg.dll")

End If

Example4 (early binding)

Dim shr As New Sharer
Dim lRes As Long, dll As New DllClass

lRes = shr.NetUse("", "\\ServerName\IPC$")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes)), "netmsg.dll")

End If


NetUseDel(...) As Long

Class Sharer

Friday, January 12, 2001

NetUseDel

(strLocal As String, [booForce As Boolean = False], [booRemember As Boolean = True]) As Long

Function

Return value

Returns 0 in case of success, otherwise a nonzero value. This value can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

The function cancels remembered or unremembered connections to a network resource.

Parameters

strLocal
specifies the local device or the remote resource, the function has to disconnect from (for example "E:" or "LPT5:" for connections to shared printers or an UNC path to a connected resource). The string cannot be empty.

booForce (optional)
specifies whether the function should cancel a connection even if the user has open files or jobs on the connection. If you omitt the parameter, the function failes in these cases.

booRemember (optional)
specifies whether the disconnection should be stored in the users profile. In this case, the connection will no longer be restored on the next logon. The value True is the default if you omitt the parameter.

Remarks

To establish a network connection, use function NetUse of this class.

See also

NetUse
FormatAPIMessage

Example (early binding)

Dim shr As New Sharer
Dim lRes As Long, dll As New DllClass

lRes = shr.NetUseDel("z:", True, False)

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes)), "netmsg.dll")

End If


Properties of Sharer

Class Sharer

Saturday, January 13, 2001

The properties of class Sharer

Some properties of this class are read only, some can be set by assigning a value. Some of the properties, which are not read only, can only be set within non Valid Sharer objects in order to create a new share with function Create .

If any error occurs by setting properties, property LastError of this class returns an error number. But LastError will not return an error, if you try to set properties which require a non Valid Sharer object within a Valid Sharer object. So you have to proove property Valid at first in these cases.


Shares As Collection

Class Sharer

Friday, January 12, 2001

Shares As Collection

Property (read only)

Return value

Returns a collection of Sharer objects. It is initialized with function InitShares of this class. The collection represents the shares on a local or remote computer. All collection members should be Valid Sharer objects. All actions on the Sharer objects (setting or receiving properties of the object) must be done within the object instances of the collection members.

All collection members are indexed with the name of the share (property ShName ). You can access the properties of the collection members over the 'For Each ...' construct (example 1) or directly over the index (example 2).

See also

InitShares
Valid
ShName

Example1 (late binding)

Dim shr, shrMember, dll, lRes

Set shr = CreateObject("ntXdll.Sharer")
Set dll = CreateObject("ntXdll.DllClass")
lRes = shr.InitShares("Machine")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Exit Sub

End If

If lRes = 0 Then

For Each shrMember In shr.Shares

MsgBox shrMember.ShName

Next

Else

MsgBox "Error could not get info of shares"

End If

Set shr = Nothing

Example2 (late binding)

Dim shr, dll, lRes

Set shr = CreateObject("ntXdll.Sharer")
Set dll = CreateObject("ntXdll.DllClass")
lRes = shr.InitShares("Machine")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
GoTo exit_sub

End If

If lRes = 0 Then

MsgBox shr.Shares("TestShare").ShPath

End If


Computer As String

Class Sharer

Friday, January 12, 2001

Computer As String

Property

Return value

Returns (example 1) or sets the computername of a Sharer object (do not use leading backslashs '\\'). This is the name of the computer, where the resource exists. You only can set this property, if the Sharer object is not valid (property Valid of this class), for example, if you want to create a new share with function Create of this class (example 2).

To get the property, you have to init the properties of a Sharer object at first with functions GetShareInfo or InitShares of this class.

See also

GetShareInfo
InitShares
Create
Valid

Example1 (query the property from one object, early binding)

Dim shr As New Sharer
Dim lRes As Long

lRes = shr.GetShareInfo("Computername", "NameOfShare")

If lRes = 0 Then

MsgBox shr.Computer

End If

Example2 (setting the property, late binding)

Dim shr, dll, lRes

Set shr = CreateObject("ntXdll.Sharer")
Set dll = CreateObject("ntXdll.DllClass")

shr.Computer
    = "TheComputerNameWithoutBackSlashs"
shr.ShName = "Private$"
shr.ShPath = "d:\private"
shr.ShRemark = "New Remark"
shr.ShMaxUses = 25

lRes = shr.Create

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set shr = Nothing


ShName As String

Class Sharer

Saturday, January 13, 2001

ShName As Long

Property

Return value

Returns or sets the name of a share on a local or remote computer. You only can get ShName within a Valid Sharer object. You get Valid Sharer objects with functions GetShareInfo , InitShares or Create of this class. Note, that names with a trailing dollar sign ('$') are hidden and not visble within the explorer.

You can set this property only within a non Valid (new) Sharer object in order to create a new share with function Create (example 2). To change the name of an existing share, you have to remove the share with function RemoveShare of this class and then to create a new with function Create .

To get the property for multiple shares, initialize the objects with function InitShares of this class.

See also

Valid
GetShareInfo
InitShares
Create
RemoveShare

Example1 (late binding)

Dim shr, lRes

Set shr = CreateObject("ntXdll.Sharer")
lRes = shr.GetShareInfo("ComputerName", "TestShare$")

If lRes = 0 And shr.Valid Then

MsgBox shr.ShName

Else

MsgBox "Error could not get share info"

End If

Set shr = Nothing

Example2 (late binding)

Dim shr, dll, lRes

Set shr = CreateObject("ntXdll.Sharer")
Set dll = CreateObject("ntXdll.DllClass")

shr.Computer = "TheComputerNameWithoutBackSlashs"
shr.ShName = "Private$"
shr.ShPath = "d:\private"
shr.ShRemark = "New Remark"
shr.ShMaxUses = 25

lRes = shr.Create

If lRes <> 0 Or shr.Valid = False Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

Set shr = Nothing


ShPath As String

Class Sharer

Saturday, January 13, 2001

ShPath As String

Property

Return value

Returns or sets the local path of a share on a local or remote computer. For print queues, the property is the name of the print queue which is shared.

You only can get ShPath within a Valid Sharer object. You get Valid Sharer objects with functions GetShareInfo , InitShares or Create of this class.

You can set this property only within a non Valid (new) Sharer object in order to create a new share with function Create (example 2). You cannot change the path of an existing shared resource.

To get the property for multiple shares, initialize the objects with function InitShares of this class.

See also

Valid
GetShareInfo
InitShares
Create

Example1 (late binding)

Dim shr, lRes

Set shr = CreateObject("ntXdll.Sharer")
lRes = shr.GetShareInfo("ComputerName", "TestShare$")

If lRes = 0 And shr.Valid Then

MsgBox shr.ShPath

Else

MsgBox "Error could not get share info"

End If

Set shr = Nothing

Example2 (late binding)

Dim shr, dll, lRes

Set shr = CreateObject("ntXdll.Sharer")
Set dll = CreateObject("ntXdll.DllClass")

shr.Computer = "TheComputerNameWithoutBackSlashs"
shr.ShName = "Private$"
shr.ShPath = "d:\private"
shr.ShRemark = "New Remark"
shr.ShMaxUses = 25

lRes = shr.Create

If lRes <> 0 Or shr.Valid = False Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

Set shr = Nothing


ShRemark As String

Class Sharer

Saturday, January 13, 2001

ShRemark As String

Property

Return value

Returns or sets an optional comment associated to a share on a local or remote computer. You only can get ShRemark within a Valid Sharer object. You get Valid Sharer objects with functions GetShareInfo , InitShares or Create of this class.

You can set this property in a Valid Sharer object in order to modifiy the property (example 2). You get Valid Sharer objects with functions GetShareInfo , InitShares or Create of this class. If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

You also can set this property within a non Valid (new) Sharer object in order to create a new share with function Create (example 3).

To get or set the property for multiple shares, initialize the objects with function InitShares of this class.

See also

Valid
GetShareInfo
InitShares
Create
LastError
FormatAPIMessage

Example1 (late binding)

Dim shr, lRes

Set shr = CreateObject("ntXdll.Sharer")
lRes = shr.GetShareInfo("ComputerName", "TestShare$")

If lRes = 0 And shr.Valid Then

MsgBox shr.ShRemark

Else

MsgBox "Error could not get share info"

End If

Set shr = Nothing

Example2 (late binding)

Dim shr, lRes

Set shr = CreateObject("ntXdll.Sharer")
lRes = shr.GetShareInfo("ComputerName", "TestShare$")

If lRes = 0 And shr.Valid Then

shr.ShRemark = "New comment"

Else

MsgBox "Error could not get share info"

End If

lRes = shr.LastError
If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

Set shr = Nothing

Example3 (late binding)

Dim shr, dll, lRes

Set shr = CreateObject("ntXdll.Sharer")
Set dll = CreateObject("ntXdll.DllClass")

shr.Computer = "TheComputerNameWithoutBackSlashs"
shr.ShName = "Private$"
shr.ShPath = "d:\private"
shr.ShRemark = "my hidden private share"
shr.ShMaxUses = 25

lRes = shr.Create

If lRes <> 0 Or shr.Valid = False Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

Set shr = Nothing


ShType As Long

Class Sharer

Saturday, January 13, 2001

ShType As Long

Property

Return value

Returns or sets the type of a share on a local or remote computer. Use the STYPE_* properties to set the right values or to determine, what the returned values mean.

You only can get ShType within a Valid Sharer object. You get Valid Sharer objects with functions GetShareInfo , InitShares or Create of this class.

You can set this property only within a non Valid (new) Sharer object in order to create a new share with function Create (example 2). You cannot change the type of an existing shared resource. If you don't set the property before creating a new share, the default STYPE_DISKTREE is used.

To get the property for multiple shares, initialize the objects with function InitShares of this class.

Remarks

to get the type of a share in textual form, use the read only property ShTypeStr of this class.

See also

Valid
GetShareInfo
InitShares
Create
STYPE_* properties
 ShTypeStr

Example1 (late binding)

Dim shr, lRes

Set shr = CreateObject("ntXdll.Sharer")
lRes = shr.GetShareInfo("ComputerName", "TestShare$")

If lRes = 0 And shr.Valid Then

MsgBox shr.ShType

Else

MsgBox "Error could not get share info"

End If

Set shr = Nothing

Example2 (late binding)

Dim shr, dll, lRes

Set shr = CreateObject("ntXdll.Sharer")
Set dll = CreateObject("ntXdll.DllClass")

shr.Computer = "TheComputerNameWithoutBackSlashs"
shr.ShName = "Private$"
shr.ShPath = "d:\private"
shr.ShRemark = "New Remark"
shr.ShType = shr.STYPE_DISKTREE
shr.ShMaxUses = 25

lRes = shr.Create

If lRes <> 0 Or shr.Valid = False Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

Set shr = Nothing


STYPE_* properties

Class Sharer

Saturday, January 13, 2001

STYPE_DISKTREE
STYPE_PRINTQ
STYPE_IPC
STYPE_DEVICE
STYPE_SPECIAL

As Long

Properties (read only)

Return value

The properties are used like constants to get or set the property ShType of this class. For further informations, read the help to this property.

The meanings:

STYPE_DISKTREE
a share which is a disk or a directory on a disk

STYPE_PRINTQ
a print queue (a shared printer)

STYPE_IPC
Interprocess communication

STYPE_DEVICE
a communication device

STYPE_SPECIAL
a special share reserved for interprocess communication (IPC$) or remote administration of the server (ADMIN$). Can also refer to administrative shares such as C$

See also

ShType

Example (early binding)

Dim shr, lRes

Set shr = CreateObject("ntXdll.Sharer")
lRes = shr.GetShareInfo("ComputerName", "PrinterForAll")

If lRes = 0 And shr.Valid Then

If shr.ShType = shr.STYPE_PRINTQ Then

MsgBox "The share is a print queue"

End If

Else

MsgBox "Error could not get share info or no valid share"

End If

Set shr = Nothing


ShTypeStr As String

Class Sharer

Saturday, January 13, 2001

ShTypeStr As String

Property (read only)

Return value

Returns the type of a share on a local or remote computer in textual form. The property returns a string which represents the property ShType of this class. The property contains one of the following strings:

'STYPE_DISKTREE'
'STYPE_PRINTQ'
'STYPE_IPC'
'STYPE_DEVICE'
'STYPE_SPECIAL'

You can get this property only in a Valid Sharer object. You get Valid Sharer objects with functions GetShareInfo , InitShares or Create of this class.

To get the property for multiple shares, initialize the objects with function InitShares of this class.

Remarks

To set the type of a share, use property ShType of this class.

See also

Valid
GetShareInfo
InitShares
Create
ShType
STYPE_* properties

Example (late binding)

Dim shr, lRes

Set shr = CreateObject("ntXdll.Sharer")
lRes = shr.GetShareInfo("ComputerName", "TestShare$")

If lRes = 0 And shr.Valid Then

MsgBox shr.ShTypeStr

Else

MsgBox "Error could not get share info"

End If

Set shr = Nothing


ShCurUses As Long

Class Sharer

Saturday, January 13, 2001

ShCurUses As Long

Property (read only)

Return value

Returns the number of current connections to a share. You only can get ShCurUses within a Valid Sharer object. You get Valid Sharer objects with functions GetShareInfo , InitShares or Create of this class.

To get the property for multiple shares, initialize the objects with function InitShares of this class.

See also

Valid
GetShareInfo
InitShares
Create

Example (late binding)

Dim shr, lRes

Set shr = CreateObject("ntXdll.Sharer")
lRes = shr.GetShareInfo("ComputerName", "TestShare$")

If lRes = 0 And shr.Valid Then

MsgBox shr.ShCurUses

Else

MsgBox "Error could not get share info"

End If

Set shr = Nothing


ShMaxUses As Long

Class Sharer

Saturday, January 13, 2001

ShMaxUses As Long

Property

Return value

Returns or sets the maximum number of allowed concurrent connections to a share. Use property MAX_USES_UNLIMITED to get or set unlimited connections.

You only can get ShMaxUses within a Valid Sharer object. You get Valid Sharer objects with functions GetShareInfo , InitShares or Create of this class.

You can set this property in a Valid Sharer object in order to modifiy the property (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

You also can set this property within a non Valid (new) Sharer object in order to create a new share with function Create (example 3).

To get or set the property for multiple shares, initialize the objects with function InitShares of this class.

See also

MAX_USES_UNLIMITED
Valid
GetShareInfo
InitShares
Create
LastError
FormatAPIMessage

Example1 (late binding)

Dim shr, lRes

Set shr = CreateObject("ntXdll.Sharer")
lRes = shr.GetShareInfo("ComputerName", "TestShare$")

If lRes = 0 And shr.Valid Then

MsgBox shr.ShMaxUses

Else

MsgBox "Error could not get share info"

End If

Set shr = Nothing

Example2 (late binding)

Dim shr, lRes

Set shr = CreateObject("ntXdll.Sharer")
lRes = shr.GetShareInfo("ComputerName", "TestShare$")

If lRes = 0 And shr.Valid Then

shr.ShMaxUses = 150

Else

MsgBox "Error could not get share info"

End If

lRes = shr.LastError
If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

Set shr = Nothing

Example3 (late binding)

Dim shr, dll, lRes

Set shr = CreateObject("ntXdll.Sharer")
Set dll = CreateObject("ntXdll.DllClass")

shr.Computer = "TheComputerNameWithoutBackSlashs"
shr.ShName = "Private$"
shr.ShPath = "d:\private"
shr.ShRemark = "New Remark"
shr.ShMaxUses = 25

lRes = shr.Create

If lRes <> 0 Or shr.Valid = False Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

Set shr = Nothing


MAX_USES_UNLIMITED As Long

Class Sharer

Thursday, January 11, 2001

MAX_USES_UNLIMITED

As Long

Property (read only)

Return value

The property is used like a constant to get the unlimited number of concurrent connections, which is returned or can be set by property ShMaxUses of this class. For further informations, read the help to this property.

The meaning:

MAX_USES_UNLIMITED
the value is -1 and means that there is no limit of concurrent connections to the share which is represented by a Valid Sharer object.

See also

ShMaxUses
Valid

Example (early binding)

Dim shr As New Sharer, dll As New DllClass
Dim lRes As Long

lRes = shr.GetShareInfo("", "user")

If lRes <> 0 Or shr.Valid = False Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Exit Sub

End If

shr.ShMaxUses = MAX_USES_UNLIMITED


ShDFSFlag As Long

Class Sharer

Saturday, January 13, 2001

ShDFSFlag As Long

Property (read only)

Return value

Returns, whether a share is a (root) volume in a Dfs tree structure or not. If there is no DFS flag set on the share, the value is 0 (zero). Use the FLAGS_* properties of this class, to determine, which flag is set.

You only can get ShDFSFlag within a Valid Sharer object. You get Valid Sharer objects with functions GetShareInfo , InitShares or Create of this class.

To get the property for multiple shares, initialize the objects with function InitShares of this class.

See also

FLAGS_* properties
 Valid
GetShareInfo
InitShares
Create

Example (late binding)

Dim shr, lRes

Set shr = CreateObject("ntXdll.Sharer")
lRes = shr.GetShareInfo("ComputerName", "TestShare$")

If lRes = 0 And shr.Valid Then

If shr.ShDFSFlag = shr.FLAGS_DFS_ROOT Then

MsgBox "The share is a root volume in a Dfs tree structure"

End If

Else

MsgBox "Error could not get share info"

End If

Set shr = Nothing


FLAGS_* properties

Class Sharer

Monday, January 08, 2001

FLAGS_DFS
FLAGS_DFS_ROOT

As Long

Properties (read only)

Return value

The properties are used like constants to get the property ShDFSFlag of this class. For further informations, read the help to this property.

The meanings:

FLAGS_DFS
the share is a volume in a Dfs tree structure.

FLAGS_DFS_ROOT
the share is a root volume in a Dfs tree structure.

See also

ShDFSFlag

Example (early binding)

Dim shr As New Sharer, dll As New DllClass
Dim lRes As Long

lRes = shr.GetShareInfo("", "user")

If lRes <> 0 Or shr.Valid = False Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Exit Sub

End If

If shr.ShDFSFlag = FLAGS_DFS_ROOT Then

MsgBox "The share is a root volume in a Dfs tree structure"

End If


ShPermissions As Long

Class Sharer

Saturday, January 13, 2001

ShPermissions As Long

Property

Return value

Returns or sets the permissions which are set on a share on a local or remote computer. This property is not used on servers which are not running share level security (servers which are running user level security). Use the ACCESS_* properties to get or set the right values to the property. You can assign any of the ACCESS_* properties to ShPermissions can contain any of the ACCESS_* properties or 0 (zero), if no permissions are set.

You can set this property in a Valid Sharer object in order to modifiy the property (example 2). You get Valid Sharer objects with functions GetShareInfo , InitShares or Create of this class. If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

You also can set this property within a non Valid (new) Sharer object in order to create a new share with function Create (example 3).

To get or set the property for multiple shares, initialize the objects with function InitShares of this class.

Remarks

To read the permissions in textual form, use property ShPermissionsStr of this class.

See also

Valid
GetShareInfo
InitShares
Create
LastError
FormatAPIMessage
ACCESS_* properties
 ShPermissionsStr
ShPassword

Example1 (late binding)

Dim shr, lRes

Set shr = CreateObject("ntXdll.Sharer")
lRes = shr.GetShareInfo("ComputerName", "TestShare$")

If lRes = 0 And shr.Valid Then

MsgBox shr.ShPermissions

Else

MsgBox "Error could not get share info"

End If

Set shr = Nothing

Example2 (late binding)

Dim shr, lRes

Set shr = CreateObject("ntXdll.Sharer")
lRes = shr.GetShareInfo("ComputerName", "TestShare$")

If lRes = 0 And shr.Valid Then

shr.ShPermissions = shr.ACCESS_READ Or shr.ACCESS_WRITE

Else

MsgBox "Error could not get share info"

End If

lRes = shr.LastError
If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

Set shr = Nothing

Example3 (late binding)

Dim shr, dll, lRes

Set shr = CreateObject("ntXdll.Sharer")
Set dll = CreateObject("ntXdll.DllClass")

shr.Computer = "TheComputerNameWithoutBackSlashs"
shr.ShName = "Private$"
shr.ShPath = "d:\private"
shr.ShRemark = "New Remark"
shr.ShMaxUses = 25
shr.ShPermissions = shr.ACCESS_EXEC
shr.ShPassword = "12345678"

lRes = shr.Create

If lRes <> 0 Or shr.Valid = False Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

Set shr = Nothing


ShPermissionsStr As String

Class Sharer

Saturday, January 13, 2001

ShPermissionsStr As String

Property (read only)

Return value

Returns the permissions in textual form which are set to a share on a local or remote computer. The property returns a string which represents the property ShPermissions of this class. The property contains any of the following strings, seperated by a semicolon or an empty string, if no permissions are set on the share:

'ACCESS_ALL'
'ACCESS_READ'
'ACCESS_WRITE'
'ACCESS_CREATE'
'ACCESS_DELETE'
'ACCESS_EXEC'
'ACCESS_PERM'
'ACCESS_ATRIB'

You can get this property only in a Valid Sharer object. You get Valid Sharer objects with functions GetShareInfo , InitShares or Create of this class.

To get the property for multiple shares, initialize the objects with function InitShares of this class.

Remarks

To set the permissions on a share, use property ShPermissions of this class.

See also

Valid
GetShareInfo
InitShares
Create
ShPermissions
ACCESS_* properties
 ShPassword

Example (late binding)

Dim shr, lRes

Set shr = CreateObject("ntXdll.Sharer")
lRes = shr.GetShareInfo("ComputerName", "TestShare$")

If lRes = 0 And shr.Valid Then

MsgBox shr.ShPermissionsStr

Else

MsgBox "Error could not get share info"

End If

Set shr = Nothing


ShPassword As String

Class Sharer

Saturday, January 13, 2001

ShPassword As String

Property

Return value

Returns or sets the password which is set on a share on a local or remote computer. This property is not used on servers which are not running share level security (this are servers which are running user level security). The property allways returns "********" because the password can only be set and not be displayed.

You can set this property in a Valid Sharer object in order to modifiy the property (example 2). You get Valid Sharer objects with functions GetShareInfo , InitShares or Create of this class. If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

You also can set this property within a non Valid (new) Sharer object in order to create a new share with function Create (example 3).

The password cannot be longer than 8 characters.

To get or set the property for multiple shares, initialize the objects with function InitShares of this class.

See also

Valid
GetShareInfo
InitShares
Create
LastError
FormatAPIMessage
ShPermissions

Example1 (late binding)

Dim shr, lRes

Set shr = CreateObject("ntXdll.Sharer")
lRes = shr.GetShareInfo("ComputerName", "TestShare$")

If lRes = 0 And shr.Valid Then

MsgBox shr.ShPassword

Else

MsgBox "Error could not get share info"

End If

Set shr = Nothing

Example2 (late binding)

Dim shr, lRes

Set shr = CreateObject("ntXdll.Sharer")
lRes = shr.GetShareInfo("ComputerName", "TestShare$")

If lRes = 0 And shr.Valid Then

shr.ShPassword = "4g!x&9j"

Else

MsgBox "Error could not get share info"

End If

lRes = shr.LastError
If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

Set shr = Nothing

Example3 (late binding)

Dim shr, dll, lRes

Set shr = CreateObject("ntXdll.Sharer")
Set dll = CreateObject("ntXdll.DllClass")

shr.Computer = "TheComputerNameWithoutBackSlashs"
shr.ShName = "Private$"
shr.ShPath = "d:\private"
shr.ShRemark = "New Remark"
shr.ShMaxUses = 25
shr.ShPassword = "12345678"

lRes = shr.Create

If lRes <> 0 Or shr.Valid = False Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

Set shr = Nothing


ACCESS_* properties

Class Sharer

Monday, January 08, 2001

ACCESS_ALL
ACCESS_READ
ACCESS_WRITE
ACCESS_CREATE
ACCESS_DELETE
ACCESS_EXEC
ACCESS_ATRIB
ACCESS_PERM

As Long

Properties (read only)

Return value

The properties are used like constants to get or set the property ShPermissions of this class. For further informations, read the help to this property.

The meanings:

ACCESS_ALL
all permissions

ACCESS_READ
permission to read data from a resource and, by default, to execute the resource.

ACCESS_WRITE
permission to write data to the resource.

ACCESS_CREATE
permission to create an instance of the resource (such as a file); data can be written to the resource as the resource is created.

ACCESS_DELETE
permission to delete the resource.

ACCESS_EXEC
permission to execute within the resource.

ACCESS_ATRIB
permission to modify the resource's attributes (for example the date and time when a file was last modified).

ACCESS_PERM
permission to modify the permissions (read, write, create, execute, and delete) assigned to a resource for a user or application.

See also

ShPermissions

Example (early binding)

Dim shr As New Sharer, dll As New DllClass
Dim lRes As Long

lRes = shr.GetShareInfo("", "user")

If lRes <> 0 Or shr.Valid = False Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Exit Sub

End If

shr.ShPermissions = shr.ACCESS_CREATE

lRes = shr.LastError

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Exit Sub

End If


ShareRights As Collection

Class Sharer

Friday, January 12, 2001

ShareRights As Collection

Property (read only)

Return value

Returns a collection of Sharer objects. It is initialized with function InitShareRights of this class. The collection represents the access rights on a share which is represented by a Valid Sharer object. This means, the collection can only be created within such object.

The members of the collection do not have all properties filled with information. Only the ShRight* properties

ShRightUser
ShRightDomain
ShRightTypeStr
ShRightStr

contain information.

All collection members are indexed with <domainname>\<username> or <username> if property ShRightDomain is empty. You can access the properties of the collection members over the 'For Each ...' construct (example 1) or directly over the index (example 2).

See also

InitShareRights
Valid
ShRightUser
ShRightDomain
ShRightTypeStr
ShRightStr

Example1 (late binding)

Dim shr, shrRight, dll
Dim lRes, s

Set shr = CreateObject("ntXdll.Sharer")
Set dll = CreateObject("ntXdll.DllClass")

lRes = shr.GetShareInfo("PDCName", "NETLOGON")

If lRes <> 0 Or shr.Valid = False Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Exit Sub

End If

lRes = shr.InitShareRights()

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Exit Sub

End If

For Each shrRight In shr.ShareRights

If shrRight.ShRightTypeStr = "ACCESS_ALLOWED_ACE_TYPE" Then

s = "User " & shrRight.ShRightDomain & "\" & shrRight.ShRightUser
s = s & " has the following access rights: "
s = s & shrRight.ShRightStr & " to share " & shr.ShName

Else

s = "Access is denied for " & shrRight.ShRightDomain & "\" & shrRight.ShRightUser
s = s & " to share " & shr.ShName

End If

MsgBox s

Next

Example2 (late binding)

Dim shr, shrRight, dll
Dim lRes, s

Set shr = CreateObject("ntXdll.Sharer")
Set dll = CreateObject("ntXdll.DllClass")

lRes = shr.GetShareInfo("PDCName", "NETLOGON")

If lRes <> 0 Or shr.Valid = False Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Exit Sub

End If

lRes = shr.InitShareRights()

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Exit Sub

End If

If shr.ShareRights("MyDomain\TestUser").ShRightTypeStr = "ACCESS_ALLOWED_ACE_TYPE" Then

s = "User MyDomain\TestUser has the following access rights: "
s = s & shr.ShareRights("MyDomain\TestUser").ShRightStr & " to share " & shr.ShName

Else

s = "Access is denied for MyDomain\TestUser to share " & shr.ShName

End If

MsgBox s


ShRightDomain As String

Class Sharer

Saturday, January 13, 2001

ShRightDomain As String

Property (read only)

Return value

Returns the domain of a user or group who has access rights defined on a share which is represented by a parent Sharer object. The property can only be accessed over a member object of collection ShareRights . This collection is initialized through the function InitShareRights which can only be executed within a Valid Sharer object. This Valid Sharer object is the parent object for the collection.

You get Valid Sharer objects with functions GetShareInfo , InitShares or Create of this class.

See also

ShareRights
InitShareRights
Valid
GetShareInfo
InitShares
Create
ShRightUser
ShRightTypeStr
ShRightStr

Example (late binding)

Read the example in the help to function InitShareRights


ShRightUser As String

Class Sharer

Saturday, January 13, 2001

ShRightUser As String

Property (read only)

Return value

Returns the user or group who has access rights defined on a share which is represented by a parent Sharer object. The property can only be accessed through a member of collection ShareRights . This collection is initialized through the function InitShareRights which can only be executed within a Valid Sharer object. This Valid Sharer object is the parent object for the collection.

You get Valid Sharer objects with functions GetShareInfo , InitShares or Create of this class.

See also

ShareRights
InitShareRights
Valid
GetShareInfo
InitShares
Create
ShRightDomain
ShRightTypeStr
ShRightStr

Example (late binding)

Read the example in the help to function InitShareRights


ShRightTypeStr As String

Class Sharer

Saturday, January 13, 2001

ShRightTypeStr As String

Property (read only)

Return value

Returns the type of access of a user or group who has access rights defined on a share, which is represented by a parent Sharer object. The property can only be accessed through a member of collection ShareRights . This collection is initialized through the function InitShareRights which can only be executed within a Valid Sharer object. This Valid Sharer object is the parent object for the collection.

You get Valid Sharer objects with functions GetShareInfo , InitShares or Create of this class.

ShRightTypeStr can be one of the following strings:

'ACCESS_ALLOWED_ACE_TYPE'
'ACCESS_DENIED_ACE_TYPE'

See also

ShareRights
InitShareRights
Valid
GetShareInfo
InitShares
Create
ShRightDomain
ShRightUser
ShRightStr

Example (late binding)

Read the example in the help to function InitShareRights


ShRightStr As String

Class Sharer

Saturday, January 13, 2001

ShRightStr As String

Property (read only)

Return value

Returns the access rights of a user or group who has access rights defined on a share, which is represented by a parent Sharer object. The property can only be accessed through a member of collection ShareRights . This collection is initialized through the function InitShareRights which can only be executed within a Valid Sharer object. This Valid Sharer object is the parent object for the collection.

You get Valid Sharer objects with functions GetShareInfo , InitShares or Create of this class.

Dependend on the type of the share (properties ShType and ShTypeStr of this class), ShRightStr contains different strings. If the share is a print queue, ShRightStr can be one of the following strings:

'FULL'
'MANAGE DOCUMENTS'
'PRINT'
'ZERO' (if access is denied to the specified user or group).

Otherwise, ShRightStr can be any combination of the following characters (or it can be the string 'FULL', 'CHANGE', 'READ' or 'ZERO' if access is denied to the specified user or group):

'R' | the right to read the share
'W' | the right to write to the share
'X' | the right to execute within the share
'D' | the right to delete the share
'P' | the right to set permissions on the share
'O' | the right to take ownership

See also

ShareRights
InitShareRights
Valid
GetShareInfo
InitShares
Create
ShRightDomain
ShRightUser
ShRightTypeStr

Example (late binding)

Read the example in the help to function InitShareRights


Valid As Boolean

Class Sharer

Saturday, January 13, 2001

Valid As Boolean

Property (read only)

Return value

Returns whether a Sharer object represents an existing share on a local or remote computer.

To get the property, you have to init the properties of a Sharer object at first with functions GetShareInfo (example 1) or InitShares (example 2) of this class. If you have executed this functions without error, all properties of the Sharer objects are filled with information and all of these objects represent existing shares. You also get a Valid Sharer object by creating a new share with function Create of this class.

See also

GetShareInfo
InitShares
Create
Shares

Example1 (late binding)

Dim shr, lRes

Set shr = CreateObject("ntXdll.Sharer")
lRes = shr.GetShareInfo("ComputerName", "TestShare$")

If lRes = 0 And shr.Valid Then

MsgBox "TestShare$ is a valid share"

Else

MsgBox "Error could not get share info or no valid share"

End If

Set shr = Nothing

Example2 (late binding)

Dim shr, shrMember, lRes

Set shr = CreateObject("ntXdll.Sharer")
lRes = shr.InitShares("Machine")

If lRes = 0 Then

For Each shrMember In shr.Shares

MsgBox shrMember.Valid

Next

Else

MsgBox "Error could not get info from shares"

End If

Set shr = Nothing


LastError As Long

Class Sharer

Thursday, January 11, 2001

LastError As Long

Property (read only)

Return value

The property returns an error number which is set by different functions and properties of this class. A value of 0 means no error. Otherwise the error number can be a VB or an API error. It is documented in the help of the methods which set this property. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

See also

FormatAPIMessage

Example (late binding)

Dim shr, dll, lRes

Set shr = CreateObject("ntXdll.Sharer")
Set dll = CreateObject("ntXdll.DllClass")
lRes = shr.GetShareInfo("Machine", "TestShare")

If lRes = 0 And shr.Valid Then

shr.Remark = "Comment for TestShare"

End If

lRes = shr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set shr = Nothing


Class UserManager

Tuesday, January 15, 2002

Class UserManager

This class uses Win32 network API to query or set properties of users on the local or a remote system and needs Windows NT® 4.0 Service Pack 4 or higher. You can use the class for properties on workstations and servers (domains) as well.

To query or set user properties, you have to initialize UserManager objects at first. Function GetUserInfo initializes a single UserManager object, which represents a single user on the local or a remote computer. After executing the function without error, you have a Valid UserManager object. You can access the properties of the requested user through the object instance, you called the function GetUserInfo from.

Function InitUsers initializes a collection Users , which represents all users on the local or a remote computer. You can specify a group in this function. Then, the collection contains only the users, which are members of the group.

After executing the function without error, all collection members are Valid UserManager objects. You can access the properties of the requested users only through the object instances of the collection members.

With function GetSeparateInfos , you can initialize these properties of a UserManager object, which are sparately strored on each domain controller (property LastLogon for example). You can call this function only within a Valid UserManager object.

You can change user properties by assigning a value of the right type to the property (syntax: <usermanager object>.<property> = <value>). You only can change properties within a Valid UserManager object. This means, that you have to initialize a UserManager object with the functions above.

If you want to change a property of a single user, you should initialize only a single object with function GetUserInfo . Otherwise, you would have to run through all collection members with a search criteria until you find the right user. Please read the help to each property to determine, whether the property can be set or whether it is read only.

Some of these properties, you can change only within non Valid UserManager objects in order to create a new user with function Create .

There are some additional functions, which you can use seperate and which you can use within non Valid UserManager objects. These functions are:

Create
DeleteUser
GetCurrentUser

You get detailed information in the help of each function or property.


GetUserInfo(...) As Long

Class UserManager

Monday, January 08, 2001

GetUserInfo

(strUserName As String, [strComputer As String], [booHoursBinary As Boolean = True]) As Long

Function

Return value

Returns 0 in case of success, otherwise a nonzero value. This value can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

The function initializes the properties of a UserManager object. This means that the properties of a UserManager object instance, through which you call this function are filled with the properties of a user account, you want to query. After executing the function without error, the object instance, you call the function from, is a Valid UserManager object.

To initialize the properties of multiple users on a machine, use the function InitUsers of this class.

You have to call this function (or InitUsers for multiple users or Create for new users) before you want modifiy properties of users.

If you want to initialize only these properties which can be different on each domain controller (DC), call function GetSeparateInfos of this class.

Parameters

strUserName
specifies the name of the user, you want to get the infos from. For computer account, add a trailing dollar sign ('$') to the name

strComputer (optional)
specifies the name of the computer where the users exists from which you want to get the infos. Do not use leading backslashs ('\\'). If you omitt the parameter, the local machine is used.

booHoursBinary (optional)
if you set this parameter to True (this is the default value, if you omitt the parameter), the LogonHours* properties are returned as binary coded strings, otherwise in the format 'H-H;H-H;...' for example '5-14;16-20'.

See also

InitUsers
Create
Valid
LogonHours*
GetSeparateInfos
FormatAPIMessage

Example (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("TestUserName", "ComputerName")

If lRes = 0 And usr.Valid Then

MsgBox usr.UserName
MsgBox usr.Comment
MsgBox usr.Description
MsgBox usr.FullName

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing


InitUsers(...) As Long

Class UserManager

Monday, January 08, 2001

InitUsers

([strComputer As String], [lngFilter As Long = 2], [strGroup As String], [booHoursBinary As Boolean = True]) As Long

Function

Return value

Returns 0 in case of success, otherwise a nonzero value. This value can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

The function initializes the collection Users of a UserManager object and all of it's properties. This means that the properties of each member of this collection, which represents a user on a local or remote machine, are filled with information.

You can filter the members of the collection when you assign the different parameters. Not all members of the collection must be Valid UserManager objects. Because if you assign strGroup as parameter for example, the collection members are members of a local or global group. It is possible to add local and global (domain) users to a local group on a machine, which is no domain controller (DC). But not all properties of the domain users are stored in the account database on this non DC machine. So only the properties

UserName
DomainName
Computer

of these non valid members are initialized in the collection. To get the rest of the properties (to get Valid objects), you must execute InitUsers on the DC where this accounts are stored (parameter strComputer).

All collection members are indexed with <domainname>\<username> or <username> if the domainname is empty (group 'Everyone' for example). You can access the properties of the collection members over the 'For Each ...' construct (example 1) or directly over the index (example 2).

All actions on the UserManager objects (setting or receiving values of properties of the object) must be done within the object instances of the collection members (example 3).

To initialize the properties of only one user on a machine, use the function GetUserInfo of this class.

You have to call this function (or GetUserInfo for only one user or Create for new users) before you want modifiy properties of user accounts.

If you want to get only the properties of the collection members, which can be different on each DC, call function GetSeparateInfos of this class. You have to call this function within the object instances of the collection members.

Parameters

strComputer (optional)
specifies the name of the computer, where you want to get the users from. If you omitt this parameter, the local machine is used. Do not use leading backslashs ('\\').

lngFilter (optional)
use the FILTER_* properties to assign this paramter so that only users with the specified account type are members of the collection. The default is FILTER_NORMAL_ACCOUNT.

strGroup (optional)
specifies the name of a group, from which you want to get the user members from (all users on the specified computer, which are members of this group). If you omitt this parameter, all users on the computer are returned.

booHoursBinary (optional)
if you set this parameter to True (this is the default value, if you omitt the parameter), the LogonHours* properties of all collection members are returned as binary coded strings, otherwise in the format 'H-H;H-H;...' for example '5-14;16-20'.

See also

Users
GetUserInfo
Create
Valid
FILTER_*
LogonHours*
GetSeparateInfos
FormatAPIMessage

Example1 (late binding)

Dim usr, usrMember, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.InitUsers("Machine")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Exit Sub

End If

If lRes = 0 Then

For Each usrMember In usr.Users

MsgBox usrMember.UserName

Next

Else

MsgBox "Error could not get info of users"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.InitUsers("Machine")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
GoTo exit_sub

End If

If lRes = 0 Then

MsgBox usr.Users("MyDomain\UserName").UserFullName

End If

Example3 (modifying user properties, late binding)

Dim usr, usrMember, dll, lRes, sLH

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")

sLH = "000000000000000000000000" & _
"000000111111111111000000" & _
"000000111111111111000000" & _
"000000111111111111000000" & _
"000000111111111111000000" & _
"000000111111111111000000" & _
"000000000000000000000000"

lRes = usr.InitUsers("Machine")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
GoTo exit_sub

End If

If lRes = 0 Then

For Each usrMember In usr.Users

If usrMember.Valid Then

usrMember.LogonHours = sLH
If usrMember.LastError <> 0 Then MsgBox "Error changing LogonHours"

End If

Next

Else

MsgBox "Error could not get info of users"

End If

Set usr = Nothing


GetSeparateInfos(...) As Long

Class UserManager

Sunday, December 31, 2000

GetSeparateInfos

(strComputer As String, [booSynchronize As Boolean = True]) As Long

Function

Return value

Returns 0 in case of success, otherwise a nonzero value. This value can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass.

The function initializes only the properties of a Valid UserManager object which are different on each domain controller. These properties are

BadPasswordCount
LastLogoff
LastLogon
NumLogons

You must call the function within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

The function will only work with UserManager objects, which represent domain accounts (not for example accounts that exist on a workstation).

Parameters

strComputer
specifies the name of the computer where the account exists. This should be a domain controller. Do not use leading backslashs ('\\').

booSynchronize (optional)
if this parameter is True (default), the function synchronizes the old values of the properties with the new values. The properties NumLogons and BadPasswordCount will be counted up and the values of LastLogoff and LastLogon will be replaced by the latest values. If the parameter is False, the values will always be replaced.

See also

GetUserInfo
InitUsers
Create
Valid
FormatAPIMessage

Example (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "PDCName")

If lRes = 0 And usr.Valid Then

'get the properties on the backup domain controller
lRes = usr.GetSeparateInfos("BDCName", True)

If lRes = 0 Then

MsgBox usr.BadPasswordCount
MsgBox usr.LastLogoff
MsgBox usr.LastLogon
MsgBox usr.NumLogons

Else

MsgBox "Error could not get user info from BDC"

End If

Else

MsgBox "Error could not get user info from PDC"

End If

Set usr = Nothing


Create() As Long

Class UserManager

Thursday December 28, 2000

Create() As Long

Function

Return value

Returns 0 in case of success, otherwise a nonzero value. This value can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

The function creates a new account on a local or remote machine or server. It has no parameters because you have to set some properties of a UserManager object before you can call the function. You have to call the function within the object instance, in which you have set these properties.

The following properties are supported when you create a user:

UserName | you must set this property
Computer | default: empty (the local computer)
Password | default: empty, must be LanManager 2.0 compatible (limit to 14 characters)
UserDescription | default: empty
HomeDirectory | default: empty
LogonScriptPath | default: empty
AccountType | default: UF_NORMAL_ACCOUNT

After creating the user without error, the rest of the properties of the UserManager object in which you called the functions, are filled with information and you have a Valid UserManager object.

If you want to set additional properties, you have to do this after executing function Create.

Remarks

With this function, you also can create a computer account (domain controller (DC) or workstation/server).

In this case, Computer must be the name of a DC, UserName must have a dollar sign '$' at the end, should be uppercase and is limited to 15 characters (without the '$'). Password should be the lowercase representation of UserName (without the '$') - this will be changed by the system after the creation. Truncate the password to 14 charakters, if the length of the computer name is higher. AccountType must be UF_WORKSTATION_TRUST_ACCOUNT or UF_SERVER_TRUST_ACCOUNT .

See also

UserName
Computer
Password
UserDescription
HomeDirectory
LogonScriptPath
AccountType
UF_* properties
Valid
FormatAPIMessage

Example (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")

usr.Computer = "TheComputer"
usr.UserName = "TestUser"
usr.Password = "d!fsgk5x"
usr.UserDescription = "The description"
usr.HomeDirectory = "\\MyServer\TestUser"
usr.LogonScriptPath = "login.bat"
usr. = usr.UF_NORMAL_ACCOUNT

lRes = usr.Create

If lRes <> 0 Then

MsgBox "Error: " & dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

'now setting additional properties:
usr.HomeDirDrive = "X:"

lRes = usr.LastError
If lRes <> 0 Then

MsgBox "Error: " & dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If


DeleteUser(...) As Long

Class UserManager

Saturday December 30, 2000

DeleteUser

(strUserName As String, [strComputer As String]) As Long

Function

Return value

Returns 0 in case of success, otherwise a nonzero value. This value can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

The function deletes an account on a local or remote machine or server.

Parameters

strUserName
specifies the name of the user to delete

strComputer (optional)
specifies the name of the computer, where the account exists. If you omitt the parameter, the local machine is used. Don't use leading backslashs ('\\').

Remarks

With this function, you also can delete a computer account (domain controller (DC) or workstation/server). In this case, strComputer must be the name of a DC, strUserName is the name of the computer to delete and must have a trailing dollar sign '$'.

To create a new account, use function Create of this class.

See also

Create
FormatAPIMessage

Example (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")

lRes = usr.DeleteUser("TestUser", "ServerName")

If lRes <> 0 Then

MsgBox "Error: " & dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If


Properties of UserManager

Class UserManager

Saturday, January 06, 2001

The properties of class UserManager

Some properties of this class are read only, some can be set by assigning a value. Some of the properties, which are not read only, can only be set within Valid UserManager objects in order to change them. These objects represent existing users. Some others can be set within non Valid UserManager objects in order to create a new user with function Create .

If any error occurs by setting properties, property LastError of this class returns an error number. But LastError will not return an error, if you try to set properties which require a Valid UserManager object within a non Valid UserManager object. So you have to proove property Valid at first in these cases.


Users As Collection

Class UserManager

Friday, January 12, 2001

Users As Collection

Property (read only)

Return value

Returns a collection of UserManager objects. It is initialized with function InitUsers of this class. The collection represents the users on a computer. All actions on the UserManager objects (setting or receiving values of properties of the object) must be done within the object instances of the collection members.

All collection members are indexed with <domainname>\<username> or <username> if property DomainName is empty. You can access the properties of the collection members over the 'For Each ...' construct (example 1) or directly over the index (example 2).

To get information about which members of collection Users are Valid or non Valid objects, read the help to InitUsers .

See also

InitUsers
Valid
DomainName

Example1 (late binding)

Dim usr, usrMember, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.InitUsers("Machine")

If lRes = 0 Then

For Each usrMember In usr.Users

If usrMember.Valid Then

MsgBox usrMember.UserName

End If

Next

Else

MsgBox "Error could not get info of users"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.InitUsers("Machine")

If lRes = 0 Then

MsgBox usr.Users("MyDomain\UserName").UserComment

End If


Computer As String

Class UserManager

Thursday December 28, 2000

Computer As String

Property

Return value

Returns (example 1) or sets the computername of a UserManager object (do not use leading backslashs '\\'). This is the name of the computer, where the account exists. You only can set this property, if the UserManager object is not valid (property Valid of this class), for example, if you want to create a new account with function Create of this class (example 2).

To get the property, you have to init the properties of a UserManager object at first with functions GetUserInfo or InitUsers of this class.

See also

GetUserInfo
InitUsers
Create
Valid

Example1 (query the property from one object, early binding)

Dim usr As New UserManager
Dim lRes As Long

lRes = usr.GetUserInfo("testuser", "NameOfServer")

If lRes = 0 Then

MsgBox usr.Computer

End If

Example2 (setting the property, late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")

usr.Computer
    = "TheComputer"
usr.UserName = "TestUser"
usr.Password = "d!fsgk5x"
usr.UserDescription = "The description"
usr.HomeDirectory = "\\MyServer\TestUser"
usr.LogonScriptPath = "login.bat"
usr.AccountType = usr.UF_NORMAL_ACCOUNT

lRes = usr.Create

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing


DomainName As String

Class UserManager

Saturday December 30, 2000

DomainName As String

Property (read only)

Return value

Returns the name of the computerdomain of a Valid UserManager object. To get the property, you have to init the properties of a UserManager object at first with functions GetUserInfo (example 1), InitUsers (example 2) or Create of this class.

The property is important especially if you want to get the members of local groups (with function InitUsers ), because you can add users from different domains to a local group. For example, if you add a domain user and a local user to a local group on a workstation (on workstations, the DomainName is equal to the name of the computer), you have different values for property DomainName.

See also

Valid
Computer
GetUserInfo
InitUsers
Create

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "Machine")

If lRes = 0 And usr.Valid Then

MsgBox usr.DomainName

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, usrMember, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.InitUsers("Machine", , "GroupName")

If lRes = 0 Then

For Each usrMember In usr.Users

If usrMember.Valid Then

MsgBox usrMember.DomainName

End If

Next

Else

MsgBox "Error could not get info of users"

End If

Set usr = Nothing


UserName As String

Class UserManager

Saturday, January 06, 2001

UserName As String

Property

Return value

Returns or sets the string which contains the name of an user account. It cannot be an empty string and cannot exceed 256 characters. You only can get UserName within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

You can set this property within a Valid UserManager object in order to modifiy the property (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the examples).

You also can set this property within a non Valid (new) UserManager object in order to create a new user with function Create (example 3).

To get or set the property for multiple users, initialize the objects with function InitUsers of this class.

See also

Valid
GetUserInfo
InitUsers
Create
LastError
FormatAPIMessage

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.UserName

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.GetUserInfo("UserName", "Machine")

If lRes = 0 And usr.Valid Then

usr.UserName = "UserNameNew"

End If

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing

Example3 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")

usr.Computer = "PDCName"
usr.UserName = "TestUser"
usr.Password = "d!fsgk5x"
usr.UserDescription = "The description"
usr.HomeDirectory = "\\MyServer\TestUser"
usr.LogonScriptPath = "login.bat"
usr. = usr.UF_NORMAL_ACCOUNT

lRes = usr.Create

If lRes <> 0 Then

MsgBox "Error: " & dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

'now setting additional properties:
usr.HomeDirDrive = "X:"

lRes = usr.LastError
If lRes <> 0 Then

MsgBox "Error: " & dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If


UserDescription As String

Class UserManager

Tuesday, December 04, 2001

UserDescription As String

Property

Return value

Returns or sets the string which contains a description to associate with an user account. It can be an empty string. You only can get UserDescription within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

You can set this property within a Valid UserManager object in order to modifiy the property (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the examples).

You also can set this property within a non Valid (new) UserManager object in order to create a new user with function Create (example 3).

To get or set the property for multiple users, initialize the objects with function InitUsers of this class.

See also

Valid
GetUserInfo
InitUsers
Create
LastError
FormatAPIMessage

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.UserDescription

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.GetUserInfo("UserName", "Machine")

If lRes = 0 And usr.Valid Then

usr.UserDescription = "New description"

End If

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing

Example3 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")

usr.Computer = "PDCName"
usr.UserName = "TestUser"
usr.Password = "d!fsgk5x"
usr.UserDescription = "The description"
usr.HomeDirectory = "\\MyServer\TestUser"
usr.LogonScriptPath = "login.bat"
usr. = usr.UF_NORMAL_ACCOUNT

lRes = usr.Create

If lRes <> 0 Then

MsgBox "Error: " & dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

'now setting additional properties:
usr.HomeDirDrive = "X:"

lRes = usr.LastError
If lRes <> 0 Then

MsgBox "Error: " & dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If


UserFullName As String

Class UserManager

Saturday, January 06, 2001

UserFullName As String

Property

Return value

Returns or sets the string which contains a description to associate with an user account. It can be an empty string. You only can get UserFullName within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

You can set this property only within a Valid UserManager object in order to modifiy the property (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the examples).

To get or set the property for multiple users, initialize the objects with function InitUsers of this class.

See also

Valid
GetUserInfo
InitUsers
Create
LastError
FormatAPIMessage

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.UserFullName

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.GetUserInfo("UserName", "Machine")

If lRes = 0 And usr.Valid Then

usr.UserFullName = "New FullName"

End If

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing


UserComment As String

Class UserManager

Saturday, January 06, 2001

UserComment As String

Property

Return value

Returns or sets the string which contains a user comment. This property is not shown in the usermanager of NT (like property UserDescription ). It can be an empty string. You only can get UserComment within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

You can set this property only within a Valid UserManager object in order to modifiy the property (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the examples).

To get or set the property for multiple users, initialize the objects with function InitUsers of this class.

See also

Valid
GetUserInfo
InitUsers
Create
LastError
FormatAPIMessage
UserDescription

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.UserComment

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.GetUserInfo("UserName", "Machine")

If lRes = 0 And usr.Valid Then

usr.UserComment = "This comment will not be shown in the usermanager"

End If

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing


Password As String

Class UserManager

Tuesday January 02, 2001

Password As String

Property

Return value

Returns or sets the password for an user account. You only can get Password as the string '**************' within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

You can set this property in a Valid UserManager object in order to modifiy the property (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the examples).

You also can set this property within a non Valid (new) UserManager object in order to create a new user with function Create (example 3).

To set the property for multiple users, initialize the objects with function InitUsers of this class.

Remarks

For Lanmager 2.0 compatibility, the password cannot be longer than 14 characters.

If you create a computer account with function Create of this class, the Password should be the lowercase representation of UserName without the trailing dollar sign '$' (a computer account is named with the uppercase name of the computer and a trailing dollar sign). The Password will be changed by the system after the creation. Truncate the password to 14 charakters, if the length of the computername is higher.

See also

Valid
GetUserInfo
InitUsers
Create
LastError
FormatAPIMessage

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

'only '**************' will be returned:
MsgBox usr.Password

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.GetUserInfo("UserName", "Machine")

If lRes = 0 And usr.Valid Then

usr.Password = "f5x!<jx"

End If

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing

Example3 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")

usr.Computer = "PDCName"
usr.UserName = "TestUser"
usr.Password = "d!fsgk5x"
usr.UserDescription = "The description"
usr.HomeDirectory = "\\MyServer\TestUser"
usr.LogonScriptPath = "login.bat"
usr. = usr.UF_NORMAL_ACCOUNT

lRes = usr.Create

If lRes <> 0 Then

MsgBox "Error: " & dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

'now setting additional properties:
usr.HomeDirDrive = "X:"

lRes = usr.LastError
If lRes <> 0 Then

MsgBox "Error: " & dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If


PasswordDontExpire As Boolean

Class UserManager

Tuesday January 02, 2001

PasswordDontExpire As Boolean

Property

Return value

Returns or sets whether the password of an user account never expires. You only can get PasswordDontExpire within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

You can set this property only in a Valid UserManager object in order to modifiy the property (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the examples).

To get or set the property for multiple users, initialize the objects with function InitUsers of this class.

See also

Valid
GetUserInfo
InitUsers
Create
LastError
FormatAPIMessage

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.PasswordDontExpire

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.GetUserInfo("UserName", "Machine")

If lRes = 0 And usr.Valid Then

usr.PasswordDontExpire = True

End If

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing


PasswordCannotChange As Boolean

Class UserManager

Tuesday January 02, 2001

PasswordCannotChange As Boolean

Property

Return value

Returns or sets whether the password can be changed by an user account. You only can get PasswordCannotChange within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

You can set this property only in a Valid UserManager object in order to modifiy the property (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the examples).

To get or set the property for multiple users, initialize the objects with function InitUsers of this class.

See also

Valid
GetUserInfo
InitUsers
Create
LastError
FormatAPIMessage

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.PasswordCannotChange

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.GetUserInfo("UserName", "Machine")

If lRes = 0 And usr.Valid Then

usr.PasswordCannotChange = True

End If

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing


PasswordNotRequired As Boolean

Class UserManager

Saturday, January 06, 2001

PasswordNotRequired As Boolean

Property

Return value

Returns or sets whether a password is not required for an user account. You only can get PasswordNotRequired within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

You can set this property only in a Valid UserManager object in order to modifiy the property (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the examples).

To get or set the property for multiple users, initialize the objects with function InitUsers of this class.

See also

Valid
GetUserInfo
InitUsers
Create
LastError
FormatAPIMessage

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.PasswordNotRequired

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.GetUserInfo("UserName", "Machine")

If lRes = 0 And usr.Valid Then

usr.PasswordNotRequired = True

End If

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing


PasswordExpired As Boolean

Class UserManager

Tuesday January 02, 2001

PasswordExpired As Boolean

Property

Return value

Returns or sets whether the password of an user account is expired. This property causes the ckeckbox 'user has to change his password at the next logon' to be changed.

You only can get PasswordExpired within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

You can set this property only in a Valid UserManager object in order to modifiy the property (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the examples).

To get or set the property for multiple users, initialize the objects with function InitUsers of this class.

See also

Valid
GetUserInfo
InitUsers
Create
LastError
FormatAPIMessage

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.PasswordExpired

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.GetUserInfo("UserName", "Machine")

If lRes = 0 And usr.Valid Then

usr.PasswordExpired = True

End If

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing


PasswordAge As Long

Class UserManager

Tuesday January 02, 2001

Password Age As Long

Property (read only)

Return value

Returns the password age of an user account in seconds. You only can get PasswordAge within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

To get the property for multiple users, initialize the objects with function InitUsers of this class.

See also

Valid
GetUserInfo
InitUsers
Create

Example (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.PasswordAge

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

End If


PasswordLastModified As Date

Class UserManager

Tuesday January 02, 2001

PasswordLastModified As Date

Property (read only)

Return value

Returns the date when the password of an user was changed. You only can get PasswordLastModified within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

To get the property for multiple users, initialize the objects with function InitUsers of this class.

See also

Valid
GetUserInfo
InitUsers
Create

Example (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.PasswordLastModified

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

End If


HomeDirectory As String

Class UserManager

Saturday, January 06, 2001

HomeDirectory As String

Property

Return value

Returns or sets the string which contains the path of the home directory of an user account. It can be an empty string. You only can get HomeDirectory within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

You can set this property within a Valid UserManager object in order to modifiy the property (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the examples).

You also can set this property within a non Valid (new) UserManager object in order to create a new user with function Create (example 3).

To get or set the property for multiple users, initialize the objects with function InitUsers of this class.

To set a drive letter for the user's HomeDirectory, use property HomeDirDrive of this class.

See also

Valid
GetUserInfo
InitUsers
Create
HomeDirDrive
LastError
FormatAPIMessage

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.HomeDirectory

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.GetUserInfo("UserName", "Machine")

If lRes = 0 And usr.Valid Then

usr.HomeDirectory = "\\MyServer\TestUser"

End If

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing

Example3 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")

usr.Computer = "PDCName"
usr.UserName = "TestUser"
usr.Password = "d!fsgk5x"
usr.UserDescription = "The description"
usr.HomeDirectory = "\\MyServer\TestUser"
usr.LogonScriptPath = "login.bat"
usr. = usr.UF_NORMAL_ACCOUNT

lRes = usr.Create

If lRes <> 0 Then

MsgBox "Error: " & dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

'now setting additional properties:
usr.HomeDirDrive = "X:"

lRes = usr.LastError
If lRes <> 0 Then

MsgBox "Error: " & dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If


HomeDirDrive As String

Class UserManager

Saturday, January 06, 2001

HomeDirDrive As String

Property

Return value

Returns or sets the string which contains the drive letter assigned to the user's home directory for logon purposes. It can be an empty string, but not, if property HomeDirectory is not empty.

You only can get HomeDirDrive within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

You can set this property only within a Valid UserManager object in order to modifiy the property (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the examples).

To get or set the property for multiple users, initialize the objects with function InitUsers of this class.

See also

Valid
GetUserInfo
InitUsers
Create
HomeDirectory
LastError
FormatAPIMessage

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.HomeDirDrive

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.GetUserInfo("UserName", "Machine")

If lRes = 0 And usr.Valid Then

usr.HomeDirDrive = "X" '"X:" would also work

End If

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing


HomeDirRequired As Boolean

Class UserManager

Sunday, January 07, 2001

HomeDirRequired As Boolean

Property

Return value

Returns or sets whether the home directory is required. This property is ignored on Windows NT computers and is only implemented for use in the future. You should not set this property. To set the home properties of a user, use HomeDirectory and HomeDirDrive .

You only can get HomeDirRequired within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

To get the property for multiple users, initialize the objects with function InitUsers of this class.

See also

Valid
GetUserInfo
InitUsers
Create
HomeDirectory
HomeDirDrive

Example (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.HomeDirRequired

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing


AccountType As Long

Class UserManager

Wednesday December 27, 2000

AccountType As Long

Property

Return value

Returns or sets the account type of a user account. You only can get AccountType within a Valid UserManager object (example 1). You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

You can set this property within a Valid UserManager object in order to modifiy the property (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

You can set the property within a non Valid UserManager object in order to create a new account (example 3). In this case, use a new object instance. If you don't assign an account type by creating a new account, UF_NORMAL_ACCOUNT is the default.

Use the UF_* properties to assign the right values.

To get or set the property for multiple users, initialize the objects with function InitUsers of this class.

Remarks

If you set the property within a Valid UserManager object in order to modify it, you cannot change an user account to a workstation or server trust account or vice versa.

You only can create computer accounts on a domain controller. To manage this, use the name of a domain controller in the functions GetUserInfo , InitUsers or Create .

To get the account type in textual form, use the property AccountTypeStr of this class.

See also

Valid
LastError
GetUserInfo
InitUsers
Create
UF_* properties
 AccountTypeStr
FormatAPIMessage

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.AccountType

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.GetUserInfo("UserName", "Machine")

If lRes = 0 And usr.Valid Then

usr.AccountType = usr.UF_TEMP_DUPLICATE_ACCOUNT

End If

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing

Example3 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")

usr.Computer = "TheComputer"
usr.UserName = "TestUser"
usr.Password = "d!fsgk5x"
usr.UserDescription = "The description"
usr.HomeDirectory = "\\MyServer\TestUser"
usr.LogonScriptPath = "login.bat"
usr.AccountType = usr.UF_NORMAL_ACCOUNT

lRes = usr.Create

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing


AccountTypeStr As String

Class UserManager

Wednesday December 27, 2000

AccountTypeStr As String

Property (read only)

Return value

Returns the account type of a user account in textual form. You only can get AccountTypeStr within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

The property returns one of the following strings:

'UF_WORKSTATION_TRUST_ACCOUNT'
'UF_SERVER_TRUST_ACCOUNT'
'UF_NORMAL_ACCOUNT'
'UF_INTERDOMAIN_TRUST_ACCOUNT'
'UF_TEMP_DUPLICATE_ACCOUNT'

Read the help to the UF_* properties, to see, what these strings mean.

Remarks

To set the account type, use the property AccountType of this class.

See also

Valid
GetUserInfo
InitUsers
Create
AccountType
UF_* properties

Example (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.AccountTypeStr

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing


UF_* properties

Class UserManager

Wednesday December 27, 2000

UF_WORKSTATION_TRUST_ACCOUNT
UF_SERVER_TRUST_ACCOUNT
UF_NORMAL_ACCOUNT
UF_INTERDOMAIN_TRUST_ACCOUNT
UF_TEMP_DUPLICATE_ACCOUNT

As Long

Properties (read only)

Return value

The properties are used like constants to set or get the account type of a user or computer account. For further informations, read the help to property AccountType or function Create of this class.

The meanings:

UF_WORKSTATION_TRUST_ACCOUNT
is a computer account for a workstation or server that is a member of a domain.

UF_SERVER_TRUST_ACCOUNT
is a computer account for a backup domain controller that is a member of a domain.

UF_NORMAL_ACCOUNT
is a default account type that represents a typical user.

UF_INTERDOMAIN_TRUST_ACCOUNT
is a permit to trust account for a domain that trusts other domains.

UF_TEMP_DUPLICATE_ACCOUNT
is an account for users whose primary account is in another domain.

See also

Create
AccountType

Example (early binding)

Dim usr As New UserManager
Dim dll As New DllClass
Dim lRes As Long

usr.Computer = "TheComputer"
usr.UserName = "TestUser"
usr.Password = "d!fsgk5x"
usr.UserDescription = "The description"
usr.HomeDirectory = "\\MyServer\TestUser"
usr.LogonScriptPath = "login.bat"
usr.AccountType = usr.UF_NORMAL_ACCOUNT

lRes = usr.Create

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing


FILTER_* properties

Class UserManager

Saturday, December 30, 2000

FILTER_ALL_ACCOUNT
FILTER_WORKSTATION_TRUST_ACCOUNT
FILTER_SERVER_TRUST_ACCOUNT
FILTER_NORMAL_ACCOUNT
FILTER_INTERDOMAIN_TRUST_ACCOUNT
FILTER_TEMP_DUPLICATE_ACCOUNT

As Long

Properties (read only)

Return value

The properties are used like constants to get filtered user account types by function InitUsers of this class. If you use a filter in this function (parameter lngFilter), only the accounts with the specified type are members of the collection Users of the UserManager object. For further informations, read the help to this function. The properties are equal to the UF_* properties except FILTER_ALL_ACCOUNT.

The meanings:

FILTER_ALL_ACCOUNT
all account types are returned.

FILTER_WORKSTATION_TRUST_ACCOUNT
is a computer account for a workstation or server that is a member of a domain.

FILTER_SERVER_TRUST_ACCOUNT
is a computer account for a backup domain controller that is a member of a domain.

FILTER_NORMAL_ACCOUNT
is a default account type that represents a typical user.

FILTER_INTERDOMAIN_TRUST_ACCOUNT
is a permit to trust account for a domain that trusts other domains.

FILTER_TEMP_DUPLICATE_ACCOUNT
is an account for users whose primary account is in another domain.

See also

InitUsers
Users
UF_* properties

Example (early binding)

Dim usr, usrMember, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.InitUsers("DCName", FILTER_WORKSTATION_TRUST_ACCOUNT)

If lRes = 0 Then

For Each usrMember In usr.Users

If usrMember.Valid Then

MsgBox usrMember.UserName

End If

Next

Else

MsgBox "Error could not get info of users"

End If

Set usr = Nothing


AccountDisabled As Boolean

Class UserManager

Tuesday December 26, 2000

AccountDisabled As Boolean

Property

Return value

Returns or sets whether a user account on a local or remote machine is disabled or not. You only can get AccountDisabled within a Valid UserManager object (example 1). You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

You can set this property only in a Valid UserManager object in order to modifiy the property (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

To get or set the property for multiple users, initialize the objects with function InitUsers of this class.

See also

Valid
LastError
GetUserInfo
InitUsers
Create
FormatAPIMessage

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.AccountDisabled

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.GetUserInfo("UserName", "Machine")

If lRes = 0 And usr.Valid Then

usr.AccountDisabled = True

End If

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing


AccountLocked As Boolean

Class UserManager

Tuesday December 26, 2000

AccountLocked As Boolean

Property

Return value

Returns or sets whether a user account on a local or remote machine is locked or not. You only can get AccountLocked within a Valid UserManager object (example 1). You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

You can set this property only in a Valid UserManager object in order to modifiy the property (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

To get or set the property for multiple users, initialize the objects with function InitUsers of this class.

Remarks

Although it is possible with this property, you never should lock unlocked acounts. In the usermanager of NT, it is not possible to lock accounts. Accounts are locked automatically by the system.

See also

Valid
LastError
GetUserInfo
InitUsers
Create
FormatAPIMessage

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.AccountLocked

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.GetUserInfo("UserName", "Machine")

If lRes = 0 And usr.Valid Then

If usr.AccountLocked = True Then

usr.AccountLocked = False

End If

End If

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing


AccountExpires As Date

Class UserManager

Tuesday December 26, 2000

AccountExpires As Date

Property

Return value

Returns or sets the user account expiration date. It returns 01/01/1970 when the account never exires. You only can get AccountExpires within a Valid UserManager object (example 1). You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

You can set this property only in a Valid UserManager object in order to modifiy the property (example 2). Set it to -1 in for an account that never expires. If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

To get or set the property for multiple users, initialize the objects with function InitUsers of this class.

Remarks

in the usermanager of Windows NT, the expiration date is shown as the last valid day to logon. Here, the property sets the date as the day after the last valid day to logon. You should set only a date without hours, minutes or seconds.

See also

Valid
LastError
GetUserInfo
InitUsers
Create
FormatAPIMessage

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.AccountExpires

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.GetUserInfo("UserName", "Machine")

If lRes = 0 And usr.Valid Then

usr.AccountExpires = "06/01/2001"

End If

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing


LogonScriptPath As String

Class UserManager

Monday January 01, 2001

LogonScriptPath As String

Property

Return value

Returns or sets the logon script path for an user account. You only can get LogonScriptPath within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

You can set this property in a Valid UserManager object in order to modifiy the property (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the examples).

You also can set this property within a non Valid (new) UserManager object in order to create a new user with function Create (example 3).

To get or set the property for multiple users, initialize the objects with function InitUsers of this class.

See also

Valid
GetUserInfo
InitUsers
Create
LastError
FormatAPIMessage

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.LogonScriptPath

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.GetUserInfo("UserName", "Machine")

If lRes = 0 And usr.Valid Then

usr.LogonScriptPath = "login.bat"

End If

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing

Example3 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")

usr.Computer = "PDCName"
usr.UserName = "TestUser"
usr.Password = "d!fsgk5x"
usr.UserDescription = "The description"
usr.HomeDirectory = "\\MyServer\TestUser"
usr.LogonScriptPath = "login.bat"
usr. = usr.UF_NORMAL_ACCOUNT

lRes = usr.Create

If lRes <> 0 Then

MsgBox "Error: " & dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

'now setting additional properties:
usr.HomeDirDrive = "X:"

lRes = usr.LastError
If lRes <> 0 Then

MsgBox "Error: " & dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If


ProfilePath As String

Class UserManager

Wednesday, January 03, 2001

ProfilePath As String

Property

Return value

Returns or sets the path to the user's profile. This property can be an empty string, a local absolute path, or a UNC path. You only can get ProfilePath within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

You can set this property only within a Valid UserManager object in order to modifiy the property (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the examples).

To get or set the property for multiple users, initialize the objects with function InitUsers of this class.

See also

Valid
GetUserInfo
InitUsers
Create
LastError
FormatAPIMessage

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.ProfilePath

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.GetUserInfo("UserName", "Machine")

If lRes = 0 And usr.Valid Then

usr.ProfilePath = "\\TheServer\TestUser\Profile"

End If

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing


LogonHours As String

Class UserManager

Monday January 01, 2001

LogonHours As String

Property

Return value

Returns or sets the allowed logon hours for an user account as a string of 168 binary digits. 168 binary digits mean 7 days with 24 hours beginning with sunday 00:00 AM and ending with saturday 24:00 PM. In this string, every character which is '0' means the logon is not allowed, otherwise allowed.

You only can get LogonHours within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

You can set this property only in a Valid UserManager object in order to modifiy the property. If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

To get or set the property for multiple users, initialize the objects with function InitUsers of this class (example 2).

Remarks

To query the logon hours of each day with some formatting options, use the LogonHours* properties of this class.

See also

Valid
GetUserInfo
InitUsers
Create
LastError
LogonHours*
FormatAPIMessage

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.LogonHours

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, usrMember, dll, lRes, sLH

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")

'the logon hours are 6:00 AM to 6:00 PM
'on every day except sunday and saturday
sLH = "000000000000000000000000" & _
"000000111111111111000000" & _
"000000111111111111000000" & _
"000000111111111111000000" & _
"000000111111111111000000" & _
"000000111111111111000000" & _
"000000000000000000000000"

lRes = grp.InitUsers("Machine")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
GoTo exit_sub

End If

If lRes = 0 Then

For Each usrMember In usr.Users

If usrMember.Valid Then

usrMember.LogonHours = sLH
If usrMember.LastError <> 0 Then MsgBox "Error changing LogonHours"

End If

Next

Else

MsgBox "Error could not get info of users"

End If


LogonHours* properties

Class UserManager

Monday January 01, 2001

LogonHoursSun
LogonHoursMon
LogonHoursTue
LogonHoursWed
LogonHoursThu
LogonHoursFri
LogonHoursSat

As String

Properties (read only)

Return value

Return the allowed logon hours for an user account as a formatted string for each day of the week.

You only can get LogonHours* within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

The strings are formatted how it is declared in parameter booLogonHoursBinary of the functions GetUserInfo and InitUsers of this class. If you set this parameter to True, the strings are strings with length 24 (24 hours each day) out of binary digits. In this string, every character which is '0' means the logon is not allowed, otherwise allowed.

If parameter booLogonHoursBinary is set to False, the format of each string is 'H-H;H-H;...' for example '5-14;16-20'.

To get the properties for multiple users, initialize the objects with function InitUsers of this class.

Remarks

To set the logon hours, use property the LogonHours of this class.

See also

Valid
GetUserInfo
InitUsers
Create
LogonHours

Example (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName", False)

If lRes = 0 And usr.Valid Then

MsgBox "Sunday: " & usr.LogonHoursSun
MsgBox "Saturday: " & usr.LogonHoursSat

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing


UnitsPerWeek As Long

Class UserManager

Wednesday, January 03, 2001

UnitsPerWeek As Long

Property (read only)

Return value

Returns the number of time units in which the property LogonHours and the LogonHours* properties are counted. Normally, UnitsPerWeek has the value 168. That means 168 hours per week (hourly dividing the week). This is the only value which is supported by ntXdll.

You only can get UnitsPerWeek within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

To get the property from multiple users, initialize the objects with function InitUsers of this class.

Remarks

The property is not very important and only implemented for support purposes. I don't know any system with other values than hourly units. Please write me if any error occurs by reading the LogonHours or LogonHours* properties.

See also

Valid
GetUserInfo
InitUsers
Create
LogonHours
LogonHours*

Example (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

Msgbox usr.UnitsPerWeek

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing


Workstations As String

Class UserManager

Saturday, January 06, 2001

Workstations As String

Property

Return value

Returns or sets the string which contains the computer names, an user is allowed to log on. It can be an empty string if the user can log on to any computer. More than one workstation names must be seperated by a comma. Do not specify more than 8 computers. Don't use trailing backslashs ('\\').

You only can get Workstations within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

You can set this property only within a Valid UserManager object in order to modifiy the property (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the examples).

To get or set the property for multiple users, initialize the objects with function InitUsers of this class.

Remarks

To read the workstations in an easier way, use the Workstation* properties of this class.

See also

Valid
GetUserInfo
InitUsers
Create
LastError
FormatAPIMessage
Workstation*

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.Workstations

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.GetUserInfo("UserName", "Machine")

If lRes = 0 And usr.Valid Then

usr.Workstations = "Computer1,Computer2"

End If

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing


Workstation* properties

Class UserManager

Saturday, January 06, 2001

Workstation1
Workstation2
Workstation3
Workstation4
Workstation5
Workstation6
Workstation7
Workstation8

As String

Properties (read only)

Return value

Return a string which contains the computer name, an user is allowed to log on to. It can be an empty string if the user can log on to any computer.

You only can get the Workstation* properties within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

To get the properties for multiple users, initialize the objects with function InitUsers of this class.

Remarks

To set the workstations, use the property Workstations of this class.

See also

Valid
GetUserInfo
InitUsers
Create
Workstations

Example (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.Workstation1 & "," & usr.Workstation2

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing


UserID As Long

Class UserManager

Saturday, January 06, 2001

UserID As Long

Property (read only)

Return value

Returns the unique ID of a user on a local or remote computer. You only can get UserID within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

To get the property for multiple users, initialize the objects with function InitUsers of this class (example 2).

See also

Valid
GetUserInfo
InitUsers
Create

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.UserID

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, usrMember, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.InitUsers("Machine")

If lRes = 0 Then

For Each usrMember In usr.Users

If usrMember.Valid Then

MsgBox usrMember.UserID

End If

Next

Else

MsgBox "Error could not get info of users"

End If

Set usr = Nothing


PrimaryGroupID As Long

Class UserManager

Wednesday, January 03, 2001

PrimaryGroupID As Long

Property

Return value

Returns or sets the ID of the primary group, an user account is member of. At default, an account belongs to Domain Users on domain controllers or to Users on workstations/servers.

You only can get PrimaryGroupID within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

You can set this property only in a Valid UserManager object in order to modifiy the property (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the examples).

You get the ID of a group from property GroupID of class GroupManager.

To get or set the property for multiple users, initialize the objects with function InitUsers of this class.

See also

Valid
GetUserInfo
InitUsers
Create
LastError
GroupID
FormatAPIMessage

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.PrimaryGroupID

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.GetUserInfo("UserName", "PDCName")

If lRes = 0 And usr.Valid Then

usr.PrimaryGroupID = 512 'domain admins

End If

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing


LastLogon As Date

Class UserManager

Monday, January 01, 2001

LastLogon As Date

Property (read only)

Return value

Returns the datetime of the last logon of an user account. You only can get LastLogon within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

For domain users, this property can be different on each domain controller (DC) in a domain. To get the latest datetime you must query the property on each DC. You can use the function GetSeparateInfos to fill all the properties of a Valid UserManager object which are different on each DC.

To get each DC in a domain, use function InitComputerInfo of class Computer.

See also

Valid
GetUserInfo
InitUsers
Create
GetSeparateInfos
InitComputerInfo

Example (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "PDCName")

If lRes = 0 And usr.Valid Then

'get the property on the backup domain controller
lRes = usr.GetSeparateInfos("BDCName", True)

If lRes = 0 Then

MsgBox usr.LastLogon

Else

MsgBox "Error could not get user info from BDC"

End If

Else

MsgBox "Error could not get user info from PDC"

End If

Set usr = Nothing


LastLogoff As Date

Class UserManager

Monday, January 01, 2001

LastLogoff As Date

Property (read only)

Return value

Returns the datetime of the last logoff of an user account. You only can get LastLogoff within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

For domain users, this property can be different on each domain controller (DC) in a domain. To get the latest datetime you must query the property on each DC. You can use the function GetSeparateInfos to fill all the properties of a Valid UserManager object which are different on each DC.

To get each DC in a domain, use function InitComputerInfo of class Computer.

See also

Valid
GetUserInfo
InitUsers
Create
GetSeparateInfos
InitComputerInfo

Example (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "PDCName")

If lRes = 0 And usr.Valid Then

'get the property on the backup domain controller
lRes = usr.GetSeparateInfos("BDCName", True)

If lRes = 0 Then

MsgBox usr.LastLogoff

Else

MsgBox "Error could not get user info from BDC"

End If

Else

MsgBox "Error could not get user info from PDC"

End If

Set usr = Nothing


NumLogons As Long

Class UserManager

Monday January 01, 2001

NumLogons As Long

Property (read only)

Return value

Returns the number of logons of an user account. You only can get NumLogons within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

This property can be different on each domain controller (DC) in a domain. To get the total number of all logons you must count up the numbers on each DC. You can use the function GetSeparateInfos to fill all the properties of a Valid UserManager object which are different on each DC.

To get each DC in a domain, use function InitComputerInfo of class Computer.

See also

Valid
GetUserInfo
InitUsers
Create
GetSeparateInfos
InitComputerInfo

Example (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "PDCName")

If lRes = 0 And usr.Valid Then

'get the number on the backup domain controller
lRes = usr.GetSeparateInfos("BDCName", True)

If lRes = 0 Then

MsgBox usr.NumLogons

Else

MsgBox "Error could not get user info from BDC"

End If

Else

MsgBox "Error could not get user info from PDC"

End If

Set usr = Nothing


BadPasswordCount As Long

Class UserManager

Thursday December 28, 2000

BadPasswordCount As Long

Property (read only)

Return value

Returns the number of bad logon attempts of an user account. You only can get BadPasswordCount within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

This property can be different on each domain controller (DC) in a domain. To get the total number of all bad logon attempts you must count up the numbers on each DC. You can use the function GetSeparateInfos to fill all the properties of a Valid UserManager object which are different on each DC.

To get each DC in a domain, use function InitComputerInfo of class Computer.

See also

Valid
GetUserInfo
InitUsers
Create
GetSeparateInfos
InitComputerInfo

Example (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "PDCName")

If lRes = 0 And usr.Valid Then

'get the number on the backup domain controller
lRes = usr.GetSeparateInfos("BDCName", True)

If lRes = 0 Then

MsgBox usr.BadPasswordCount

Else

MsgBox "Error could not get user info from BDC"

End If

Else

MsgBox "Error could not get user info from PDC"

End If

Set usr = Nothing


Privilege As Long

Class UserManager

Wednesday, January 03, 2001

Privilege As Long

Property (read only)

Return value

Returns the enabled privilege of an user account. You only can get Privilege within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

To determine, what the returned number means, you can use the USER_PRIV_* properties of this class.

Privilege is read only. This means that the users privilege cannot be set by setting the property. The privilege must be set by adding the user to special groups with function AddMember of class GroupManager. For example Users, Guests or Administrators.

Remarks

To get the privilege in textual form, use property PrivilegeStr of this class.

See also

Valid
GetUserInfo
InitUsers
Create
USER_PRIV_*
PrivilegeStr
AddMember

Example (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

If usr.Privilege = usr.USER_PRIV_ADMIN Then

Msgbox "User is an admin"

End If

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing


PrivilegeStr As String

Class UserManager

Wednesday, January 03, 2001

PrivilegeStr As String

Property (read only)

Return value

Returns the enabled privilege of a user account in textual form. You only can get PrivilegeStr within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

The property returns one of the following strings:

'USER_PRIV_ADMIN'
'USER_PRIV_USER'
'USER_PRIV_GUEST'
'USER_PRIV_MASK'

Read the help to the USER_PRIV_* properties to determine, what the returned strings mean.

Remarks

To get the privilege as a long number, use property Privilege of this class.

See also

Valid
GetUserInfo
InitUsers
Create
USER_PRIV_* properties
 Privilege

Example (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

If usr.PrivilegeStr = "USER_PRIV_ADMIN" Then

Msgbox "User is an admin"

End If

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing


USER_PRIV_* properties

Class UserManager

Wednesday, January 03, 2001

USER_PRIV_ADMIN
USER_PRIV_USER
USER_PRIV_GUEST
USER_PRIV_MASK

As Long

Properties (read only)

Return value

The properties are used like a constants to get the user's privilege. For further information, read the help to property Privilege of this class.

The meanings:

USER_PRIV_ADMIN
user has admin privileges.

USER_PRIV_USER
user has user privileges.

USER_PRIV_GUEST
user has guest privileges.

USER_PRIV_MASK
reserved.

See also

Privilege
AF_* properties

Example (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

If usr.Privilege = usr.USER_PRIV_ADMIN Then

Msgbox "User has admin privileges"

End If

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

'what is the privilege of an user, who is member
'of the groups Administrators and Users and Guests?
'Try it out!


Authority As Long

Class UserManager

Wednesday, January 03, 2001

Authority As Long

Property (read only)

Return value

Returns the enabled authority of a user account. You only can get Authority within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

To determine, what the returned number means, you can use the AF_* properties of this class.

Authority is read only. This means that the users authority cannot be set by setting the property. The authority must be set by adding the user to special operator groups with function AddMember of class GroupManager.

Remarks

To get the authority in textual form, use property AuthorityStr of this class.

See also

Valid
GetUserInfo
InitUsers
Create
AF_* properties
 AuthorityStr
AddMember

Example (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

If usr.Authority = usr.AF_OP_NONE Then

Msgbox "User has no authority"

End If

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing


AuthorityStr As String

Class UserManager

Wednesday, January 03, 2001

AuthorityStr As String

Property (read only)

Return value

Returns the enabled authority of a user account in textual form. You only can get AuthorityStr within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

The property returns one of the following strings:

'AF_OP_ACCOUNTS'
'AF_OP_COMM'
'AF_OP_PRINT'
'AF_OP_SERVER'
'AF_OP_NONE'

Read the help to the AF_* properties to determine, what the returned strings mean.

Remarks

To get the authority as a long number, use property Authority of this class.

See also

Valid
GetUserInfo
InitUsers
Create
AF_* properties
 Authority

Example (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

If usr.AuthorityStr = "AF_OP_NONE" Then

Msgbox "User has no authority"

End If

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing


AF_* properties

Class UserManager

Wednesday December 27, 2000

AF_OP_ACCOUNTS
AF_OP_PRINT
AF_OP_SERVER
AF_OP_COMM
AF_OP_NONE

As Long

Properties (read only)

Return value

The properties are used like constants to get the authority of a user account. For further informations, read the help to property Authority of this class. The users authority cannot be set by setting the property Authority . This property is read only. It must be set by adding the user to special operator groups with function AddMember of class GroupManager.

The meanings:

AF_OP_PRINT
the print operator privilege is enabled.

AF_OP_COMM
the communications operator privilege is enabled.

AF_OP_SERVER
the server operator privilege is enabled.

AF_OP_ACCOUNTS
the accounts operator privilege is enabled.

AF_OP_NONE
no privilege is enabled.

See also

Authority
AddMember

Example (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

If usr.Authority = usr.AF_OP_NONE Then

Msgbox "User has no authority"

End If

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing


LogonScriptExecuted As Boolean

Class UserManager

Monday January 01, 2001

LogonScriptExecuted As Boolean

Property

Return value

Returns or sets whether tho logon script is to be executed. This property must always be set to True on Windows NT computers and Lanmanager 2.0 networks. An error will be returned, if you try to set this property to False.

You only can get LogonScriptExecuted within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

To get the property for multiple users, initialize the objects with function InitUsers of this class.

See also

Valid
GetUserInfo
InitUsers
Create

Example (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.LogonScriptExecuted

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing


CodePage As Long

Class UserManager

Thursday December 28, 2000

CodePage As Long

Property

Return value

Returns or sets the default codepage for a user's language. You only can get CodePage within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

You can set this property only in a Valid UserManager object in order to modifiy the property (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

To get or set the property for multiple users, initialize the objects with function InitUsers of this class.

Remarks

You should not set this property because all users get the default system codepage and regulary, the codepage is not stored in the user's properties.

See also

Valid
GetUserInfo
InitUsers
Create
LastError
FormatAPIMessage

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.CodePage

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.GetUserInfo("UserName", "Machine")

If lRes = 0 And usr.Valid Then

usr.CodePage = 850

End If

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing


CountryCode As Long

Class UserManager

Thursday December 28, 2000

CountryCode As Long

Property

Return value

Returns or sets the country code for a user's language. You only can get CountryCode within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

You can set this property only in a Valid UserManager object in order to modifiy the property (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

To get or set the property for multiple users, initialize the objects with function InitUsers of this class.

Remarks

You should not set this property because all users get the default system country code and normally, the codepage is not stored in the user's properties.

See also

Valid
GetUserInfo
InitUsers
Create
LastError
FormatAPIMessage

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.CountryCode

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.GetUserInfo("UserName", "Machine")

If lRes = 0 And usr.Valid Then

'setting the german country code
usr.CountryCode = 49

End If

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing


Parameters As String

Class UserManager

Monday January 01, 2001

Parameters As String

Property

Return value

Returns or sets the parameters of an user account. You only can get Parameters within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

You can set this property only in a Valid UserManager object in order to modifiy the property (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

To get or set the property for multiple users, initialize the objects with function InitUsers of this class.

Remarks

You should not set this property because only Microsoft products use this member to store user configuration information (for example FPNW informations).

See also

Valid
GetUserInfo
InitUsers
Create
LastError
FormatAPIMessage

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.Parameters

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.GetUserInfo("UserName", "Machine")

If lRes = 0 And usr.Valid Then

usr.Parameters = "Do not edit this property"

End If

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing


MaxStorage As Long

Class UserManager

Saturday, January 06, 2001

MaxStorage As Long

Property

Return value

Returns or sets the maximum amount of disk space the user can use. A value of USER_MAXSTORAGE_UNLIMITED (-1) means unlimited space. Do not set another value, because only USER_MAXSTORAGE_UNLIMITED is allowed. An error will be returned, if you try to set another value.

You only can get MaxStorage within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

To get the property for multiple users, initialize the objects with function InitUsers of this class.

See also

Valid
GetUserInfo
InitUsers
Create
USER_MAXSTORAGE_UNLIMITED

Example (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox usr.MaxStorage

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing


USER_MAXSTORAGE_UNLIMITED As Long

Class UserManager

Wednesday, January 03, 2001

USER_MAXSTORAGE_UNLIMITED As Long

Property (read only)

Return value

The property is used like a constant to get the unlimited usage of disk space which is represented by property MaxStorage of this class. For further information, read the help to property MaxStorage of this class.

See also

MaxStorage

Example (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

If usr.MaxStorage = USER_MAXSTORAGE_UNLIMITED Then

MsgBox "Users disk usage is not limited"

End If

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing


LogonServer As String

Class UserManager

Monday January 01, 2001

LogonServer As String

Property (read only)

Return value

Returns the name of the server, to which logon requests are sent. On NT machines, the property always returns '\\*'. This means that logon requests can be handled by any logon server.

You only can get LogonServer within a Valid UserManager object. You get Valid UserManager objects with functions GetUserInfo , InitUsers or Create of this class.

To get the property for multiple users, initialize the objects with function InitUsers of this class.

See also

Valid
GetUserInfo
InitUsers
Create

Example (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

Msgbox usr.LogonServer

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing


Valid As Boolean

Class UserManager

Saturday, January 13, 2001

Valid As Boolean

Property (read only)

Return value

Returns whether a UserManager object represents an existing user account on a local or remote computer.

To get the property, you have to init the properties of a UserManager object at first with functions GetUserInfo (example 1) or InitUsers (example 2) of this class. If you have executed this functions without error, all properties of the UserManager objects are filled with information and all of these objects represent existing users. You also get a Valid UserManager object by creating a new user with function Create of this class.

Only in some special cases, UserManager object members of collection Users of this class can be non Valid objects. To get information about these cases, read the help to InitUsers .

See also

GetUserInfo
InitUsers
Create
Users

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox "UserName is a valid user"

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, usrMember, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.InitUsers("Machine")

If lRes = 0 Then

For Each usrMember In usr.Users

MsgBox usrMember.Valid

Next

Else

MsgBox "Error could not get info of users"

End If

Set usr = Nothing


LastError As Long

Class UserManager

Monday, January 01, 2001

LastError As Long

Property (read only)

Return value

The property returns an error number which is set by different functions and properties of this class. A value of 0 means no error. Otherwise the error number can be a VB or an API error. It is documented in the help of the methods which set this property. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

See also

FormatAPIMessage

Example (late binding)

Dim usr, dll, lRes

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = usr.GetUserInfo("TestUser", "Machine")

If lRes = 0 And usr.Valid Then

usr.UserFullName = "Mr. Test"

End If

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set usr = Nothing


GetCurrentUser(...) As String

Class UserManager

Wednesday, January 16, 2002

GetCurrentUser

(strDefault As String)

As String

Function

Return value

Returns the name of the current logged on user. If an error occurs, parameter strDefault will be returned and property LastError of this class will be set to a non zero error number. This value can be a VB or an API error. To get the description of an API error, use function FormatAPIMessage of class DllClass (see the example).

The function returnes only the current logged on user of the local machine. You cannot execute the function on a remote computer.

Parameters

strDefault
specifies the value, which shoul be returned in case of an error.

See also

LastError
FormatAPIMessage

Example (late binding)

Dim usr, dll
Dim lRes, s

Set usr = CreateObject("ntXdll.UserManager")
Set dll = CreateObject("ntXdll.DllClass")

s = usr.GetCurrentUser("NULL")

If s = "NULL" Then

lRes = usr.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes), "netmsg.dll"))

Else

MsgBox s

End If


Class GroupManager

Wednesday, January 09, 2002

Class GroupManager

This class uses Win32 network API to query or set properties of groups on the local or a remote system and needs Windows NT® 4.0 Service Pack 4 or higher. You can use the class for properties on workstations and servers (domains) as well.

To query or set group properties, you have to initialize GroupManager objects at first. Function GetGroupInfo initializes a single GroupManager object, which represents a single group on the local or a remote computer. After executing the function without error, you have a Valid GroupManager object. You can access the properties of the requested group through the object instance, you called the function GetGroupInfo from.

Function InitGroups initializes a collection Groups , which represents all groups on the local or a remote computer. You can specify a local group or a user in this function. Then, the collection contains only the global groups, which are members of the local group. Or the collection contains only the groups, where the user is member of.

After executing the function without error, all collection members are Valid GroupManager objects. You can access the properties of the requested groups only through the object instances of the collection members.

You can add or remove members of groups with the functions AddMember or RemoveMember of this class. The function accepts only Valid GroupManager objects (if you want to add or remove a group member) or Valid UserManager objects (if you want to add or remove a member, which is an user account).

You can change group properties by assigning a value of the right type to the property (syntax: <groupmanager object>.<property> = <value>). You only can change properties within a Valid GroupManager object. This means, that you have to initialize a GroupManager object with the functions above.

If you want to change a property of a single group, you should initialize only a single object with function GetGroupInfo . Otherwise, you would have to run through all collection members with a search criteria until you find the right group.

In this version of ntXdll, you only can change the following properties (alphabetical order):

Computer
GroupComment
GroupName
IsLocal

Some of these properties, you can change only within non Valid GroupManager objects in order to create a new group with function Create .

There are some additional functions, which you can use seperate and which you can use within non Valid GroupManager objects. These functions are:

AddMember
RemoveMember
DeleteGroup

You get detailed information in the help of each function or property.


GetGroupInfo(...) As Long

Class GroupManager

Monday, January 01, 2001

GetGroupInfo

(strGroupName As String, [strComputer As String]) As Long

Function

Return value

Returns 0 in case of success, otherwise a nonzero value. This value can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

The function initializes the properties of a GroupManager object. This means that the properties of a GroupManager object instance, through which you call this function are filled with the properties of a group, you want to query. After executing the function without error, the object instance, you call the function from, is a Valid GroupManager object.

To initialize the properties of multiple groups on a machine, use the function InitGroups of this class.

You have to call this function (or InitGroups for multiple groups or Create for new groups) before you want modifiy properties of groups.

Parameters

strGroupName
specifies the name of the group, you want to get the infos from

strComputer (optional)
specifies the name of the computer where the group lies from which you want to get the info from. Do not use leading backslashs ('\\'). If you omitt the parameter, the local machine is used.

See also

InitGroups
Create
Valid
FormatAPIMessage

Example (late binding)

Dim grp, lRes

Set grp = CreateObject("ntXdll.GroupManager")
lRes = grp.GetGroupInfo("GroupName", "Machine")

If lRes = 0 And grp.Valid Then

MsgBox grp.GroupName

Else

MsgBox "Error could not get group info"

End If

Set grp = Nothing


InitGroups(...) As Long

Class GroupManager

Tuesday, December 19, 2000

InitGroups

([strComputer As String], [strLocalGroup As String], [strUser As String], [booEnumIndirectMembership As Boolean = False]) As Long

Function

Return value

Returns 0 in case of success, otherwise a nonzero value. This value can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

The function initializes the collection Groups of a GroupManager object and all of it's properties. This means that the properties of each member of this collection, which represents a group on a local or remote machine, are filled with information.

You can filter the members of the collection when you assign the different parameters. Not all members of the collection must be Valid GroupManager objects. Because if you assign strLocalGroup as parameter for example, the collection members are members of a local group. It is possible to add global domain groups to a local group on a machine, which is no domain controller (DC). But not all properties of these domain groups are stored in the account database on this non DC machine. So only the properties

GroupName
DomainName
Computer

of these non valid members are initialized in the collection. To get the rest of the properties (to get Valid objects), you must execute InitGroups on the DC where this account are stored (parameter strComputer).

All collection members are indexed with <domainname>\<groupname> or <groupname> if the domainname is empty (group 'Everyone' for example). You can access the properties of the collection members over the 'For Each ...' construct (example 1) or directly over the index (example 2).

All actions on the GroupManager objects (setting or receiving values of properties of the object) must be done within the object instances of the collection members (example 3).

To initialize the properties of only one group on a machine, use the function GetGroupInfo of this class.

You have to call this function (or GetGroupInfo for only one group) before you want modifiy properties of groups.

Parameters

strComputer (optional)
specifies the name of the computer, where you want to get the groups from. If you omitt this parameter, the local machine is used. Do not use leading backslashs ('\\').

strLocalGroup (optional)
specifies the name of a local group, from which you want to get the members. If you omitt this parameter, all groups on the computer are returned.

strUser (optional)
specifies the name of an user, from which you want to get the groups (all groups on the specified computer, where the user is member of). If you omitt this parameter, all groups on the computer are returned.

booEnumIndirectMembership (optional)
if you assign parameter strUser and booEnumIndirectMembership as True, all groups, the user is member and indirectly member of, are returned. Indirectly means, the user is a member of a group which is member of a group on the specified machine. Default is False.

Remarks

If you assign strLocalGroup and strUser, only strLocalGroup is used.

See also

Groups
GetGroupInfo
Valid
FormatAPIMessage

Example1 (late binding)

Dim grp, grpMember, dll, lRes

Set grp = CreateObject("ntXdll.GroupManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = grp.InitGroups("Machine")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
GoTo exit_sub

End If

If lRes = 0 Then

For Each grpMember In grp.Groups

MsgBox grpMember.GroupName

Next

Else

MsgBox "Error could not get info of groups"

End If

Set grp = Nothing

Example2 (late binding)

Dim grp, dll, lRes

Set grp = CreateObject("ntXdll.GroupManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = grp.InitGroups("Machine")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
GoTo exit_sub

End If

If lRes = 0 Then

MsgBox grp.Groups("MyDomain\GroupName").GroupComment

End If

Example3 (modifying group properties, late binding)

Dim grp, grpMember, dll, lRes

Set grp = CreateObject("ntXdll.GroupManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = grp.InitGroups("Machine")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
GoTo exit_sub

End If

If lRes = 0 Then

For Each grpMember In grp.Groups

If grpMember.GroupName = "TheGroupToChange" Then

grpMember.GroupComment = "New Comment"
If grpMember.LastError <> 0 Then MsgBox "Error changing comment"

End If

Next

Else

MsgBox "Error could not get info of groups"

End If

Set grp = Nothing


Create() As Long

Class GroupManager

Tuesday, December 26, 2000

Create() As Long

Function

Return value

Returns 0 in case of success, otherwise a nonzero value. This value can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

The function creates a local or global group on a local or remote machine or server. It has no parameters because you have to set some properties of a GroupManager object before you can call the function. You have to call the function over the object instance, in which you have set these properties.

The following properties are supported when you create a group:

GroupName | you must set this property
Computer | default: empty (the local computer)
GroupComment | default: empty
IsLocal | default: False

After creating the group without error, the rest of the properties of the GroupManager object in which you called the functions, are filled with information and you have a Valid GroupManager object.

Remarks

You cannot create global groups on a computer which is not a domain controller. And you cannot call the function in a GroupManager object, which is valid (property Valid of this object). Use a new instanced object.

See also

GroupName
Computer
GroupComment
IsLocal
Valid
FormatAPIMessage

Example (late binding)

Dim grp, dll, lRes

Set grp = CreateObject("ntXdll.GroupManager")
Set dll = CreateObject("ntXdll.DllClass")

grp.GroupName = InputBox("Groupname:")
grp.Computer = InputBox("Computer:")
grp.GroupComment = InputBox("Comment:")
grp.IsLocal = InputBox("Local?")

lRes = grp.Create

If lRes <> 0 Then

MsgBox "Error: " & dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If


DeleteGroup(...) As Long

Class GroupManager

Wednesday, December 13, 2000

DeleteGroup

(strGroupName As String, [strComputer As String]) As Long

Function

Return value

Returns 0 in case of success, otherwise a nonzero value. This value can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

The function deletes a local or global group on a local or remote machine.

Parameters

strGroupName
the name of the group, you want to delete.

strComputer (optional)
the name of the machine, where you want to delete the group. Do not use leading backslashs ('\\'). If you omitt this parameter, the local machine is used.

See also

FormatAPIMessage

Example (late binding)

Dim grp, dll, lRes

Set grp = CreateObject("ntXdll.GroupManager")
Set dll = CreateObject("ntXdll.dllClass")

lRes = grp.DeleteGroup("TestGroup", "TheServer")

If lRes <> 0 Then

MsgBox "Error: " & dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

Set grp = Nothing
Set dll = Nothing


AddMember(...) As Long

Class GroupManager

Wednesday, January 03, 2001

AddMember

(objAccount As Object) As Long

Function

Return value

Returns 0 in case of success, otherwise a nonzero value. This value can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

The function adds a member to a local or global group on a local or remote computer. This member can be a valid UserManger object (property Valid of the UserManager object) or a valid GroupManager object (property Valid of the GroupManager object).

You get valid objects of these classes with functions, call the functions GetUserInfo , InitUsers , Create of class UserManager, GetGroupInfo , InitGroups or Create of class GroupManager.

You have to call the function in a valid GroupManager object. This is an object which was initialized over function GetGroupInfo or InitGroups of this class and represents an existing group.

Parameter

objAccount
this is the valid UserManager or GroupManager object, you want to add to a group.

Remarks

You cannot add a local group to a local group and you cannot add a global group to a global group. To determine, whether a group is a local or a global group, use property IsLocal of this class.

You cannot add members from a machine, which is not a domain controller to a group on another machine.

To add multiple members to a group or to add one member to multiple groups, you can use the VB structure For Each .... At first, you have to create multiple instances of the objects, you want to use, with the Init* functions of the classes named above.

See also

GetGroupInfo
InitGroups
Create of class GroupManager
 GetUserInfo
InitUsers
Create of class UserManager
 Valid of class GroupManager
 Valid of class UserManager
 IsLocal
FormatAPIMessage

Example1 (adding a global to a local group on the same computer (DC), early binding)

Dim grp1 As New GroupManager, grp2 As New GroupManager
Dim dll As New DllClass
Dim lRes As Long

lRes = grp1.GetGroupInfo("testgroup_local", "NameOfServer")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
GoTo exit_sub

End If

'grp1 must be a valid local group
If grp1.IsLocal = False Or grp1.Valid = False Then GoTo exit_sub

lRes = grp2.GetGroupInfo("testgroup_global", "NameOfServer")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
GoTo exit_sub

End If

'grp2 must be a valid global group
If grp2.IsLocal = True Or grp2.Valid = False Then GoTo exit_sub

lRes = grp1.AddMember(grp2)

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

exit_sub:

Example2 (adding a domain user to a local group on a workstation, early binding)

Dim grp As New GroupManager, usr As New UserManager
Dim dll As New DllClass
Dim lRes As Long

lRes = grp.GetGroupInfo("testgroup_local", "NameOfWorkstation")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
GoTo exit_sub

End If

'grp must be a valid local group
If grp.IsLocal = False Or grp.Valid = False Then GoTo exit_sub

'here, the name of the PDC is used, because a domain user
'must be added to a local group on a workstation
lRes = usr.GetUserInfo("testuser", "NameOfPDC")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
GoTo exit_sub

End If

'usr must be a valid domain user
If usr.Valid = False Then GoTo exit_sub

lRes = grp.AddMember(usr)

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

exit_sub:


RemoveMember(...) As Long

Class GroupManager

Wednesday, January 03, 2001

RemoveMember

(objAccount As Object) As Long

Function

Return value

Returns 0 in case of success, otherwise a nonzero value. This value can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

The function removes a member from a local or global group on a local or remote computer. This member can be a valid UserManger object (property Valid of the UserManager object) or a valid GroupManager object (property Valid of the GroupManager object).

You get valid objects of these classes with functions, call the functions GetUserInfo , InitUsers , Create of class UserManager, GetGroupInfo , InitGroups or Create of class GroupManager.

You have to call the function in a valid GroupManager object. This is an object which was initialized over function GetGroupInfo or InitGroups of this class and represents an existing group.

Parameter

objAccount
this is the valid UserManager or GroupManager object, you want to remove from a group.

Remarks

To remove multiple members from a group or to remove one member from multiple groups, you can use the VB structure For Each .... At first, you have to create multiple instances of the objects you want to use with the Init* functions of the classes named above.

See also

GetGroupInfo
InitGroups
Create of class GroupManager
 GetUserInfo
InitUsers
Create of class UserManager
 Valid of class GroupManager
 Valid of class UserManager
 IsLocal
FormatAPIMessage

Example1 (removing a global from a local group on the same computer (DC), early binding)

Dim grp1 As New GroupManager, grp2 As New GroupManager
Dim dll As New DllClass
Dim lRes As Long

lRes = grp1.GetGroupInfo("testgroup_local", "NameOfServer")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
GoTo exit_sub

End If

'grp1 must be a valid local group
If grp1.IsLocal = False Or grp1.Valid = False Then GoTo exit_sub

lRes = grp2.GetGroupInfo("testgroup_global", "NameOfServer")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
GoTo exit_sub

End If

'grp2 must be a valid global group
If grp2.IsLocal = True Or grp2.Valid = False Then GoTo exit_sub

lRes = grp1.RemoveMember(grp2)

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

exit_sub:

Example2 (removing a domain user from a local group on different remote computers, early binding)

Dim grp As New GroupManager, usr As New UserManager
Dim dll As New DllClass
Dim lRes As Long

lRes = grp.GetGroupInfo("testgroup_local", "NameOfWorkstation")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
GoTo exit_sub

End If

'grp must be a valid local group
If grp.IsLocal = False Or grp.Valid = False Then GoTo exit_sub

'here, the name of the PDC is used, because a domain user
'must be removed from a local group on a workstation
lRes = usr.GetUserInfo("testuser", "NameOfPDC")

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
GoTo exit_sub

End If

'usr must be a valid domain user
If usr.Valid = False Then GoTo exit_sub

lRes = grp.RemoveMember(usr)

If lRes <> 0 Then

MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")

End If

exit_sub:


Properties of GroupManager

Class GroupManager

Saturday, January 06, 2001

The properties of class GroupManager

Some properties of this class are read only, some can be set by assigning a value. Some of the properties, which are not read only, can only be set within Valid GroupManager objects in order to change them. These objects represent existing groups. Some others can be set within non Valid GroupManager objects in order to create a new group with function Create .

If any error occurs by setting properties, property LastError of this class returns an error number. But LastError will not return an error, if you try to set properties which require a Valid GroupManager object within a non Valid GroupManager object. So you have to check property Valid at first in these cases.


Groups As Collection

Class GroupManager

Friday, January 12, 2001

Groups As Collection

Property (read only)

Return value

Returns a collection of GroupManager objects. It is initialized with function InitGroups of this class. The collection represents the local or global groups on a computer. All actions on the GroupManager objects (setting or receiving values of properties of the object) must be done within the object instances of the collection members.

All collection members are indexed with <domainname>\<groupname> or <groupname> if property DomainName is empty (group 'Everyone' for example). You can access the properties of the collection members over the 'For Each ...' construct (example 1) or directly over the index (example 2).

To get information about which members of collection Groups are Valid or non Valid objects, read the help to InitGroups .

See also

InitGroups
Valid
DomainName

Example1 (late binding)

Dim grp, grpMember, lRes

Set grp = CreateObject("ntXdll.GroupManager")
lRes = grp.InitGroups("Machine")

If lRes = 0 Then

For Each grpMember In grp.Groups

If grpMember.Valid Then

MsgBox grpMember.GroupName

End If

Next

Else

MsgBox "Error could not get info of groups"

End If

Set grp = Nothing

Example2 (late binding)

Dim grp, lRes

Set grp = CreateObject("ntXdll.GroupManager")
lRes = grp.InitGroups("Machine")

If lRes = 0 Then

MsgBox grp.Groups("MyDomain\GroupName").GroupComment

End If


GroupName As String

Class GroupManager

Tuesday, December 26, 2000

GroupName As String

Property

Return value

Returns or sets the name of a local or global group on the local or a remote computer. You only can get GroupName in a Valid GroupManager object (example 1). You get Valid GroupManager objects with functions GetGroupInfo , InitGroups or Create of this class.

The length of GroupName must be less than or equal to 256 characters.

You can set this property in a new GroupManager object in order to create a group (example 2) or in a Valid GroupManager object in order to modifiy the property (example 3). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

To get or set the property for multiple groups, initialize the objects with function InitGroups of this class.

See also

Valid
IsLocal
LastError
GetGroupInfo
InitGroups
Create
FormatAPIMessage

Example1 (late binding)

Dim grp, lRes

Set grp = CreateObject("ntXdll.GroupManager")
lRes = grp.GetGroupInfo("GroupName", "Machine")

If lRes = 0 And grp.Valid Then

MsgBox grp.GroupName

Else

MsgBox "Error could not get group info"

End If

Set grp = Nothing

Example2 (late binding)

Dim grp, lRes

Set grp = CreateObject("ntXdll.GroupManager")

grp.GroupName
    = InputBox("Groupname:")
grp.Computer = InputBox("Computer:")
grp.GroupComment = InputBox("Comment:")
grp.IsLocal = InputBox("Local?")

lRes = grp.Create

Example3 (late binding)

Dim grp, dll, lRes

Set grp = CreateObject("ntXdll.GroupManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = grp.GetGroupInfo("GroupName", "Machine")

If lRes = 0 And grp.Valid Then

grp.GroupName = "NewName"

End If

lRes = grp.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set grp = Nothing


GroupComment As String

Class GroupManager

Sunday, December 17, 2000

GroupComment As String

Property

Return value

Returns or sets the comment of a local or global group on the local or a remote computer. You only can get GroupComment in a Valid GroupManager object (example 1). You get Valid GroupManager objects with functions GetGroupInfo or InitGroups of this class.

You can set this property in a new GroupManager object in order to create a group (example 2) or in a Valid GroupManager object in order to modifiy the property (example 3). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

To get or set the property for multiple groups, initialize the objects with function InitGroups of this class.

See also

Valid
IsLocal
LastError
GetGroupInfo
InitGroups
FormatAPIMessage

Example1 (late binding)

Dim grp, lRes

Set grp = CreateObject("ntXdll.GroupManager")
lRes = grp.GetGroupInfo("GroupName", "Machine")

If lRes = 0 And grp.Valid Then

MsgBox grp.GroupComment

Else

MsgBox "Error could not get group info"

End If

Set grp = Nothing

Example2 (late binding)

Dim grp, lRes

Set grp = CreateObject("ntXdll.GroupManager")

grp.GroupName = InputBox("Groupname:")
grp.Computer = InputBox("Computer:")
grp.GroupComment = InputBox("Comment:")
grp.IsLocal = InputBox("Local?")

lRes = grp.Create

Example3 (late binding)

Dim grp, dll, lRes

Set grp = CreateObject("ntXdll.GroupManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = grp.GetGroupInfo("GroupName", "Machine")

If lRes = 0 And grp.Valid Then

grp.GroupComment = "New comment"

End If

lRes = grp.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set grp = Nothing


Computer As String

Class GroupManager

Tuesday, December 19, 2000

Computer As String

Property

Return value

Returns (example 1 + 2) or sets the computername of a GroupManager object (do not use leading backslashs '\\'). This is the name of the computer, where the group exists. You only can set this property, if the GroupManager object is not valid (property Valid of this class), for example, if you want to create a new group with function Create of this class (example 3).

To get the property, you have to init the properties of a GroupManager object at first with functions GetGroupInfo or InitGroups of this class.

See also

GetGroupInfo
InitGroups
Create
Valid

Example1 (query the property from one object, early binding)

Dim grp As New GroupManager
Dim lRes As Long

lRes = grp.GetGroupInfo("testgroup_local", "NameOfServer")

If lRes = 0 Then

MsgBox grp.Computer

End If

Example2 (query the property from all groups, late binding)

Dim grp, grpMember
Dim lRes

Set grp = CreateObject("ntXdll.GroupManager")

lRes = grp.InitGroups("NameOfServer")

If lRes = 0 Then

Fro Each grpMember In grp.Groups

MsgBox grpMember.Computer

Next

End If

Example3 (setting the property, late binding)

Dim grp, lRes

Set grp = CreateObject("ntXdll.GroupManager")

grp.GroupName = InputBox("Groupname:")
grp.Computer = InputBox("Computer:")
grp.GroupComment = InputBox("Comment:")
grp.IsLocal = InputBox("Local?")

lRes = grp.Create


DomainName As String

Class GroupManager

Sunday, December 17, 2000

DomainName As String

Property (read only)

Return value

Returns the name of the computerdomain of a Valid GroupManager object. To get the property, you have to init the properties of a GroupManager object at first with functions GetGroupInfo (example 1) or InitGroups (example 2) of this class.

The property is important especially if you want to get the members of local groups (with function InitGroups ). Because you can add members from from different domains to a local group. For example, if you add a domain user and a local user to a local group on a workstation (on workstations, the DomainName is equal to the name of the Computer), you have different values for property DomainName.

See also

Valid
IsLocal
Computer
GetGroupInfo
InitGroups

Example1 (late binding)

Dim grp, lRes

Set grp = CreateObject("ntXdll.GroupManager")
lRes = grp.GetGroupInfo("GroupName", "Machine")

If lRes = 0 And grp.Valid Then

MsgBox grp.DomainName

Else

MsgBox "Error could not get group info"

End If

Set grp = Nothing

Example2 (late binding)

Dim grp, grpMember, lRes

Set grp = CreateObject("ntXdll.GroupManager")
lRes = grp.InitGroups("Machine")

If lRes = 0 Then

For Each grpMember In grp.Groups

If grpMember.Valid Then

MsgBox grpMember.DomainName

End If

Next

Else

MsgBox "Error could not get info of groups"

End If

Set grp = Nothing


IsLocal As Boolean

Class GroupManager

Tuesday, December 19, 2000

IsLocal As Boolean

Property

Return value

Returns (example 1 + 2) or sets whether a GroupManager object represents a local or global group. You only can set this property, if the GroupManager object is not valid (property Valid of this class), for example, if you want to create a new group with function Create of this class (example 3).

To get the property, you have to init the properties of a GroupManager object at first with functions GetGroupInfo or InitGroups of this class.

See also

GetGroupInfo
InitGroups
Create
Valid

Example1 (query the property from one object, early binding)

Dim grp As New GroupManager
Dim lRes As Long

lRes = grp.GetGroupInfo("testgroup_local", "NameOfServer")

If lRes = 0 Then

MsgBox grp.IsLocal

End If

Example2 (query the property from all groups, late binding)

Dim grp, grpMember
Dim lRes

Set grp = CreateObject("ntXdll.GroupManager")

lRes = grp.InitGroups("NameOfServer")

If lRes = 0 Then

Fro Each grpMember In grp.Groups

MsgBox grpMember.IsLocal

Next

End If

Example2 (setting the property, late binding)

Dim grp, lRes

Set grp = CreateObject("ntXdll.GroupManager")

grp.GroupName = InputBox("Groupname:")
grp.Computer = InputBox("Computer:")
grp.GroupComment = InputBox("Comment:")
grp.IsLocal = InputBox("Local?")

lRes = grp.Create


GroupID As Long

Class GroupManager

Saturday, January 06, 2001

GroupID As Long

Property (read only)

Return value

Returns the unique ID of a global group on a local or remote computer. A local group (property IsLocal of the GroupManager object is True) has no ID (the value is 0).

You only can get GroupID in a Valid GroupManager object (example 1). You get Valid GroupManager objects with functions GetGroupInfo , InitGroups or Create of this class. To get the property for multiple groups, initialize the objects with function InitGroups of this class (example 2).

See also

Valid
IsLocal
GetGroupInfo
InitGroups
Create

Example1 (late binding)

Dim grp, lRes

Set grp = CreateObject("ntXdll.GroupManager")
lRes = grp.GetGroupInfo("GroupName", "Machine")

If lRes = 0 And grp.Valid Then

MsgBox grp.GroupID

Else

MsgBox "Error could not get group info"

End If

Set grp = Nothing

Example2 (late binding)

Dim grp, grpMember, lRes

Set grp = CreateObject("ntXdll.GroupManager")
lRes = grp.InitGroups("Machine")

If lRes = 0 Then

For Each grpMember In grp.Groups

If grpMember.Valid Then

MsgBox grpMember.GroupID

End If

Next

Else

MsgBox "Error could not get info of groups"

End If

Set grp = Nothing


Enabled As Boolean

Class GroupManager

Sunday, December 17, 2000

Enabled As Boolean
EnabledByDefault As Boolean

Properties (read only)

Return value

Return whether a group is enabled for access checks or whether a group is enabled for access check by default. Only global groups have this property (look at IsLocal of this class).

Because of this property is hardcoded to groups, the Enabled* properties of all global groups are True. The Enabled* properties of all local groups are False. You need a Valid GroupManager object. To get the property, you have to init the properties of a GroupManager object at first with functions GetGroupInfo (example 1) or InitGroups (example 2) of this class.

See also

Valid
IsLocal
GetGroupInfo
InitGroups

Example1 (late binding)

Dim grp, lRes

Set grp = CreateObject("ntXdll.GroupManager")
lRes = grp.GetGroupInfo("GroupName", "Machine")

If lRes = 0 And grp.Valid Then

MsgBox grp.Enabled
MsgBox grp.EnabledByDefault

Else

MsgBox "Error could not get group info"

End If

Set grp = Nothing

Example2 (late binding)

Dim grp, grpMember, lRes

Set grp = CreateObject("ntXdll.GroupManager")
lRes = grp.InitGroups("Machine")

If lRes = 0 Then

For Each grpMember In grp.Groups

If grpMember.Valid Then

MsgBox grpMember.Enabled
MsgBox grpMember.EnabledByDefault

End If

Next

Else

MsgBox "Error could not get info of groups"

End If

Set grp = Nothing


Mandatory As Boolean

Class GroupManager

Tuesday, December 19, 2000

Mandatory As Boolean

Properties (read only)

Return value

Returns whether a group cannot have cleared the Enabled property. Only global groups have this property (look at IsLocal of this class).

Because this property is hardcoded to groups, the Mandatory property of all global groups are True. The Mandatory property of all local groups are False. You need a Valid GroupManager object. To get the property, you have to init the properties of a GroupManager object at first with functions GetGroupInfo (example 1) or InitGroups (example 2) of this class.

See also

Enabled
Valid
IsLocal
GetGroupInfo
InitGroups

Example1 (late binding)

Dim grp, lRes

Set grp = CreateObject("ntXdll.GroupManager")
lRes = grp.GetGroupInfo("GroupName", "Machine")

If lRes = 0 And grp.Valid Then

MsgBox grp.Mandatory

Else

MsgBox "Error could not get group info"

End If

Set grp = Nothing

Example2 (late binding)

Dim grp, grpMember, lRes

Set grp = CreateObject("ntXdll.GroupManager")
lRes = grp.InitGroups("Machine")

If lRes = 0 Then

For Each grpMember In grp.Groups

If grpMember.Valid Then

MsgBox grpMember.Mandatory

End If

Next

Else

MsgBox "Error could not get info of groups"

End If

Set grp = Nothing


Valid As Boolean

Class GroupManager

Tuesday, December 26, 2000

Valid As Boolean

Property (read only)

Return value

Returns whether a GroupManager object represents an existing local or global group on a local or remote computer.

To get the property, you have to init the properties of a GroupManager object at first with functions GetGroupInfo (example 1) or InitGroups (example 2) of this class. If you have executed this functions without error, all properties of the GroupManager objects are filled with information and all of these objects represent existing groups. You also get a Valid GroupManager object by creating a new group with function Create of this class.

Only in some special cases, GroupManager object members of collection Groups of this class can be non Valid objects. To get information about these cases, read the help to InitGroups .

See also

GetGroupInfo
InitGroups
Create
Groups

Example1 (late binding)

Dim grp, lRes

Set grp = CreateObject("ntXdll.GroupManager")
lRes = grp.GetGroupInfo("GroupName", "Machine")

If lRes = 0 Then

MsgBox grp.Valid

Else

MsgBox "Error could not get group info"

End If

Set grp = Nothing

Example2 (late binding)

Dim grp, grpMember, lRes

Set grp = CreateObject("ntXdll.GroupManager")
lRes = grp.InitGroups("Machine")

If lRes = 0 Then

For Each grpMember In grp.Groups

MsgBox grpMember.Valid

Next

Else

MsgBox "Error could not get info of groups"

End If

Set grp = Nothing


LastError As Long

Class GroupManager

Tuesday, December 19, 2000

LastError As Long

Property (read only)

Return value

The property returns an error number which is set by different functions and properties of this class. A value of 0 means no error. Otherwise the error number can be a VB or an API error. It is documented in the help of the methods which set this property. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

See also

FormatAPIMessage

Example (late binding)

Dim grp, dll, lRes

Set grp = CreateObject("ntXdll.GroupManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = grp.GetGroupInfo("GroupName", "Machine")

If lRes = 0 And grp.Valid Then

grp.GroupComment = "New comment"

End If

lRes = grp.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set grp = Nothing


Class ModalsManager

Thursday, January 10, 2002

Class ModalsManager

This class uses Win32 network API to query or set properties of user and group modals on the local or a remote system and needs Windows NT® 4.0 Service Pack 4 or higher. User and group modals are information for all users and groups on a system.

To query or set modals properties, you have to initialize a ModalsManager object at first. Function GetModalsInfo initializes a single ModalsManager object, which represents the modals informations on the local or a remote computer. After executing the function without error, you have a Valid ModalsManager object. You can access the properties of the requested user and group modals through the object instance, you called the function GetModalsInfo from.

You can change service ModalsManager by assigning a value of the right type to the property (syntax: <service object>.<property> = <value>). You only can change properties within a Valid ModalsManager object. This means, that you have to initialize a ModalsManager object with the function above.

Read the help to each property, to determine, whether you can change it or whether it is read only.

You get detailed information in the help of each function or property.


GetModalsInfo(...) As Long

Class ModalsManager

Sunday, January 14, 2001

GetShareInfo

([strComputer As String]) As Long

Function

Return value

Returns 0 in case of success, otherwise a nonzero value. This value can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

The function initializes the properties of a ModalsManager object. This means that the properties of a ModalsManager object instance, through which you call this function are filled with the properties of the user modals on a local or remote computer. After executing the function without error, the object instance, you call the function from, is a Valid ModalsManager object.

You have to call this function before you want modifiy modals properties on a computer (example 2).

Parameters

strComputer (optional)
specifies the name of the computer from which you want to get modals informations. Do not use leading backslashs ('\\'). If you omitt the parameter, the local machine is used.

See also

Valid
FormatAPIMessage

Example1 (late binding)

Dim mdl As New ModalsManager
Dim lRes As Long

lRes = mdl.GetModalsInfo("Computername")

If lRes = 0 And mdl.Valid Then

MsgBox mdl.ForceLogoff

End If

Example2 (late binding)

Dim mdl, dll, lRes

Set mdl = CreateObject("ntXdll.ModalsManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = mdl.GetModalsInfo("Machine")

If lRes = 0 And mdl.Valid Then

mdl.ForceLogoff = mdl.TIMEQ_FOREVER

End If

lRes = mdl.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set mdl = Nothing


Computer As String

Class ModalsManager

Sunday, January 14, 2001

Computer As String

Property (read only)

Return value

Returns the computername of a ModalsManager object (without leading backslashs '\\'). This is the name of the computer, on which you want to query or set the modals informations. You only can get Computer within a Valid ModalsManager object. You get a Valid ModalsManager object with function GetModalsInfo of this class.

See also

GetModalsInfo
Valid

Example (query the property from one object, early binding)

Dim mdl As New ModalsManager
Dim lRes As Long

lRes = mdl.GetModalsInfo("Computername")

If lRes = 0 And mdl.Valid Then

MsgBox mdl.Computer

End If


DomainName As String

Class ModalsManager

Sunday, January 14, 2001

DomainName As String

Property (read only)

Return value

Returns the name of the computerdomain of a Valid ModalsManager object. On domain controllers (DC), it is the name of the domain, the computers belong to. On servers and workstations it is the name of the server/workstation (look property Computer of this class).

You only can get DomainName within a Valid ModalsManager object. You get a Valid ModalsManager object with function GetModalsInfo of this class.

See also

GetModalsInfo
Computer
Valid

Example (late binding)

Dim mdl, lRes

Set mdl = CreateObject("ntXdll.ModalsManager")
lRes = mdl.GetModalsInfo("Machine")

If lRes = 0 And mdl.Valid Then

MsgBox mdl.DomainName

Else

MsgBox "Error could not get modals info"

End If

Set mdl = Nothing


ForceLogoff As Long

Class ModalsManager

Sunday, January 14, 2001

ForceLogoff As Long

Property

Return value

Returns or sets the time in seconds between the end of the allowed logon time and the time when the user is forced to log off the network. A value of TIMEQ_FOREVER indicates that the user is never forced to log off. A value of zero indicates that the user will be forced to log off immediately when the valid logon time expires.

You only can get ForceLogoff within a Valid ModalsManager object. You get a Valid ModalsManager object with function GetModalsInfo of this class.

You can set this property only in a Valid ModalsManager object (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

See also

Valid
GetModalsInfo
LastError
TIMEQ_FOREVER
FormatAPIMessage

Example1 (late binding)

Dim mdl As New ModalsManager
Dim lRes As Long

lRes = mdl.GetModalsInfo("Computername")

If lRes = 0 And mdl.Valid Then

MsgBox mdl.ForceLogoff

End If

Example2 (late binding)

Dim mdl, dll, lRes

Set mdl = CreateObject("ntXdll.ModalsManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = mdl.GetModalsInfo("Machine")

If lRes = 0 And mdl.Valid Then

mdl.ForceLogoff = mdl.TIMEQ_FOREVER

End If

lRes = mdl.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set mdl = Nothing


LockoutDuration As Long

Class ModalsManager

Sunday, January 14, 2001

LockoutDuration As Long

Property

Return value

Returns or sets the time in seconds, how long a locked account remains locked before it is automatically unlocked. A value of TIMEQ_FOREVER means, the user is locked until he will be unlocked by an administrator. Don't set this property to 0 (zero).

You only can get LockoutDuration within a Valid ModalsManager object. You get a Valid ModalsManager object with function GetModalsInfo of this class.

You can set this property only in a Valid ModalsManager object (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

See also

Valid
GetModalsInfo
TIMEQ_FOREVER
LastError
FormatAPIMessage

Example1 (late binding)

Dim mdl As New ModalsManager
Dim lRes As Long

lRes = mdl.GetModalsInfo("Computername")

If lRes = 0 And mdl.Valid Then

MsgBox mdl.LockoutDuration

End If

Example2 (late binding)

Dim mdl, dll, lRes

Set mdl = CreateObject("ntXdll.ModalsManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = mdl.GetModalsInfo("Machine")

If lRes = 0 And mdl.Valid Then

mdl.LockoutDuration = mdl.TIMEQ_FOREVER

End If

lRes = mdl.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set mdl = Nothing


LockoutObservationWindow As Long

Class ModalsManager

Sunday, January 14, 2001

LockoutObservationWindow As Long

Property

Return value

Returns or sets the maximum time in seconds, that can elapse between any two failed logon attempts before lockout occurs. You only can get LockoutObservationWindow within a Valid ModalsManager object. You get a Valid ModalsManager object with function GetModalsInfo of this class.

You can set this property only in a Valid ModalsManager object (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

If you set this property to TIMEQ_FOREVER , an user will never be locked, even if there occur many bad logon attempts.

See also

Valid
GetModalsInfo
TIMEQ_FOREVER
LastError
FormatAPIMessage

Example1 (late binding)

Dim mdl As New ModalsManager
Dim lRes As Long

lRes = mdl.GetModalsInfo("Computername")

If lRes = 0 And mdl.Valid Then

MsgBox mdl.LockoutObservationWindow

End If

Example2 (late binding)

Dim mdl, dll, lRes

Set mdl = CreateObject("ntXdll.ModalsManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = mdl.GetModalsInfo("Machine")

If lRes = 0 And mdl.Valid Then

mdl.LockoutObservationWindow = 600

End If

lRes = mdl.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set mdl = Nothing


LockoutThreshold As Long

Class ModalsManager

Sunday, January 14, 2001

LockoutThreshold As Long

Property

Return value

Returns or sets the number of invalid password authentications that can occur before an account is locked out. You only can get LockoutThreshold within a Valid ModalsManager object. You get a Valid ModalsManager object with function GetModalsInfo of this class.

You can set this property only in a Valid ModalsManager object (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

If you set this property to 0 (zero), an user will never be locked, even if there occur many bad logon attempts.

See also

Valid
GetModalsInfo
TIMEQ_FOREVER
LastError
FormatAPIMessage

Example1 (late binding)

Dim mdl As New ModalsManager
Dim lRes As Long

lRes = mdl.GetModalsInfo("Computername")

If lRes = 0 And mdl.Valid Then

MsgBox mdl.LockoutThreshold

End If

Example2 (late binding)

Dim mdl, dll, lRes

Set mdl = CreateObject("ntXdll.ModalsManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = mdl.GetModalsInfo("Machine")

If lRes = 0 And mdl.Valid Then

mdl.LockoutThreshold = 5

End If

lRes = mdl.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set mdl = Nothing


LogonServerRoleStr As String

Class ModalsManager

Sunday, January 14, 2001

LogonServerRoleStr As String

Property (read only)

Return value

Returns the role of the logon server in textual form. You only can get LogonServerRoleStr within a Valid ModalsManager object. You get a Valid ModalsManager object with function GetModalsInfo of this class.

LogonServerRoleStr can be one of the following strings:

'UAS_ROLE_PRIMARY'
'UAS_ROLE_BACKUP'
'UAS_ROLE_STANDALONE'
'UAS_ROLE_MEMBER'

See also

GetModalsInfo
Valid

Example (late binding)

Dim mdl, lRes

Set mdl = CreateObject("ntXdll.ModalsManager")
lRes = mdl.GetModalsInfo("Machine")

If lRes = 0 And mdl.Valid Then

MsgBox mdl.LogonServerRoleStr

Else

MsgBox "Error could not get modals info"

End If

Set mdl = Nothing


MaxPasswordAge As Long

Class ModalsManager

Sunday, January 14, 2001

MaxPasswordAge As Long

Property

Return value

Returns or sets the maximum allowable password age in seconds. A value of TIMEQ_FOREVER indicates that the password never expires. The minimum valid value for this element is ONE_DAY . MaxPasswordAge must be greater than or equal to the property MinPasswordAge

You only can get MaxPasswordAge within a Valid ModalsManager object. You get a Valid ModalsManager object with function GetModalsInfo of this class.

You can set this property only in a Valid ModalsManager object (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

See also

Valid
GetModalsInfo
MinPasswordAge
TIMEQ_FOREVER
ONE_DAY
LastError
FormatAPIMessage

Example1 (late binding)

Dim mdl As New ModalsManager
Dim lRes As Long

lRes = mdl.GetModalsInfo("Computername")

If lRes = 0 And mdl.Valid Then

MsgBox mdl.MaxPasswordAge

End If

Example2 (late binding)

Dim mdl, dll, lRes

Set mdl = CreateObject("ntXdll.ModalsManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = mdl.GetModalsInfo("Machine")

If lRes = 0 And mdl.Valid Then

mdl.MaxPasswordAge = 32 * mdl.ONE_DAY

End If

lRes = mdl.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set mdl = Nothing


MinPasswordAge As Long

Class ModalsManager

Sunday, January 14, 2001

MinPasswordAge As Long

Property

Return value

Returns or sets the minimum number of seconds that can elapse between the time a password changes and when it can be changed again. A value of 0 (zero) indicates that no delay is required between password updates. MinPasswordAge must be less than or equal to property MaxPasswordAge .

You only can get MinPasswordAge within a Valid ModalsManager object. You get a Valid ModalsManager object with function GetModalsInfo of this class.

You can set this property only in a Valid ModalsManager object (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

See also

Valid
GetModalsInfo
MaxPasswordAge
TIMEQ_FOREVER
ONE_DAY
LastError
FormatAPIMessage

Example1 (late binding)

Dim mdl As New ModalsManager
Dim lRes As Long

lRes = mdl.GetModalsInfo("Computername")

If lRes = 0 And mdl.Valid Then

MsgBox mdl.MinPasswordAge

End If

Example2 (late binding)

Dim mdl, dll, lRes

Set mdl = CreateObject("ntXdll.ModalsManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = mdl.GetModalsInfo("Machine")

If lRes = 0 And mdl.Valid Then

mdl.MinPasswordAge = mdl.ONE_DAY

End If

lRes = mdl.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set mdl = Nothing


MinPasswordLen As Long

Class ModalsManager

Sunday, January 14, 2001

MinPasswordLen As Long

Property

Return value

Returns or sets the minimum allowable password length. The property cannot be longer than 256.

You only can get MinPasswordLen within a Valid ModalsManager object. You get a Valid ModalsManager object with function GetModalsInfo of this class.

You can set this property only in a Valid ModalsManager object (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

See also

Valid
GetModalsInfo
LastError
FormatAPIMessage

Example1 (late binding)

Dim mdl As New ModalsManager
Dim lRes As Long

lRes = mdl.GetModalsInfo("Computername")

If lRes = 0 And mdl.Valid Then

MsgBox mdl.MinPasswordLen

End If

Example2 (late binding)

Dim mdl, dll, lRes

Set mdl = CreateObject("ntXdll.ModalsManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = mdl.GetModalsInfo("Machine")

If lRes = 0 And mdl.Valid Then

mdl.MinPasswordLen = 7

End If

lRes = mdl.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set mdl = Nothing


PasswordHistLen As Long

Class ModalsManager

Sunday, January 14, 2001

PasswordHistLen As Long

Property

Return value

Returns or sets the length of password history maintained. A new password cannot match any of the previous PasswordHistLen passwords.

You only can get PasswordHistLen within a Valid ModalsManager object. You get a Valid ModalsManager object with function GetModalsInfo of this class.

You can set this property only in a Valid ModalsManager object (example 2). If there occurs an error while setting the property, LastError of this class is set to an error number. This error number can be a VB or an API error. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

See also

Valid
GetModalsInfo
LastError
FormatAPIMessage

Example1 (late binding)

Dim mdl As New ModalsManager
Dim lRes As Long

lRes = mdl.GetModalsInfo("Computername")

If lRes = 0 And mdl.Valid Then

MsgBox mdl.PasswordHistLen

End If

Example2 (late binding)

Dim mdl, dll, lRes

Set mdl = CreateObject("ntXdll.ModalsManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = mdl.GetModalsInfo("Machine")

If lRes = 0 And mdl.Valid Then

mdl.PasswordHistLen = 8

End If

lRes = mdl.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set mdl = Nothing


PDCName As String

Class ModalsManager

Sunday, January 14, 2001

PDCName As String

Property (read only)

Return value

Returns the name of the domain controller that stores the primary copy of the database for the user account manager. You only can get PDCName within a Valid ModalsManager object. You get a Valid ModalsManager object with function GetModalsInfo of this class.

See also

GetModalsInfo
Valid

Example (late binding)

Dim mdl, lRes

Set mdl = CreateObject("ntXdll.ModalsManager")
lRes = mdl.GetModalsInfo("Machine")

If lRes = 0 And mdl.Valid Then

MsgBox mdl.PDCName

Else

MsgBox "Error could not get modals info"

End If

Set mdl = Nothing


Valid As Boolean

Class ModalsManager

Sunday, January 14, 2001

Valid As Boolean

Property (read only)

Return value

Returns whether a ModalsManager object represents the existing user modals informations on a local or remote computer.

To get the property, you have to init the properties of a ModalsManager object at first with function GetModalsInfo of this class. If you have executed this function without error, all properties of the ModalsManager objects are filled with information and all of these objects represent existing modals informations.

The most properties of this class, which are not read only, require a Valid ModalsManager object.

See also

GetModalsInfo

Example1 (late binding)

Dim mdl As New ModalsManager
Dim lRes As Long

lRes = mdl.GetModalsInfo("Computername")

If lRes = 0 And mdl.Valid Then

MsgBox mdl.MinPasswordAge

End If

Example2 (late binding)

Dim mdl, dll, lRes

Set mdl = CreateObject("ntXdll.ModalsManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = mdl.GetModalsInfo("Machine")

If lRes = 0 And mdl.Valid Then

mdl.MinPasswordAge = mdl.ONE_DAY

End If

lRes = mdl.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set mdl = Nothing


LastError As Long

Class ModalsManager

Sunday, January 14, 2001

LastError As Long

Property (read only)

Return value

The property returns an error number which is set by different functions and properties of this class. A value of 0 means no error. Otherwise the error number can be a VB or an API error. It is documented in the help of the methods which set this property. To get the description of the error, use function FormatAPIMessage of class DllClass (see the example).

See also

FormatAPIMessage

Example (late binding)

Dim mdl, dll, lRes

Set mdl = CreateObject("ntXdll.ModalsManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = mdl.GetModalsInfo("Machine")

If lRes = 0 And mdl.Valid Then

mdl.ForceLogoff = mdl.TIMEQ_FOREVER

End If

lRes = mdl.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set mdl = Nothing


ONE_DAY As Long

Class ModalsManager

Sunday, January 14, 2001

ONE_DAY

As Long

Property (read only)

Return value

The property is used like a constant to set some properties of this class, which are counted in seconds (property MaxPasswordAge for example). For further informations, read the help to this properties.

The meaning:

ONE_DAY
is the number of seconds on one day

Example (late binding)

Dim mdl, dll, lRes

Set mdl = CreateObject("ntXdll.ModalsManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = mdl.GetModalsInfo("Machine")

If lRes = 0 And mdl.Valid Then

mdl.MaxPasswordAge = 32 * mdl.ONE_DAY

End If

lRes = mdl.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set mdl = Nothing


TIMEQ_FOREVER As Long

Class ModalsManager

Sunday, January 14, 2001

TIMEQ_FOREVER

As Long

Property (read only)

Return value

The property is used like a constant to get or set some properties of this class, which are counted in seconds (property MaxPasswordAge for example). For further informations, read the help to this properties (you can use the search function of the help to find out the properties).

The meaning:

TIMEQ_FOREVER
the value is -1

Example (late binding)

Dim mdl, dll, lRes

Set mdl = CreateObject("ntXdll.ModalsManager")
Set dll = CreateObject("ntXdll.DllClass")
lRes = mdl.GetModalsInfo("Machine")

If lRes = 0 And mdl.Valid Then

mdl.ForceLogoff = mdl.TIMEQ_FOREVER

End If

lRes = mdl.LastError
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, Error(lRes)), "netmsg.dll")
Set mdl = Nothing


Class LocalSecurer

Wednesday, November 28, 2001

Class LocalSecurer

Class LocalSecurer provides some properties and methods, which enable the user of ntXdll to enumerate, add or remove user rights (privileges) on local or remote computers.

The class uses the ANSI versions of the Windows NT lsa APIs.

The best way to enumerate privileges and their members on a computer is to execute the function InitPolicies of this class. This function initializes the collection Policies of this class. Each Valid member of the collection represents an accounts, which is assigned to the specified privilege.

Privileges are an additional way to assign rights to users and groups. If you add or remove an account to or from a privilege, the account has to logoff and logon, so that the changes teake effect.

You can add an account to a privilege with function AddPolicyRight and remove an account from a privilege with function DeletePolicyRight . Function AddPolicyRight needs no parameters because you have to set some properties of the class before you can execute the function. You can set LocalSecurer properties by assigning a value of the right type to the property (syntax: <service object>.<property> = <value>). After executing the function without error, the object, you called the function from, is a Valid LocalSecurer object.

You can use the SE_* properties of class process, to see, which privileges are supported from ntXdll.

There are some additional functions, which you can use seperate and which require no Valid LocalSecurer objects. These functions are:

DeletePolicyRight
GetPolicyStrings

You get detailed information in the help of each function or property of the class.


Initpolicies(...) As Long

Class LocalSecurer

Sunday, December 02, 2001

InitPolicies

(strPolicy As String,
[strMachine As String])

As Long

Function

Return value

Returns 0 in case of success, otherwise a non zero value, which can be an Visual Basic Error, an internal Error or an error from an API. You can use function FormatAPIMessage of class DllClass, to convert an API message to a string. The function initializes the collection Policies of a LocalSecurer object and all of it's properties. This means that the properties of each member of this collection, which represents a privilege on a local or remote machine and an account, that belongs to it, are filled with information.

The collection Policies can only be initialized for one privilege, you assign with parameter strPolicy. Then, the collection contains so much members as accounts are assigned to this privilege. After you have executed the function without error, you have a collection of Valid LocalSecurer objects.

The function returns an error, if no account is granted to the specified privilege. After executing the function, you can use the method Policies .Count to determine the number of collection members.

Parameters

strPolicy
Specifies the policy, of which you want to get the members. You can use one of the SE_* properties of class Process to see, which policies are supported from ntXdll (see the example). You only can use one of these properties for one call of the function.

strMachine (optional)
Specifies the name of the computer, from which you want to query the policy (without backslashs). If you omitt the parameter, the local machine is used.

See also:

Policies
Valid
SE_* properties
Computer
PolicyAccount
PolicyAccountDomain
PolicyAccountType
PolicyString
FormatAPIMessage

Example (early binding)

Dim proc As New Process
Dim dll As New DllClass
Dim lRes As Long
Dim lsa As New LocalSecurer, lsaMember As LocalSecurer

lRes = lsa.InitPolicies(proc.SE_SYSTEMTIME_NAME, "RemoteComputer")
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes), "netmsg.dll"))

If lsa.Policies.Count = 0 Then

MsgBox "No account is granted to this privilege"

End If

For Each lsaMember In lsa.Policies

With lsaMember

Debug.Print .PolicyString
Debug.Print .PolicyAccountDomain & "\" & .PolicyAccount
Debug.Print .PolicyAccountType
Debug.Print .Computer
Debug.Print .Valid
Debug.Print "---------------------------------------------"

End With

Next


Policies As Collection

Class LocalSecurer

Tuesday, December 04, 2001

Policies As Collection

Property (read only)

Return value

Returns a collection of LocalSecurer objects. It is initialized with function InitPolicies of this class. The collection represents a user right on a local or remote computer with all accounts, which are assigned to this right. There are no actions possible to the properties of the collection members. You only can use the members to query the values.

Only the Policy* properties and the properties Computer and Valid are initialized within the collection members.

All collection members are indexed with <domainname>\<username> or <username> if property PolicyAccountDomain is empty. In VB or VBA or VBScript, you can access the properties of the collection members over the 'For Each ...' construct.

If you execute InitPolicies without error to fill the collection, all members are Valid LocalSecurer objects.

See also

InitPolicies
Valid
PolicyAccountDomain

Example (late binding)

Dim lsa, lsaMember
Dim proc
Dim lRes

Set lsa = CreateObject("ntXdll.LocalSecurer")
Set proc = CreateObject("ntXdll.Process")

lRes = lsa.InitPolicies(proc.SE_SYSTEMTIME_NAME, "RemoteComputer")
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes), "netmsg.dll"))

For Each lsaMember In lsa.Policies

With lsaMember

MsgBox .PolicyString
MsgBox .PolicyAccountDomain & "\" & .PolicyAccount
MsgBox .PolicyAccountType
MsgBox .Computer
MsgBox .Valid
MsgBox "------------------------------------"

End With

Next


PolicyString As String

Class LocalSecurer

Tuesday, December 04, 2001

PolicyString As String

Property

Return value

Returns or sets the string, which contains the userright (privilege or policy) on a local or remote machine. To determine, which strings are supported by ntXdll, you can use the SE_* properties of class Process (see example 1). The property cannot be an empty string.

You only can get PolicyString within a Valid LocalSecurer object. You get Valid LocalSecurer objects with function InitPolicies of this class (example 2).

You only can set this property within a non Valid LocalSecurer object in order to add a new account to a userright on the local or a remote computer with function AddPolicyRight (example 1).

To get or set the account, which should be assigned to a privilege, use property PolicyAccount of this class.

See also

Valid
InitPolicies
PolicyAccount
AddPolicyRight

Example1 (early binding) - setting the property

Dim lRes As Long
Dim dll As New DllClass
Dim proc As New Process
Dim ls As New LocalSecurer

'ls is a new, non valid LocalSecurer object
ls.PolicyAccount = "AccountName"
ls.PolicyString = proc.SE_MACHINE_ACCOUNT_NAME
ls.Computer = "RemoteComputer"
disabling the next command, because the function should search for the domain
ls.PolicyAccountDomain = "DomainName"

'after the execution of AddPolicyRight without error,
'ls will be a valid LocalSecurerObject
lRes = ls.AddPolicyRight
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes), "netmsg.dll"))

MsgBox ls.Computer
MsgBox ls.PolicyAccount
MsgBox ls.PolicyAccountDomain
MsgBox ls.PolicyString
MsgBox ls.PolicyAccountType
MsgBox ls.Valid

'deleting the object, so that you can call the function again,
'because the properties can only be set within a non valid object
Set ls = Nothing

Example2 (late binding) - querying the property

Dim proc As Object
Dim dll As Object
Dim lRes As Long
Dim lsa As Object, lsaMember As Object

Set proc = CreateObject("ntXdll.Process")
Set dll = CreateObject("ntXdll.DllClass")
Set lsa = CreateObject("ntXdll.LocalSecurer")

lRes = lsa.InitPolicies(proc.SE_SYSTEMTIME_NAME, "RemoteComputer")
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes), "netmsg.dll"))

If lsa.Policies.Count = 0 Then

MsgBox "No account is granted to this privilege"

End If

For Each lsaMember In lsa.Policies

With lsaMember

Debug.Print .PolicyString
Debug.Print .PolicyAccountDomain & "\" & .PolicyAccount
Debug.Print .PolicyAccountType
Debug.Print .Computer
Debug.Print .Valid
Debug.Print "---------------------------------------------"

End With

Next


PolicyAccount As String

Class LocalSecurer

Tuesday, December 04, 2001

PolicyAccount As String

Property

Return value

Returns or sets the string, which contains the name of an account, that is assigned to a LocalSecurer object (which represents a user right). This account can be a user or a group. It cannot be an empty string. You only can get PolicyAccount within a Valid LocalSecurer object. You get Valid LocalSecurer objects with function InitPolicies of this class (example 2).

You only can set this property within a non Valid LocalSecurer object in order to add a new account to a userright on the local or a remote computer with function AddPolicyRight (example 1). You cannot set this property for multiple userrights.

To get or set the domain, where the account exists, use property PolicyAccountDomain of this class.

See also

Valid
InitPolicies
PolicyAccountDomain
AddPolicyRight

Example1 (early binding) - setting the property

Dim lRes As Long
Dim dll As New DllClass
Dim proc As New Process
Dim ls As New LocalSecurer

'ls is a new, non valid LocalSecurer object
ls.PolicyAccount = "AccountName"
ls.PolicyString = proc.SE_MACHINE_ACCOUNT_NAME
ls.Computer = "RemoteComputer"
'disabling the next command, because the function should search for the domain
'ls.PolicyAccountDomain = "DomainName"

lRes = ls.AddPolicyRight
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes), "netmsg.dll"))

MsgBox ls.Computer
MsgBox ls.PolicyAccount
MsgBox ls.PolicyAccountDomain
MsgBox ls.PolicyString
MsgBox ls.PolicyAccountType
MsgBox ls.Valid

'deleting the object, so that you can call the function again,
'because the properties can only be set within a non valid object
Set ls = Nothing

Example2 (late binding) - querying the property

Dim proc As Object
Dim dll As Object
Dim lRes As Long
Dim lsa As Object, lsaMember As Object

Set proc = CreateObject("ntXdll.Process")
Set dll = CreateObject("ntXdll.DllClass")
Set lsa = CreateObject("ntXdll.LocalSecurer")

lRes = lsa.InitPolicies(proc.SE_SYSTEMTIME_NAME, "RemoteComputer")
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes), "netmsg.dll"))

If lsa.Policies.Count = 0 Then

MsgBox "No account is granted to this privilege"

End If

For Each lsaMember In lsa.Policies

With lsaMember

Debug.Print .PolicyString
Debug.Print .PolicyAccountDomain & "\" & .PolicyAccount
Debug.Print .PolicyAccountType
Debug.Print .Computer
Debug.Print .Valid
Debug.Print "---------------------------------------------"

End With

Next


PolicyAccountDomain As String

Class LocalSecurer

Tuesday, December 04, 2001

PolicyAccountDomain As String

Property

Return value

Returns or sets the string, which contains the name of the domain, where the account exists, that is assigned to a LocalSecurer object (which represents a user right). It can be an empty string, if the account is well known (like'Everyone').

You only can get PolicyAccountDomain within a Valid LocalSecurer object. You get Valid LocalSecurer objects with function InitPolicies of this class (example 2).

You only can set this property within a non Valid LocalSecurer object in order to add a new account to a userright on the local or a remote computer with function AddPolicyRight (example 1). You cannot set this property for multiple userrights. If you do not set this property, when you add an account with function AddPolicyRight , the function searches in the following order for the account: the local computer or the remote computer, where the function is executed, the primary domain, trusted domains. After the execution of AddPolicyRight , the property will be completed by the function (but it is an empty string for well known accounts).

To get or set the account, which is assigned to an userright, use property PolicyAccount of this class.

See also

Valid
InitPolicies
PolicyAccount
AddPolicyRight

Example1 (early binding) - setting the property

Dim lRes As Long
Dim dll As New DllClass
Dim proc As New Process
Dim ls As New LocalSecurer

'ls is a new, non valid LocalSecurer object
ls.PolicyAccount = "AccountName"
ls.PolicyString = proc.SE_MACHINE_ACCOUNT_NAME
ls.Computer = "RemoteComputer"
'disabling the next command, because the function should search for the domain
'if PolicyAccount is an well known account, the property will be empty even after
'the execution of AddPolicyRight
'ls.PolicyAccountDomain = "DomainName"

lRes = ls.AddPolicyRight
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes), "netmsg.dll"))

MsgBox ls.Computer
MsgBox ls.PolicyAccount
MsgBox ls.PolicyAccountDomain
MsgBox ls.PolicyString
MsgBox ls.PolicyAccountType
MsgBox ls.Valid

'deleting the object, so that you can call the function again,
'because the properties can only be set within a non valid object
Set ls = Nothing

Example2 (late binding) - querying the property

Dim proc
Dim dll
Dim lRes
Dim lsa, lsaMember

Set proc = CreateObject("ntXdll.Process")
Set dll = CreateObject("ntXdll.DllClass")
Set lsa = CreateObject("ntXdll.LocalSecurer")

lRes = lsa.InitPolicies(proc.SE_SYSTEMTIME_NAME, "RemoteComputer")
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes), "netmsg.dll"))

If lsa.Policies.Count = 0 Then

MsgBox "No account is granted to this privilege"

End If

For Each lsaMember In lsa.Policies

With lsaMember

Debug.Print .PolicyString
Debug.Print .PolicyAccountDomain & "\" & .PolicyAccount
Debug.Print .PolicyAccountType
Debug.Print .Computer
Debug.Print .Valid
Debug.Print "---------------------------------------------"

End With

Next


PolicyAccountType As String

Class LocalSecurer

Tuesday, December 04, 2001

PolicyAccountType As String

Property (read only)

Return value

Returns the string, which contains the type of the account, that is assigned to a LocalSecurer object (which represents a user right). It can only be one of the following strings:

"AccTypeUser"
"AccTypeGroup"
"AccTypeAlias"
"AccTypeWellKnownGroup"
"AccTypeDeletedAccount"
"AccTypeInvalid"
"AccTypeUnknown"

You only can get PolicyAccountType within a Valid LocalSecurer object. You get Valid LocalSecurer objects with function InitPolicies of this class (example 2).

You cannot set the property. If you add an account to an userright with function AddPolicyRight of this class (example 1), the property will be completed by the function automatically.

To get or set the account, which is assigned to an userright, use property PolicyAccount of this class.

See also

Valid
InitPolicies
PolicyAccount
AddPolicyRight

Example1 (early binding) - setting the property

Dim lRes As Long
Dim dll As New DllClass
Dim proc As New Process
Dim ls As New LocalSecurer

'ls is a new, non valid
    LocalSecurer object
ls.PolicyAccount = "AccountName"
ls.PolicyString = proc.SE_MACHINE_ACCOUNT_NAME
ls.Computer = "RemoteComputer"
ls.PolicyAccountDomain = "DomainName"

'after the execution of AddPolicyRight without error,
'ls will be a valid LocalSecurerObject
lRes = ls.AddPolicyRight
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes), "netmsg.dll"))

MsgBox ls.Computer
MsgBox ls.PolicyAccount
MsgBox ls.PolicyAccountDomain
MsgBox ls.PolicyString
MsgBox ls.PolicyAccountType
MsgBox ls.Valid

'deleting the object, so that you can call the function again,
'because the properties can only be set within a non valid object
Set ls = Nothing

Example2 (late binding) - querying the property

Dim proc
Dim dll
Dim lRes
Dim lsa, lsaMember

Set proc = CreateObject("ntXdll.Process")
Set dll = CreateObject("ntXdll.DllClass")
Set lsa = CreateObject("ntXdll.LocalSecurer")

lRes = lsa.InitPolicies(proc.SE_SYSTEMTIME_NAME, "RemoteComputer")
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes), "netmsg.dll"))

If lsa.Policies.Count = 0 Then

MsgBox "No account is granted to this privilege"

End If

For Each lsaMember In lsa.Policies

With lsaMember

Debug.Print .PolicyString
Debug.Print .PolicyAccountDomain & "\" & .PolicyAccount
Debug.Print .PolicyAccountType
Debug.Print .Computer
Debug.Print .Valid
Debug.Print "---------------------------------------------"

End With

Next


Computer As String

Class LocalSecurer

Saturday, December 01, 2001

Computer As String

Property

Return value

Returns (example 1) or sets the computername of a LocalSecurer object (do not use leading backslashs '\\'). This is the name of the computer, where the local security policy exists. You only can set this property, if the LocalSecurer object is not valid (property Valid of this class), for example, if you want to add an account to a user right on a remote machine with function AddPolicyRight (example 2).

To get the property, you have to init the properties of a LocalSecurer object at first with function InitPolicies of this class. In this version of ntXdll, you only can access the property through the collection Policies of this class.

See also

InitPolicies
Policies
AddPolicyRight
Valid

Example1 (query the property from one object, early binding)

Dim lsa As New
    LocalSecurer
Dim lsaMember As LocalSecurer
Dim proc As New Process
Dim lRes As Long

lRes = lsa.InitPolicies(proc.SE_SYSTEMTIME_NAME, "RemoteComputer")
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes), "netmsg.dll"))

For Each lsaMember In lsa.Policies

With lsaMember

Debug.Print .PolicyString
Debug.Print .PolicyAccountDomain & "\" & .PolicyAccount
Debug.Print .PolicyAccountType
Debug.Print .Computer
Debug.Print .Valid
Debug.Print "------------------------------------"

End With

Next

Example2 (setting the property, late binding)

Dim lRes
Dim dll
Dim proc
Dim ls

Set dll = CreateObject("ntXdll.DllClass")
Set proc = CreateObject("ntXdll.Process")
Set ls = CreateObject("ntXdll.LocalSecurer")

ls.PolicyAccount = "AccountName"
ls.PolicyString = proc.SE_MACHINE_ACCOUNT_NAME
ls.Computer = "RemoteComputer"

lRes = ls.AddPolicyRight
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes), "netmsg.dll"))

MsgBox ls.Computer
MsgBox ls.PolicyAccount
MsgBox ls.PolicyAccountDomain
MsgBox ls.PolicyString


Valid As Boolean

Class LocalSecurer

Saturday, December 01, 2001

Valid As Boolean

Property (read only)

Return value

Returns whether a LocalSecurer object represents an existing privilege object (a privilege with an account, that belongs to it).

To get the property, you have to init the properties of a LocalSecurer object at first with function InitPolicies of this class. If you have executed this function without error, all properties of the member objects of the collection Policies are filled with information and all of these objects represent existing policies. You also get a Valid LocalSecurer object by adding an account to a user right with function AddPolicyRight of this class.

See also

GetUserInfo
InitUsers
Create
Users

Example1 (late binding)

Dim usr, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.GetUserInfo("UserName", "MachineName")

If lRes = 0 And usr.Valid Then

MsgBox "UserName is a valid user"

Else

MsgBox "Error could not get user info"

End If

Set usr = Nothing

Example2 (late binding)

Dim usr, usrMember, lRes

Set usr = CreateObject("ntXdll.UserManager")
lRes = usr.InitUsers("Machine")

If lRes = 0 Then

For Each usrMember In usr.Users

MsgBox usrMember.Valid

Next

Else

MsgBox "Error could not get info of users"

End If

Set usr = Nothing


AddPolicyRight(...) As Long

Class LocalSecurer

Saturday, December 01, 2001

AddPolicyRight () As Long

Function

Return value

Returns 0 in case of success, otherwise a non zero value, which can be an Visual Basic Error, an internal Error or an error from an API. You can use function FormatAPIMessage of class DllClass, to convert an API message to a string. The function adds an account to a user right on the local or a remote computer. If the specified user (or a user of the specified group) is logged on a computer, the user has to log on again, so that the changes take effect.

The function needs no parameters, because you have to set some properties of this class, before you can execute the function. You can set these properties only within a non Valid LocalSecurer object. After executing the function without errors, the LocalSecurer object, within you called the function, is a Valid LocalSecurer object. The following properties are supported from the function:

Properties, you have to set before calling the function:

PolicyString
Required. Specifies the policy, to which the account should be added. You can use one of the SE_* properties of class Process to see, which policies are supported from ntXdll (see the example). You only can use one of these properties for one call of the function.

PolicyAccount
Required. Specifies the name of the account, which is to add to the policy. This can be an user- or a group-account. The account must be known on the target computer. This means for example, that only local or domain users can be used. This includes accounts of trusted domains.

PolicyAccountDomain (optional)
Specifies the domain, the account belongs to. If you do not set this property, the function searches in the following order for the account: the local machine, the primary domain, trusted domains. If you specifiy a domain, the function tries to search for the account on the domain controller of this domain. This should be the primary or a trusted domain.

Computer (optional)
Specifies the name of the computer, on which policy should be changed. The property also specifies the computer, on which the search for the account is performed from the function. If you do not set this property, the local machine is used.

Remarks

The function does not return an error, if the account already has the specified privilege.
If you do not set some of the optional properties, the properties will be filled with information after a successfull call of the function. Then, property PolicyAccountDomain contains the name of the domain, where the account was found. Also, the rest of the properties are set and contain valid information ( PolicyAccountType , Valid ).

If you have created a collection of LocalSecurer objects with function InitPolicies of this class, before you execute AddPolicyRight, the collection will not be refreshed automatically after executing the function. You have to call InitPolicies again.

See also:

PolicyString
PolicyAccount
PolicyAccountDomain
Computer
PolicyAccountType
Valid
SE_* properties
DeletePolicyRight
InitPolicies
FormatAPIMessage

Example (early binding)

Dim lRes As Long
Dim dll As New DllClass
Dim proc As New Process
Dim ls As New LocalSecurer

ls.PolicyAccount = "AccountName"
ls.PolicyString = proc.SE_MACHINE_ACCOUNT_NAME
ls.Computer = "RemoteComputer"
'disabling the next command, because the function should search for the domain
'ls.PolicyAccountDomain = "DomainName"

lRes = ls.AddPolicyRight
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes), "netmsg.dll"))

MsgBox ls.Computer
MsgBox ls.PolicyAccount
MsgBox ls.PolicyAccountDomain
MsgBox ls.PolicyString
MsgBox ls.PolicyAccountType
MsgBox ls.Valid

'deleting the object, so that you can call the function again,
'because the properties can only be set within a non valid object
Set ls = Nothing


DeletePolicyRight(...) As Long

Class LocalSecurer

Saturday, December 01, 2001

DeletePolicyRight

(strPolicy As String,
strAccount As String,
[strDomain As String],
[strMachine As String])

As Long

Function

Return value

Returns 0 in case of success, otherwise a non zero value, which can be an Visual Basic Error, an internal error of ntXdll or an error from an API. You can use function FormatAPIMessage of class DllClass, to convert an API message to a string. The function removes an account from a user right on the local or a remote computer. If the specified user (or a user of the specified group) is logged on a computer, the user has to log on again, so that the changes take effect.

You can execute the function within a Valid or a non Valid LocalSecurer object, because no properties of the class are effected from the execution.

Parameters

strPolicy
Required. Specifies the policy, from which the account should be removed. You can use one of the SE_* properties of class Process to see, which policies are supported from ntXdll (see the example). You only can use one of these properties for one call of the function.

strAccount
Required. Specifies the name of the account, which is to remove from the policy. This can be an user- or a group-account. The account must be known on the target computer. This means for example, that only local or domain users can be used. This includes accounts of trusted domains.

strDomain (optional)
Specifies the domain, the account belongs to. If you omitt the parameter, the function searches in the following order for the account: the local machine, the primary domain, trusted domains. If you specifiy a domain, the function tries to search for the account on the domain controller of this domain. This should be the primary or a trusted domain.

strMachine (optional)
Specifies the name of the computer (without backslashs), on which policy should be changed. The parameter also specifies the computer, on which the search for the account is performed from the function. If you omitt the parameter, the local machine is used.

Remarks

The function does not return an error, if the account already is removed from the user right (privilege).
If you do not set some of the optional properties, the properties will be filled with information after a successfull call of the function.

If you have created a collection of LocalSecurer objects with function InitPolicies of this class, before you execute DeletePolicyRight, the collection will not be refreshed automatically after executing the function. You have to call InitPolicies again.

See also:

Valid
SE_* properties
InitPolicies
FormatAPIMessage
AddPolicyRight

Example (late binding)

Dim lRes
Dim dll
Dim proc
Dim ls

Set dll = CreateObject("ntXdll.DllClass")
Set proc = CreateObject("ntXdll.Process")
Set ls = CreateObject("ntXdll.LocalSecurer")

lRes = ls.DeletePolicyRight(proc.SE_MACHINE_ACCOUNT_NAME, "AccountName", "AccountDomain", "RemoteComputer")
MsgBox dll.FormatAPIMessage(lRes, dll.FormatAPIMessage(lRes, CStr(lRes), "netmsg.dll"))


GetPolicyStrings(...) As String

Class LocalSecurer

Saturday, December 01, 2001

GetPolicyStrings

([strSeperator As String])

As String

Function

Return value

The function returns all strings, which represent a from ntXdll supported privilege. The function has no error handling. You can execute the function within a Valid or a non Valid LocalSecurer object, because no properties of the class are effected from the execution.

Parameters

strSeperator (optional)
Within the returned string, all privileges are seperated by a string, you assign to this parameter. If you omitt the parameter, a semicolon is used.

Remarks

You can use the function, to search for an account through all privileges on a computer. This means, you can search for all privileges, an account belongs to (see the example 2).

See also:

Valid
SE_* properties
InitPolicies
FormatAPIMessage

Example1 - messaging all privileges (late binding)

Dim lsa

Set lsa = CreateObject("ntXdll.LocalSecurer")

'using a carriage return as seperator
MsgBox lsa.GetPolicyStrings(vbCr)

Example2 - searching through all privileges (early binding)

Dim proc As New Process, dll As New DllClass
Dim lRes As Long
Dim lsa As New LocalSecurer, lsaMember As LocalSecurer
Dim s As New Stringer, sMember As Stringer
Dim strg As String, sep As String, sAccount As String

sep = ";"
sAccount = "Administrator"

strg = lsa.GetPolicyStrings(sep)

lRes = s.InitSeperator(strg, sep, False)
MsgBox lRes

For Each sMember In s.SepStrings

lRes = lsa.InitPolicies(sMember.SepString, "RemoteComputer")
MsgBox lRes
If lsa.Policies.Count = 0 Then

MsgBox "No accounts have privilege " & sMember.SepString

End If

For Each lsaMember In lsa.Policies

If lsaMember.PolicyAccount = sAccount Then

MsgBox sAccount & " is granted to privilege " & lsaMember.PolicyString

End If

Next

Next


Support and Warranty

Friday, January 26, 2001

Support and Warranty

ntXdll is released for Windows NT® (4.0 SP4 or higher). It will be released for Windows 2000® in a later version.

I make no warranty for that there are no bugs in ntXdll. I refuse Liability for any damages due to unqualified usage (incidental or consequential) or due to unknown and unfixed bugs.

But I suppose, that a prospective buyer has downloaded the demo version before ordering and has tested it for his purpose.Considering this, I cannot satisfy any claim to return the software.

I thank for any suggestion which improves the software and for any detection of a bug. I will take them in next versions as soon as possible. Technical questions will be answered as soon as possible.

support@kleinetools.de

Frank Seidel
12/09/2000


Support und Gewährleistung

Friday, January 26, 2001

Support und Gewährleistung

ntXdll ist für Windows NT® 4.0 (SP4 oder höher) freigegeben. Die Freigabe für Windows 2000® wird mit einer späteren Version erfolgen.

Für die Fehlerfreiheit des Produkts wird keine Garantie übernommen. Jegliche Haftung für Schäden wird ausgeschlossen (sei es durch unsachgemäßen Gebrauch (versehentlich oder mit Absicht) oder durch unbekannte, noch nicht behobene Fehler im Produkt). Zu Testzwecken kann jederzeit eine Demoversion heruntergeladen werden.

Ich gehe davon aus, dass sich Interessenten vor einer Bestellung die Demoversion heruntergeladen und sich einen Eindruck von der Brauchbarkeit des Produkts für ihre Bedüfnisse gemacht haben. In Anbetracht der Möglichkeit, das Produkt vorher zu testen, können keine Rückgabeansprüche geltend gemacht werden.

Ich bin für jede Anregung und jede Offenlegung eines Fehlers dankbar und werde diese schnellstmöglich in nachfolgenden Versionen berücksichtigen. Technische Fragen werden schnellstmöglich beantwortet.

support@kleinetools.de

Frank Seidel
09.12.2000


Licensing

Friday, January 12, 2001

Licensing

Demoversion

The demo version of ntXdll, which is available for download on the ntXdll site of www.kleinetools.de or other sites or resources is free to use for evaluating the software but not for commercial purposes.

You can get the full version by ordering on www.kleinetools.de . Then you get a license keyfile 'keyfile.ntx'. This file upgrades the demo version, which was downloaded on the site above, to a full version. Later versions can be used with old keyfiles a certain time.

Full Version

ntXdll is licensed for usage or developing on only one computer at a time. Any usage of one license on more than one computer at a time is strictly prohibited (this includes copies on a network resource for simultaneous usage on more computers than licenses exist). Any copies made of ntXdll are only allowed for backing up the product or the software to which ntXdll is bound.

Each developer, using the product or developing on a project, which includes ntXdll needs one license to work with it. ntXdll may be royalty free distributed with software, to which ntXdll is bounded in such way as seperat use is prohibited. Developers may distribute ntXdll only in conjunction with their own software and not as itself.

Each administrator or other employee using ntXdll to administer or document a NT domain or any other NT machines local or on the network, needs one license for each computer on which ntXdll is used (even if ntXdll is used only through automatic scripts).

The license may be transferred - provided that it will be no more used for own purposes.

It is not possible, to share licenses with another person or company (for example John shares a 100 Units license with Tom).

Any attempt for decompiling and modifying the software for commercial purpose is expressly prohibited.

Frank Seidel
12/09/2000


Lizenzierung

Friday, January 12, 2001

Lizenzierung

Demoversion

Die Demoversion von ntXdll, die von der ntXdll Seite auf www.kleinetools.de heruntergeladen wurde oder auch von anderen Internetseiten oder anderen Quellen bezogen wurde kann zu Testzwecken frei ohne Lizenzgebühr genutzt werden. Kommerzielle Nutzung der Demoversion ist dagegen untersagt.

Sie bekommen die Vollversion nach einer Bestellung über www.kleinetools.de . Sie erhalten dann eine Lizenzdatei 'keyfile.ntx', welche die vorher heruntergeladene Demoversion in eine Vollversion umwandelt. Spätere Versionen sind eine Zeit lang mit bestehenden Lizenzdateien gültig.

Vollversion

ntXdll ist für die Entwicklung von Software oder anderen EDV-technischen Zwecken pro Computerarbeitsplatz lizenziert. Die Nutzung einer einzigen Lizenz auf mehreren Computern zur gleichen Zeit ist untersagt (dies betrifft auch Kopien auf Netzwerkressourcen, die von mehreren Arbeitsplätzen aus erreichbar sind). Kopien der Software sind lediglich zu Backupzwecken erlaubt.

Jeder Softwareentwickler, der ntXdll nutzt oder an einem Projekt arbeitet, dass ntXdll beinhaltet, benötigt eine Lizenz des Produkts. ntXdll kann dann aber ohne zusätzliche Gebühren mit der Software vertrieben werden - vorausgesetzt ntXdll ist in der Weise in die Software eingebunden, dass eine eigenständige Nutzung lizenzrechtlich untersagt wird. Die Verteilung von ntXdll erfolgt ausschliesslich nur in Verbindung mit dieser Software und nicht als eigenständiges Produkt.

Jeder Administrator oder andere Mitarbeiter, der ntXdll zu administrativen Zwecken oder zum Zwecke der Dokumentation von NT Umgebungen nutzt, benötigt eine Lizenz für jede Maschine, auf der das Produkt eingesetzt wird (auch wenn es ausschließlich über automatisierte Skripte eingesetzt wird).

Die Lizenz ist übertragbar - vorausgesetzt, sie wird nicht mehr für eigene Zwecke benutzt.

Lizenzen können nicht mit anderen Personen oder Firmen geteilt werden (z.B. von einer Lizenz über 100 Einheiten nutzt Peter 40 und Wolfgang 60).

Jeder Versuch, die Software für kommerzielle Zwecke zu decompilieren und / oder zu modifizieren ist untersagt.

Frank Seidel
09.12.2000


Copyright

Saturday, December 09, 2000

Copyright

Microsoft®, WindowsNT®, Visual Basic®, Windows Scripting Host® and msdn™
are registered trademarks of Microsoft Corporation in the United States and other countries