I am new here & into programming. Maybe my question sounds stupid - whether it may be very simple or not possible at all... Anyway, it is possible to "sleep" until any browser is executed/active? I don't mind whether it is vb, vbs, bat, python... Thanks!
Asked
Active
Viewed 77 times
0
-
1Your actual question is probably not stupid, but your current question is completely unclear. How and where are you executing your code? What permissions do you have on the system it is being executed on? – timgeb Jan 25 '16 at 06:40
-
on Linux you could use `ps` to see running program. – furas Jan 25 '16 at 07:52
-
Well I'm doing some experiments (admin account) & trying to figure this out so maybe I could use it on some projects if it is possible. Basicly I'd like to run a script/file or whatever commands are in the code that follows once I open chrome let's say. Like an autohotkey but an "event" or "processkey" in this case haha. I'm sure there's an elegant command to do that. – Jan 25 '16 at 07:53
-
http://stackoverflow.com/questions/2703640/process-list-on-linux-via-python - psutil and PSI – furas Jan 25 '16 at 07:58
1 Answers
1
This vbscript checks every 15 minutes if an amount of programs is launched like ( chrome.exe,firefox.exe, iexplore.exe .... ) whether it finds nothing so it launch it.
If AppPrevInstance() Then
WScript.Echo "Instance already running"
WScript.Quit
Else
Do
Call Main(Array("%ProgramFiles%\Internet Explorer\iexplore.exe", "%ProgramFiles%\Mozilla Firefox\Firefox.exe", "%ProgramFiles%\Google\Chrome\Application\chrome.exe")) ',
Call Pause(15)
Loop
End If
Sub Main(colProcessPaths)
Dim ProcessPath
For Each ProcessPath In colProcessPaths
CheckProcess(ProcessPath)
Next
End Sub
'*********************************************************************************************
Sub CheckProcess(ProcessPath)
Dim ProcessName : ProcessName = StripProcPath(ProcessPath)
With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
With .ExecQuery("SELECT * FROM Win32_Process WHERE Commandline LIKE " & CommandLineLike(ProcessName))
If .Count = 0 Then
With CreateObject("WScript.Shell")
WScript.Echo ProcessPath & vbCrLf & CommandLineLike(ProcessName) & vbCrLf & CommandLineLike(ProcessName) & vbCrLf
.Run DblQuote(ProcessPath)
End With
Else
Exit Sub
End if
End With
End With
End Sub
'*********************************************************************************************
Function AppPrevInstance()
With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptFullName) & " AND CommandLine LIKE '%WScript%' OR CommandLine LIKE '%cscript%'")
AppPrevInstance = (.Count > 1)
End With
End With
End Function
'*********************************************************************************************
Sub Pause(Minutes)
Wscript.Sleep(Minutes*1000*60)
End Sub
'*********************************************************************************************
Function StripProcPath(ProcessPath)
Dim arrStr : arrStr = Split(ProcessPath, "\")
StripProcPath = arrStr(UBound(arrStr))
End Function
'*********************************************************************************************
Function CommandLineLike(ProcessPath)
ProcessPath = Replace(ProcessPath, "\", "\\")
CommandLineLike = "'%" & ProcessPath & "%'"
End Function
'*********************************************************************************************
Function DblQuote(Str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
'**********************************************************************************************

Hackoo
- 18,337
- 3
- 40
- 70