Back to the WFC main page
CNetworkShares : CNetwork
$Revision: 26 $
Description
This class allows you to add, delete or enumerate shares in Win32.
Constructors
CNetworkShares()
CNetworkShares( LPCTSTR machine_name )
-
Creates the object and let's you specify which machine to
execute on (i.e. which machine's shares you want to play with).
Methods
BOOL Add( const CNetworkShareInformation& share_to_add )
-
Creates a new share with the options you specify.
The return value will be TRUE if the share was created, FALSE otherwise.
BOOL Check( LPCTSTR computer_name = NULL, DWORD type = accountMachine )
-
Checks whether or not a computer is sharing a device.
The return value will be TRUE if the device is shared, FALSE otherwise.
void Close( void )
-
Closes the connection with the machine and cleans up any
internal buffers used.
BOOL Delete( const CNetworkShareInformation& share_to_delete )
-
Deletes a share.
The return value will be TRUE if the share was deleted, FALSE otherwise.
BOOL Enumerate( void )
-
Initializes the object for enumeration.
BOOL GetNext( CNetworkShareInformation& information )
-
Retrieves the next CNetworkShareInformation.
When you reach the end of the list, GetNext() will return FALSE.
Example
void test_CNetworkShares( LPCTSTR machine_name )
{
WFCTRACEINIT( TEXT( "test_CNetworkShares()" ) );
CNetworkShares shares( machine_name );
CNetworkShareInformation share_information;
if ( shares.Enumerate() != FALSE )
{
_tprintf( TEXT( "Share Information for %s:\n" ), (LPCTSTR) shares.GetMachineName() );
while( shares.GetNext( share_information ) != FALSE )
{
_tprintf( TEXT( " NetworkName - \"%s\"\n" ), (LPCTSTR) share_information.NetworkName );
_tprintf( TEXT( " Type - %lu " ), share_information.Type );
switch( share_information.Type )
{
case STYPE_DISKTREE:
_tprintf( TEXT( "Disk" ) );
break;
case STYPE_PRINTQ:
_tprintf( TEXT( "Printer" ) );
break;
case STYPE_DEVICE:
_tprintf( TEXT( "Communications Device" ) );
break;
case STYPE_IPC:
_tprintf( TEXT( "IPC" ) );
break;
case STYPE_DFS:
_tprintf( TEXT( "Distributed File System" ) );
break;
case STYPE_SPECIAL:
_tprintf( TEXT( "Special" ) );
break;
default:
_tprintf( TEXT( "Unknown Type" ) );
break;
}
_tprintf( TEXT( "\n" ) );
_tprintf( TEXT( " Remark - \"%s\"\n" ), (LPCTSTR) share_information.Remark );
_tprintf( TEXT( " Permissions - %lu\n" ), share_information.Permissions );
_tprintf( TEXT( " MaximumNumberOfUses - %d\n" ), share_information.MaximumNumberOfUses );
_tprintf( TEXT( " CurrentNumberOfUses - %d\n" ), share_information.CurrentNumberOfUses );
_tprintf( TEXT( " PathName - \"%s\"\n" ), (LPCTSTR) share_information.PathName );
_tprintf( TEXT( " Password - \"%s\"\n\n" ), (LPCTSTR) share_information.Password );
}
}
else
{
DWORD error_code = shares.GetErrorCode();
CString error_message;
Convert_NERR_Code_to_String( error_code, error_message );
_tprintf( TEXT( "CNetworkShares.Enumerate( share_information ), ErrorCode == %d \"%s\"\n" ), error_code, (LPCTSTR) error_message );
}
}
API's Used
CNetworkShares uses the following API's:
- NetApiBufferFree
- NetShareAdd
- NetShareCheck
- NetShareDel
- NetShareEnum
Copyright, 2000, Samuel R. Blackburn
$Workfile: cnetshar.cpp $
$Modtime: 1/04/00 5:16a $