7 // from the PVAX (http://www.ccas.ru/~posp/popov/spawn.htm)
8 // Create a process with pipes to stdin/out/err
9 BOOL
CreateHiddenConsoleProcess(LPCTSTR szChildName
, PROCESS_INFORMATION
* ppi
,
10 LPHANDLE phInWrite
, LPHANDLE phOutRead
,
14 SECURITY_ATTRIBUTES sa
;
20 // initialize security attributes for handle inheritance (for WinNT)
21 sa
.nLength
= sizeof( sa
);
22 sa
.bInheritHandle
= TRUE
;
23 sa
.lpSecurityDescriptor
= NULL
;
26 if( !CreatePipe( &hInRead
, phInWrite
, &sa
, 0 ))
30 if( !CreatePipe( phOutRead
, &hOutWrite
, &sa
, 0 ))
34 if( !CreatePipe( phErrRead
, &hErrWrite
, &sa
, 0 ))
37 // process startup information
38 memset( &si
, 0, sizeof( si
));
40 si
.dwFlags
= STARTF_USESHOWWINDOW
| STARTF_USESTDHANDLES
;
41 // child process' console must be hidden for Win95 compatibility
42 si
.wShowWindow
= SW_HIDE
;
43 // assign "other" sides of pipes
44 si
.hStdInput
= hInRead
;
45 si
.hStdOutput
= hOutWrite
;
46 si
.hStdError
= hErrWrite
;
48 // Create a child process (suspended)
49 fCreated
= CreateProcess( NULL
,
63 CloseHandle( hInRead
);
64 CloseHandle( hOutWrite
);
65 CloseHandle( hErrWrite
);
70 CloseHandle( hInRead
);
71 CloseHandle( hOutWrite
);
72 CloseHandle( hErrWrite
);
73 CloseHandle( ppi
->hProcess
);
74 CloseHandle( ppi
->hThread
);
80 ppi
->hThread
= INVALID_HANDLE_VALUE
;
85 BOOL
SpawnProcess(char *cmd_line
, PROCESS_INFORMATION
*pi
) {
88 memset(&si
, 0, sizeof(si
));
91 return CreateProcess(cmd_line
, NULL
, NULL
, FALSE
, NORMAL_PRIORITY_CLASS
,
92 CREATE_NEW_CONSOLE
, NULL
, NULL
, &si
, pi
);
96 int GetWin32Version(void) {
97 // return win32 version; 0 = Win32s, 1 = Win95, 2 = WinNT, 3 = Unknown -crn@ozemail.com.au
101 osv
= new OSVERSIONINFO
;
103 osv
->dwOSVersionInfoSize
= sizeof (OSVERSIONINFO
);
105 retval
= osv
->dwPlatformId
;
110 // Paul Brannan 8/7/98
111 // This code is from Michael 'Hacker' Krelin (author of KINSole)
112 // (slightly modified)
113 HWND
TelnetGetConsoleWindow() {
114 DWORD pid
= GetCurrentProcessId(), wpid
;
115 char title
[512], *t
= title
;
118 #ifndef __BORLANDC__ // Ioannou Dec. 8, 1998
119 if(!GetConsoleTitle(title
, sizeof(title
))) t
= NULL
;
122 if((hrv
= FindWindowEx(NULL
, hrv
, "tty", t
)) == NULL
) break;
123 if(!GetWindowThreadProcessId(hrv
, &wpid
)) continue;
124 if(wpid
== pid
) return hrv
;
128 return GetForegroundWindow();
131 // Sets the icon of the console window to hIcon
132 // If hIcon is 0, then use a default icon
133 // hConsoleWindow must be set before calling SetIcon
134 bool SetIcon(HWND hConsoleWindow
, HANDLE hIcon
, LPARAM
*pOldBIcon
, LPARAM
*pOldSIcon
,
135 const char *icondir
) {
136 if(!hConsoleWindow
) return false;
138 // FIX ME!!! The LoadIcon code should work with any compiler!
139 // (Paul Brannan 12/17/98)
140 #ifndef __BORLANDC__ // Ioannou Dec. 8, 1998
142 char filename
[128]; // load from telnet.ico
143 strncpy(filename
, icondir
, sizeof(filename
));
144 strncat(filename
, "telnet.ico", sizeof(filename
));
145 filename
[sizeof(filename
) - 1] = 0;
147 // Note: loading the icon from a file doesn't work on NT
148 // There is no LoadImage in Borland headers - only LoadIcon
149 hIcon
= LoadImage(NULL
, filename
, IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
+
153 // load the icon from the resource file -crn@ozemail.com.au 16/12/98
155 hIcon
= LoadIcon ((HANDLE
)GetWindowLong(hConsoleWindow
,
156 GWL_HINSTANCE
), "TELNETICON");
162 *pOldBIcon
= SendMessage(hConsoleWindow
, WM_SETICON
, ICON_BIG
,
166 *pOldSIcon
= SendMessage(hConsoleWindow
, WM_SETICON
, ICON_SMALL
,
171 // Otherwise we get a random icon at exit! (Paul Brannan 9/13/98)
176 // Allows SetIcon to be called again by resetting the current icon
177 // Added 12/17/98 by Paul Brannan
178 void ResetIcon(HWND hConsoleWindow
, LPARAM oldBIcon
, LPARAM oldSIcon
) {
180 SendMessage(hConsoleWindow
, WM_SETICON
, ICON_BIG
, (LPARAM
)oldBIcon
);
183 SendMessage(hConsoleWindow
, WM_SETICON
, ICON_SMALL
, (LPARAM
)oldSIcon
);