NewSupend (OpenInsight 32-Bit)
At 20 AUG 2006 03:50:30AM Steve Epstein wrote:
Here is a version of RUNWIN which runs both within and outside of the PS.
Thanks to Bob Carten and Sprezz.
function NewSuspend(processfile, params, modal_flag, minimize, title)
*
Use Createprocess to launch a separate windows process If modal flag is set
processfile (in)=fully qualified path to the executable you want to start, e.g c:\windows\notepad.exe
params (in)=parameters to pass, same as you would type on the command line when starting the exe modal_flag (in)=if true, app will wait till process ends, default to false
minimize (in)=if true, process will run minimized title (in)=title for process
Example - Open a file in notepad
call runprocess( "c:\windows\Notepad.exe", "/A c:\temp\test.txt", 1) ATTENTION: if process is not GUI, the first parameter must be the name of the .exe or .bat
Note: Requires that you run DEFINE_STRUCT for STARTUPINFO, PROCESS_INFORMATION structures. See definitions at bottom
08-04-06 rjc translated from http://support.microsoft.com/?kbid=129796 08-20-06 sae cleaned up with correct structure definitions
*
declare function struct_to_var, var_To_struct, blank_Struct,utf8_ansi
declare function CreateProcessA, WaitForSingleObject, CloseHandle
$insert Logical
* Fields for STARTUPINFO Structure
Equ cb$ to 1
Equ lpReserved$ to 2
Equ lpDesktop$ to 3
Equ lpTitle$ to 4
Equ dwX$ to 5
Equ dwY$ to 6
Equ dwXSize$ to 7
Equ dwYSize$ to 8
Equ dwXCountChars$ to 9
Equ dwYCountChars$ to 10
Equ dwFillAttribute$ to 11
Equ dwFlags$ to 12
Equ wShowWindow$ to 13
Equ cbReserved$ to 14
Equ lpReserved2$ to 15
Equ hStdInput$ to 16
Equ hStdOutput$ to 17
Equ hStdError$ to 18
equ startupinfo_len$ to 68
Equ STARTF_USESHOWWINDOW$ to 1
Equ SW_SHOWNORMAL$ to 1
Equ SW_SHOWMINIMIZE$ to 2
* Fields for PROCESS_INFORMATION Structure
Equ Process_Information_hProcess$ to 1
Equ Process_Information_hThread$ to 2
Equ Process_Information_dwProcessId$ to 3
Equ Process_Information_dwThreadID$ to 4
Equ process_information_len$ to 16
* Params for CreateProcess and
Equ NORMAL_PRIORITY_CLASS$ to 0X20
Equ INFINITE$ to -1
*
* Initialize Structures
startupInfo='
startupinfo=startupinfo_len$
if len(title) then
winText=utf8_ansi(title:\00\) ; *my apps run in UTF-8lockvariable winText as LPVOIDstartupinfo=GetPointer(winText)end else
startupinfo=0end
startupinfo=STARTF_USESHOWWINDOW$
if minimize=1 then
startupinfo=SW_SHOWMINIMIZE$end else
startupinfo=SW_SHOWNORMAL$end
stru_startupinfo=var_to_struct(startupinfo,'STARTUPINFO')
lockvariable stru_Startupinfo as LPVOID
pStartupinfo=GetPointer(stru_Startupinfo)
process_Information='
stru_Process_Information=var_to_struct(process_information, 'PROCESS_INFORMATION')
lockvariable stru_Process_Information as LPVOID
pProcess_Information=GetPointer(stru_Process_Information)
success=CreateProcessA(processfile,params, 0, 0, 0,NORMAL_PRIORITY_CLASS$, 0, 0, pstartupInfo, pprocess_information)
stru_Process_Information=getValue(pProcess_Information, CHAR, process_information_len$)
Process_Information=Struct_to_Var(stru_Process_Information, 'PROCESS_INFORMATION')
unlockvariable stru_Startupinfo
unlockvariable stru_Process_Information
unlockvariable pwinText
hProcess=Process_Information
hThread=Process_Information
if modal_Flag then
ret=WaitForSingleObject(hProcess, INFINITE$)end
Call CloseHandle(hThread)
Call CloseHandle(hProcess)
return 1
/*
Oi Structures needed
create using Define_struct
typedef struct _STARTUPINFO { DWORD cb;
LPTSTR lpReserved;LPTSTR lpDesktop;LPTSTR lpTitle;DWORD dwX;DWORD dwY;DWORD dwXSize;DWORD dwYSize;DWORD dwXCountChars;DWORD dwYCountChars;DWORD dwFillAttribute;DWORD dwFlags;WORD wShowWindow;WORD cbReserved2;LPBYTE lpReserved2;HANDLE hStdInput;HANDLE hStdOutput;HANDLE hStdError;} STARTUPINFO, *LPSTARTUPINFO;typedef struct _PROCESS_INFORMATION {
HANDLE hProcess;HANDLE hThread;DWORD dwProcessId;DWORD dwThreadId;} PROCESS_INFORMATION, *LPPROCESS_INFORMATION;*/
At 21 AUG 2006 10:36AM Bob Carten wrote:
Good job Steve.
Thanks for posting the cleaned up version
Bob
At 21 AUG 2006 10:51AM Karen Oland wrote:
So, should the title line be changed to:
function runprocess( ...or the internal documentation changed to:
* call NewSuspend( …
At 21 AUG 2006 08:04PM Steve Epstein wrote:
Karen,
When I did the "cut and paste" I left out the word function.
I always make every program a function … I never use procedures or calls.
At 21 AUG 2006 08:16PM Steve Epstein wrote:
Now I see what you mean. I forgot to cleanup the comments. Bob started by making a procedure called RunProcess. When I re-wrote his code, I changed the program to a function called "NewSuspend" (after the old "suspend" call from AREV).
So the declaration is "function NewSuspend", and the comment should read like "void=NewSuspend(…"
At 22 AUG 2006 08:49PM Steve Epstein wrote:
When I posted the code, all of the "" operators for dynamic arrays were stripped out, perhaps because HTML thought they were tags.
So if anyone would like the code, please write to me at sepstein@absconsulting.com.