Back to the WFC main pageCNetwork : CObject
$Revision: 40 $
Description
This class is the base class for the WFC networking classes. It is not a pure
virtual base class in that it provides some interesting (and hopefully
useful) functions.
Constructors
CNetwork( LPCTSTR machine_name = NULL )
-
Constructs the object.
Data Members
None.
Methods
BOOL AbortShutdown( void )
-
Will abort a shutdown started by Shutdown().
void Close( void )
-
Closes the connection to the machine.
BOOL EnumeratePorts( void )
-
Prepares to enumerate the ports on the machine.
DWORD GetErrorCode( void ) const
-
Retrieves the error code. This is set when a
member function returns FALSE.
void GetFriendlyMachineName( CString& machine_name )
-
Fills
machine_name
with the name of the machine
that has been Open()'ed. This names doesn't have those
annoying backslashes preceeding it.
LPCTSTR GetMachineName( void )
-
Retrieves the name of the machine this class
is working with.
BOOL GetNext( CPortInformation& port_information )
-
Gets the next CPortInformation (used in conjunction with
EnumeratePorts()).
BOOL GetTime( CTime& time )
BOOL GetTime( CSystemTime& time )
-
Gets the time from the machine as a CTime or a
CSystemTime (more accurate).
BOOL IsRebootable( void )
-
Returns TRUE if you have permissions to reboot the machine.
In other words, a call to Shutdown() should succeed.
void Open( LPCTSTR machine_name = NULL )
-
Tells the class to work with the machine you specify.
void Serialize( CArchive& archive )
-
After all we are a CObject...
BOOL SetPrivilege( LPCTSTR privilege_name, BOOL add_privilege = TRUE )
-
Adds or removes a privilege. If
add_privilege
is FALSE, the
privilege is removed, otherwise it is added. privilege_name
can be one of the following (as of NT4.0SP2/VC42b):
- SE_CREATE_TOKEN_NAME
- SE_ASSIGNPRIMARYTOKEN_NAME
- SE_LOCK_MEMORY_NAME
- SE_INCREASE_QUOTA_NAME
- SE_UNSOLICITED_INPUT_NAME
- SE_MACHINE_ACCOUNT_NAME
- SE_TCB_NAME
- SE_SECURITY_NAME
- SE_TAKE_OWNERSHIP_NAME
- SE_LOAD_DRIVER_NAME
- SE_SYSTEM_PROFILE_NAME
- SE_SYSTEMTIME_NAME
- SE_PROF_SINGLE_PROCESS_NAME
- SE_INC_BASE_PRIORITY_NAME
- SE_CREATE_PAGEFILE_NAME
- SE_CREATE_PERMANENT_NAME
- SE_BACKUP_NAME
- SE_RESTORE_NAME
- SE_SHUTDOWN_NAME
- SE_DEBUG_NAME
- SE_AUDIT_NAME
- SE_SYSTEM_ENVIRONMENT_NAME
- SE_CHANGE_NOTIFY_NAME
- SE_REMOTE_SHUTDOWN_NAME
BOOL Shutdown( BOOL reboot = TRUE,
BOOL force_applocations_to_close = TRUE,
LPCTSTR message_to_display = NULL,
DWORD number_of_seconds_before_shutdown = 0 )
-
Will reboot the machine set by Open().
Example
void test_CNetwork( LPCTSTR machine_name )
{
WFCTRACEINIT( TEXT( "test_CNetwork()" ) );
CNetwork machine( machine_name );
if ( machine.EnumeratePorts() )
{
if ( machine_name != NULL )
{
_tprintf( TEXT( "Ports on %s\n" ), machine_name );
}
else
{
_tprintf( TEXT( "Ports on local machine\n" ) );
}
CPortInformation port;
while( machine.GetNext( port ) )
{
_tprintf( TEXT( "Name: %s\n" ), (LPCTSTR) port.Name );
_tprintf( TEXT( "Monitor: %s\n" ), (LPCTSTR) port.Monitor );
_tprintf( TEXT( "Description: %s\n" ), (LPCTSTR) port.Description );
_tprintf( TEXT( "Type: %04lX\n" ), port.Type );
_tprintf( TEXT( "TypeName: %s\n\n" ), (LPCTSTR) port.TypeName );
}
}
else
{
DWORD error_code = machine.GetErrorCode();
ReportError( error_code );
_tprintf( TEXT( "Can't EnumeratePorts, reason code %lu\n" ), error_code );
}
if ( machine.IsRebootable() )
{
if ( machine_name != NULL )
{
_tprintf( TEXT( "Yes, I can reboot %s\n" ), machine_name );
}
else
{
_tprintf( TEXT( "Yes, I can reboot this machine\n" ) );
}
}
}
API's Used
- AbortSystemShutdown
- AdjustTokenPrivileges
- EnumPorts
- GetComputerName
- GetCurrentProcess
- GetLastError
- InitiateSystemShutdown
- LookupPrivilegeValue
- NetRemoteTOD
- OpenProcessToken
- ZeroMemory
Copyright, 2000, Samuel R. Blackburn
$Workfile: cnetwork.cpp $
$Modtime: 1/17/00 9:08a $