There's a GetStdHandle API call you can use to get the STDIO handles, then use ReadFile and WriteFile to work with the STDIO handle.
VB Code:
  1. Option Explicit
  2.  
  3. Private Const STD_ERROR_HANDLE As Long = -12&
  4. Private Const STD_INPUT_HANDLE As Long = -10&
  5. Private Const STD_OUTPUT_HANDLE As Long = -11&
  6.  
  7. Private Const GENERIC_WRITE As Long = &H40000000
  8. Private Const FILE_SHARE_READ As Long = &H1&
  9. Private Const OPEN_ALWAYS As Long = 4&
  10. Private Const FILE_ATTRIBUTE_ARCHIVE As Long = &H20&
  11.  
  12. Private Const FILE_END As Long = 2&
  13.  
  14. Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
  15.  
  16. Private Declare Function WriteFile Lib "kernel32.dll" (ByVal hFile As Long, _
  17.     lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, _
  18.     lpNumberOfBytesWritten As Long, lpOverlapped As Any) As Long
  19.    
  20. Private Declare Function CreateFile Lib "kernel32.dll" Alias "CreateFileA" _
  21.     (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, _
  22.     ByVal dwShareMode As Long, lpSecurityAttributes As Any, _
  23.     ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, _
  24.     ByVal hTemplateFile As Long) As Long
  25.    
  26. Public Declare Function SetFilePointer Lib "kernel32.dll" (ByVal hFile As Long, _
  27.     ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, _
  28.     ByVal dwMoveMethod As Long) As Long
  29.  
  30. Private Declare Function GetStdHandle Lib "kernel32" _
  31.     (ByVal nStdHandle As Long) As Long
  32.    
  33. Private Declare Function GetEnvironmentVariable Lib "kernel32" Alias "GetEnvironmentVariableA" _
  34.     (ByVal lpName As String, ByVal lpBuffer As String, ByVal nSize As Long) As Long
  35.  
  36. Private Declare Function AllocConsole Lib "kernel32" () As Long
  37. Private Declare Function FreeConsole Lib "kernel32" () As Long
  38.  
  39. Public Sub Main()
  40.     Dim STDOUT As Long 'handle to standard output
  41.     Dim strHTTP As String 'data buffer for HTTP header output
  42.     Dim strBuffer As String 'data buffer for writing to the log file
  43.     Dim lngBytesWritten As Long 'the number of bytes that were written
  44.     Dim retval As Long 'API return value
  45.     Dim FILEOUT As Long 'handle to the file to log to
  46.     'CGI Variables
  47.     Dim strQueryString As String
  48.     Dim strRemoteAddr As String
  49.     Dim strHTTPUserAgent As String
  50.    
  51.     'fill the buffers with nothing
  52.     strQueryString = Space$(256)
  53.     strRemoteAddr = strQueryString
  54.     strHTTPUserAgent = strQueryString
  55.    
  56.     'get and store the CGI variables needed
  57.     retval = GetEnvironmentVariable("QUERY_STRING", strQueryString, 256)
  58.     strQueryString = Left$(strQueryString, retval)
  59.     retval = GetEnvironmentVariable("REMOTE_ADDR", strRemoteAddr, 256)
  60.     strRemoteAddr = Left$(strRemoteAddr, retval)
  61.     retval = GetEnvironmentVariable("HTTP_USER_AGENT", strHTTPUserAgent, 256)
  62.     strHTTPUserAgent = Left$(strHTTPUserAgent, retval)
  63.    
  64.     strHTTP = "Location: ./win2000.gif" & vbCrLf & vbCrLf
  65.    
  66.     'start the console
  67.     'retval = AllocConsole 'UNCOMMENT FOR IDE DEBUGGING
  68.    
  69.     'get the handle to standard output
  70.     STDOUT = GetStdHandle(STD_OUTPUT_HANDLE)
  71.    
  72.     'write the string to STDOUT, just like writing to a file
  73.     retval = WriteFile(STDOUT, ByVal strHTTP, Len(strHTTP), lngBytesWritten, ByVal 0&)
  74.  
  75.     'close the handle to standard out
  76.     retval = CloseHandle(STDOUT)
  77.    
  78.     'close the console
  79.     'retval = FreeConsole 'UNCOMMENT FOR IDE DEBUGGING
  80.    
  81.     'open the file for writing
  82.     FILEOUT = CreateFile("C:\Inetpub\wwwroot\Test\image.log", GENERIC_WRITE, FILE_SHARE_READ, _
  83.         ByVal 0&, OPEN_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, 0)
  84.    
  85.     'if error
  86.     If FILEOUT = -1 Then Exit Sub
  87.        
  88.     'fill the buffer
  89.     strBuffer = Now & ";" & strQueryString & ";" & strRemoteAddr & ";" & strHTTPUserAgent & vbCrLf
  90.        
  91.     'move the file pointer to EOF
  92.     retval = SetFilePointer(FILEOUT, 0, 0, FILE_END)
  93.    
  94.     'write the buffer to the file
  95.     retval = WriteFile(FILEOUT, ByVal strBuffer, Len(strBuffer), lngBytesWritten, ByVal 0&)
  96.        
  97.     'close the handle to the file
  98.     retval = CloseHandle(FILEOUT)
  99. End Sub