Microsoft KB Archive/60075

Auto-Detecting the Video Configuration of a Network Node

PSS ID Number: Q60075 Article last modified on 11-02-1994

5.00

MS-DOS

= SUMMARY =

The following is taken from the EMAG6 article titled “Auto-Detecting the Video Configuration of a Workstation on a Network” by P. Denniston and B. Selvamuthu.

Many network products do not automatically detect the type of video card in a workstation. These products usually require one of the following:


 * 1) You must start the application with a parameter indicating the video card type (for example, WORKS /G N:.VID).
 * 2) You must set an environment variable for the application that points to the location of a unique screen driver for your machine (for example, Word’s MSWNET variable).

Both methods have limitations. The first method does not lend itself to a menu system because it requires user input. The second, although it works well with a menuing system, does not allow you to switch to workstations with different video types.

One solution for this problem encountered with these types of software applications is to write a program that detects the video card in the workstation and passes that information to the application. The program VIDEO.C (shown below), which is written in Microsoft C, addresses the needs of users across multiple-network platforms.

VIDEO.C

 * 1) include  #include  /* needed for video configurations calls / #include  / needed for DOS system calls */

/* Description ———–

This program detects a workstation’s video card type and passes that value to the DOS environment through a batch file used to start the application. Our example uses the batch file WD5.BAT to set the video configuration for a specific application (Microsoft Word 5.00), but VIDEO.C could be modified to set the configuration for any application (hint: add a parameter list to function MAIN).

Procedure
The program detects the video configuration using _getvideoconfig. Depending on the video card detected, the program writes SET VIDEO=constant (where constant is a subset of EGA, VGA, etc.) to a temporary file (TMP.BAT). Then using DOS system calls, it appends TMP.BAT to a batch file that sets the video mode using application- specific terms (WD5.BAT) and copies the result to OUTPUT.BAT. The program ends by running OUTPUT.BAT and then deletes the in-process batch files, OUTPUT.BAT and TMP.BAT.

Program Notes
SET VIDEO=constant cannot be sent directly to the DOS environment using the C DOS system call. When you invoke a DOS command from C, it pushes a new COMMAND.COM on the stack and all subsequent DOS calls run in this new environment. As soon as the system call returns, those calls are popped out of the stack, making it impossible to write to the original environment.

We recognize that the number of batch files could be reduced through some additional C function calls. This method proves preferable for the following reasons:


 * 1) It doesn’t modify the batch file used to start the application from a network menu (which is probably set to read-only).
 * 2) It is easy to maintain in terms of adding new applications.

Any additions you may want to send in on the code are welcome. */

void main (void) {

FILE fp; / File pointer–> TEMP.BAT */

struct videoconfig video;

int result; /* To hold return values */

fp=fopen(&quot;tmp.bat&quot;,&quot;w&quot;); _getvideoconfig( &video ); switch (video.adapter)

{ /* Set video to DOS environment variable by writing to file TMP.BAT and then using the DOS COPY command to append it to    WD5.BAT  */

case _MDPA: result=fprintf (fp,&quot;set VIDEO=MDPA \n&quot;); break; case _CGA: result=fprintf (fp,&quot;set VIDEO=CGA \n&quot;); break; case _EGA: result=fprintf (fp,&quot;set VIDEO=EGA \n&quot;); break; case _VGA: result= fprintf(fp,&quot;set VIDEO=VGA \n&quot;); break; case _MCGA: result=fprintf (fp,&quot;set VIDEO=MCGA \n&quot;); break; case _HGC: result=fprintf (fp,&quot;set VIDEO=HGC \n&quot;); break; default: printf(&quot;Couldn't figure out what video card you have \n&quot;); exit (0); } fclose(fp); /* Close the in-process batch files */

/* Append TMP.BAT and WD5.BAT to OUTPUT.BAT */ result = system(“copy tmp.bat + WD5.BAT output.bat”);

/* Run the batch file to copy the appropriate screen driver */ result = system(“output”);

/* Delete the appended file OUTPUT.BAT */ result = system(“erase output.bat”);

/* Delete the TMP.BAT */ result = system(“erase tmp.bat”);

}

Final Notes
  The program VIDEO.C can be found in the Software/Data Library by searching on the keyword VIDEO, the Q number of this article, or S12541. VIDEO was archived using the PKware file-compression utility. Appended to the program VIDEO.C is the file WD5.BAT. VIDEO.C and WD5.BAT both must be modified to match your system’s needs and directory structure. Also included in the Software/Data Library file VIDEO is the file WK2.BAT for those of you who want to apply a similar logic to Microsoft Works version 2.00.   If your network uses an unchanging physical station number to identify each workstation, you can automate this process another way. For more information, query on the following words: accessing and different and video and files and network 

KBCategory: kbother kbnetwork KBSubcategory: Additional reference words: ============================================================================= Copyright Microsoft Corporation 1994.