-
Northcode Proxy.exe Question
Northcode,
I have successfully used (and recommended) your PROXY.EXE program. I was wondering if you could share any details as to how it works its magic?
I'm assuming it uses a Windows API call to execute the batch file with its window hidden. I was trying to do something similar using ShellExecute from both Delphi and VB.
On Win 9x this works perfectly. The batch file is executed, it runs with no black box displayed, and the program specified in the batch file is executed.
However, this will not seem to work on XP. Any ideas? Thanks for any help.
XcVbSdRw
-
Lifetime Friend of Site Staff
This RunHidden() function is at the heart of the proxy utility. It uses CreateProcess to launch the application (specified by sCmd) as a hidden window.
Code:
void RunHidden(LPCSTR sCmd)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
// Set up for call to CreateProcess.
memset(&si, 0, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
// Create a process to run the command
CreateProcess(0, sCmd, 0, 0, FALSE, CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_PROCESS_GROUP, 0, 0, &si, &pi);
// Destroy the process and thread handles.
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
-
Northcode,
Thanks for the direction. When I implemented this using CreateProcess instead of ShellExecute it works on Win9.x all the way up through XP!
In case anyone is interested, below is the Delphi code I used to do this,
Code:
procedure RunMyProgram(ProgToRun: string; WinStyle: Word);
var
pi : TProcessInformation;
si : TStartupInfo;
begin
with si do begin
cb := SizeOf(si);
lpReserved := nil;
lpDesktop := nil;
lpTitle := nil;
dwFlags := STARTF_USESHOWWINDOW;
wShowWindow := WinStyle;
cbReserved2 := 0;
lpReserved2 := nil;
end;
Chdir(ExtractFilePath(ProgToRun));
CreateProcess(nil, PChar(ProgToRun), nil, nil, False, 0, nil, nil, si, pi);
Chdir(ExtractFilePath(ParamStr(0)));
end;
Call the procedure with,
Code:
RunMyProgram('c:\test.bat', SW_HIDE);
(for my test purposes test.bat simply contained a line to execute test.exe.)
Last edited by XcVbSdRw; 04-13-2004 at 02:57 AM.
-
Lifetime Friend of Site Staff
If you look up registered extensions in the registry and then find out what app is called to open them, then you can use CreateProcess to do the same job you're doing with ShellExecute i.e. you can implement the "open" (or default) verb for that file type. If you look up the other verbs in the file associations you can create command lines to handle the other verbs like edit, print, etc and make CreateProcess do everything. That oughta keep you busy for a little while
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|