PRODUCT : Borland C++ NUMBER : 1704 VERSION : 3.X OS : WIN, DOS DATE : October 25, 1993 PAGE : 1/4 TITLE : Detecting whether SHARE is loaded //-------------------------------------------------------------- // // Due to complications under Windows 3.x, SHARE can no longer // be detected with certainty using int 2Fh Function 1000h. // // The published workaround is to create a temporary file, // and try to lock a section of it. If the lock fails due // to an "Invalid function number" (i.e. dos error code 1 ) // then SHARE is not loaded. // // The following source is an example of doing this in C++. // The source was designed for the large memory model, but // can be compiled for the small memory model by modifying // CreateTempOn() as indicated in the source. // // // NOTE: The directory on which the shared files are located // is significant in a network environment. Typically // share is loaded on the network server and is available // for files on network drives. This is not necessarily // true for local drives. //-------------------------------------------------------------- #include // for errno and EINVAL #include // for lock() #include // for strlen() and strcpy() #include // for cout char *TempFilename; int DetectShareOn( char *PathToSharedFiles ); int CreateTempOn( char *PathOfTempFile ); int DeleteTempFile( void ); int main(void) { char Directory[] = "C:\\"; switch ( DetectShareOn ( Directory ) ) { case 1: cout << "Share installed on " << Directory << endl; return 0; PRODUCT : Borland C++ NUMBER : 1704 VERSION : 3.X OS : WIN, DOS DATE : October 25, 1993 PAGE : 2/4 TITLE : Detecting whether SHARE is loaded case 0: cout << "Share not installed on " << Directory << endl; return 1; default: cout << "Error in detection." << endl; return 2; } } int DetectShareOn( char *PathToSharedFiles ) // Parameter: // PathToSharedFiles - null-terminated string containing // path to shared files { int RetValue; int TempHandle = CreateTempOn( PathToSharedFiles ); if ( !TempHandle ) return -1; switch (lock( TempHandle, 0, 1 )) { case -1: if ( errno == EINVAL ) RetValue = 0; else RetValue = -1; break; default: unlock ( TempHandle, 0, 1 ); RetValue = 1; } DeleteTempFile(); return RetValue; } int CreateTempOn( char *PathOfTempFile ) // Parameter: PRODUCT : Borland C++ NUMBER : 1704 VERSION : 3.X OS : WIN, DOS DATE : October 25, 1993 PAGE : 3/4 TITLE : Detecting whether SHARE is loaded // PathOfTempFile - null-terminated string containing // path to create temporary file { TempFilename = new char [ strlen(PathOfTempFile) + 13 ]; if ( !TempFilename ) return 0; strcpy( TempFilename, PathOfTempFile ); asm push ds asm xor cx, cx asm mov dx, word ptr TempFilename // Remove the following two lines for near memory models asm mov ax, word ptr TempFilename + 2 asm mov ds, ax asm mov ax, 5a00h asm int 21h asm pop ds asm jc CreateTempFailed return (_AX); CreateTempFailed: return 0; } int DeleteTempFile( void ) { int RetValue = remove ( TempFilename ); switch ( RetValue ) { case 0: delete TempFilename; return RetValue; default: return RetValue; } } PRODUCT : Borland C++ NUMBER : 1704 VERSION : 3.X OS : WIN, DOS DATE : October 25, 1993 PAGE : 4/4 TITLE : Detecting whether SHARE is loaded DISCLAIMER: You have the right to use this technical information subject to the terms of the No-Nonsense License Statement that you received with the Borland product to which this information pertains.