It looks like some programs can't be started hidden using SHELL
If the caption is known this hides the program.
Can't start my own VB program hidden using SHELL.
Is there an easier way than having to search for your own runncé€,program?
Sure seems like a lot of extra work.
This code might come in handy in the future.
Note: Also tried using CreateProcess
There is a bunch of useful code in here
WaitShell and enumerate all running programs
Suggestions welcome.
If the caption is known this hides the program.
Can't start my own VB program hidden using SHELL.
Is there an easier way than having to search for your own runncé€,program?
Sure seems like a lot of extra work.
This code might come in handy in the future.
Note: Also tried using CreateProcess
There is a bunch of useful code in here
WaitShell and enumerate all running programs
Suggestions welcome.
Code:
#COMPILE EXE #DIM ALL #INCLUDE "WIN32API.INC" GLOBAL AllPrograms() AS STRING '(0,0)name (0,1)handle GLOBAL Org AS LONG 'Hide show running programs FUNCTION PBMAIN AS LONG LOCAL result AS LONG LOCAL pid AS LONG LOCAL sProgramName AS STRING LOCAL sCaption AS STRING sProgramName = "doty.exe" sCaption = "doty" result = SHELL(sProgramName) 'start program SLEEP 200 'be sure it is enough, value unknown pid = IsRunning(sCaption) 'get pid from caption IF pid THEN ? "%SW_HIDE " + $DQ + sCaption + $DQ ShowWindow(pid,%SW_HIDE) ? "%SW_NORMAL " + $DQ + sCaption + $DQ ShowWindow(pid,%SW_NORMAL) ELSE ? "Not running" END IF END FUNCTION '----------------------------------------------------------------------------------------------------------- FUNCTION WaitShell(BYVAL CmdLine AS STRING, TimeOutInMilliseconds AS LONG) AS DWORD 'Shells to another process with optional wait. Use %INFINITE to wait until done LOCAL Si AS STARTUPINFO LOCAL Pi AS PROCESS_INFORMATION LOCAL Pid AS DWORD Si.cb = SIZEOF(Si) Si.dwFlags = %STARTF_USESHOWWINDOW Si.wShowWindow = %SW_SHOWNORMAL 'Si.WshowWindow = %SW_HIDE 'This doesn't work Pid = CreateProcess("", _ BYVAL STRPTR(CmdLine), _ BYVAL %NULL, _ BYVAL %NULL, _ 0, _ &sp%3p; %NORMAL_PRIORITY_CLASS, _ <.121t; BYVAL %NULL, _ BYVAL %NULL, _ Si, _ Pi) IF Pid THEN 'Call WaitForInputIdle(pi.hProcess, %IGNORE) 'not needed FUNCTION = WaitForSingleObject(pi.hProcess, TimeOutInMilliseconds) CALL CloseHandle(pi.hProcess) CALL CloseHandle(pi.hThread) ELSE ? "Unable to CreateProcess, error" + STR$(GetLastError) END IF END FUNCTION 'ShowWindow() Commands '%SW_HIDE = 0 '%SW_SHOWNORMAL = 1 '%SW_NORMAL = 1 '%SW_SHOWMINIMIZED = 2 '%SW_SHOWMAXIMIZED = 3 '%SW_MAXIMIZE = 3 '%SW_SHOWNOACTIVATE = 4 '%SW_SHOW = 5 '%SW_MINIMIZE = 6 '%SW_SHOWMINNOACTIVE = 7 '%SW_SHOWNA = 8 '%SW_RESTORE = 9 '%SW_SHOWDEFAULT = 10 '%SW_FORCEMINIMIZE = 11 '%SW_MAX = 11 FUNCTION IsRunning(SearchFor AS STRING) AS LONG DIM search_for AS ASCIIZ * 255 REDIM AllPrograms (0 TO 255, 0 TO 255) DIM S AS LONG DIM foundIt AS LONG DIM x AS STRING LOCAL org AS LONG org = 0 search_for = SearchFor 'Search text passed as a pointer in user defined lparam& 'My_FindWindow finds first window with search_for string in title s&=EnumWindows(CODEPTR(My_FindWindow),VARPTR(search_for)) FoundIt = 0 FOR org = 0 TO 255 'Show running programs and handles 'IF LEN(AllPrograms(0,org)) THEN 'Window name ' MSGBOX STR$(org) + CHR$(34)+ AllPrograms(0,org)+ CHR$(34) 'PRINT AllPrograms(1,org) 'Window handle 'END IF 'See if program running can be found FoundIt = INSTR(AllPrograms(0,org),SearchFor) IF FoundIt THEN 'MSGBOX "Found in element" + STR$(org)+ "at bite" + STR$(FoundIt) _ ' + CHR$(34) + Allprograms(0,org) + CHR$(34) + "Handle " + ALLprograms(1,org) FUNCTION = VAL(AllPrograms(1,org)) 'MSGBOX STR$(HandleToDDocWindow) 'CALL SetForeGroundWindow(HandleToDDocWindow) 'FUNCTION = 1 EXIT FOR END IF NEXT END FUNCTION FUNCTION My_FindWindow(BYVAL whnd&,BYVAL lparm&) AS LONG DIM temp_title AS ASCIIZ *255 DIM temp_search_text AS ASCIIZ PTR DIM s AS LONG DIM org AS LONG IF lparm&>0 THEN temp_search_text=lparm& 'set pointer to search text using lparm& s&=GetWindowText(whnd&,temp_title,(255)) IF LEN(temp_title) THEN AllPrograms(0,org) = temp_title 'program name All> rams(1,org) = STR$(whnd&) 'program handle INCR org END IF END IF FUNCTION = %true 'continue searching END FUNCTION
Comment