That usually depends on the program and the installer. There is often a way to automate the CD key, but it probably wouldn't be in DOS or a batch file. For example, for Windows 98 I remember you could enter the CD-key into the "msbatch.inf" file to automate that part of the process. Other programs may have a smillar method, but it will be program specific.
Scripts can be written to "push" keystrokes. The easiest way to push keystrokes to a Window would probably to use sendkeys in a VBScript.