active processes

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
worldwide
Junior Coder
Posts: 31
Joined: Mon Jul 09, 2007 11:34 am

active processes

Post by worldwide » Tue Nov 06, 2007 3:59 pm

Hello,

could somebody help me with the following problem ?!

I want to know if a special process is started(running), if yes it should start another program.

This should all be done with one script, is that possible ?!

Best and thanx in advance

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Nov 06, 2007 4:20 pm

Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

worldwide
Junior Coder
Posts: 31
Joined: Mon Jul 09, 2007 11:34 am

Post by worldwide » Tue Nov 06, 2007 5:04 pm

Thanx for your fast reply....

now my example here :

Yes there is a mistake.... but i cant find it.

I cutted your script till the processname, i chekc if the process is running and the show it as message box

------------------------------------------


VBSTART

Sub Processes
'displays each process, its size lists each process and the cpu time it has used.

sComputer = "."
Set oWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")

Set colProcessList = oWMIService.ExecQuery _
("Select Name, WorkingSetSize from Win32_Process")


If oProcess.Name="ikke.exe"
MsgBox oProcess.Name
else
exit
endif
End Sub

VBEND

VBRun>Processes

worldwide
Junior Coder
Posts: 31
Joined: Mon Jul 09, 2007 11:34 am

Post by worldwide » Tue Nov 06, 2007 5:09 pm

Ok, i think im a bit in stress thats why i couldnt find a solution ...

sorry for this i hope still someone could help me ;-) ?!

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Nov 06, 2007 5:30 pm

Try this:

Code: Select all

VBSTART
'returns the number of copies of ProcessName that are running
'will return 0 if ProcessName is not running
Function IsProcessRunning(ProcessName)
	Set oWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
	Set colProcessList = oWMIService.ExecQuery ("Select Name from Win32_Process where Name='" & ProcessName & "'")
	IsProcessRunning = colProcessList.count
End Function
VBEND
VBEval>IsProcessRunning("ikke.exe"),res
If>res=1
  MessageModal>ikke.exe is running
Endif
If ikke.exe is running the message box will say "ikke.exe is running". Otherwise nothing will happen.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

worldwide
Junior Coder
Posts: 31
Joined: Mon Jul 09, 2007 11:34 am

Post by worldwide » Tue Nov 06, 2007 6:26 pm

Your the best !!!

Thanx a lot ;-) this helped me out ...its gettin late for me now after 14hours

Best Paul

ps. ill have a look atthis again tomorrow

worldwide
Junior Coder
Posts: 31
Joined: Mon Jul 09, 2007 11:34 am

Post by worldwide » Wed Nov 07, 2007 7:17 am

Ok heres the final script i made with your help.

The script runs like a charm, but ... as soon as i make an .exe out of it directly an windows error shows up.

ANy idea what im doin wrong ?

---------------------------------------------------------------------------------
code :

Run Program>c:\subd\prog1.exe
VBSTART
'returns the number of copies of ProcessName that are running
'will return 0 if ProcessName is not running
Function IsProcessRunning(ProcessName)
Set oWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colProcessList = oWMIService.ExecQuery ("Select Name from Win32_Process where Name='" & ProcessName & "'")
IsProcessRunning = colProcessList.count
End Function
VBEND

label>loop1
VBEval>IsProcessRunning("prog1.exe"),res
If>res=1
MessageModal>is running
Run Program>c:\subd\prog2.exe
else
MessageModal>is NOT RUNNING
goto>loop1
Endif

label>loop2

VBEval>IsProcessRunning("prog3.exe"),res

If>res=1
MessageModal>prog3.exe is running
Run Program>c:\subd\prog4.exe
else
MessageModal>prog3.exe is NOT RUNNING
goto>loop2

Endif
---------------------------------------------------------------------------------

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Nov 07, 2007 9:04 am

What windows error shows up?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

worldwide
Junior Coder
Posts: 31
Joined: Mon Jul 09, 2007 11:34 am

Post by worldwide » Wed Nov 07, 2007 9:50 am

The time ill start the proggi.exe a windows message popups with :

proggie.exe ha encountered a problem and has to be closed.

I wrote(copied from this forum) also this and made a exe out of it.... also a problem :

------------------------------------------------------------------------
VBSTART
Sub killProcess(pgm)
set wmi = getobject("winmgmts:")
sQuery = "select * from win32_process " & "where name='" & pgm & "'"
set processes = wmi.execquery(sQuery)
for each process in processes
process.terminate
next
End Sub
VBEND

VBRun>KillProcess,prog1.exe
---------------------------------------------------------------------------

I checkd it on a windows2000 and 3 different windowsXP systems

Strange isnt it ?
I mean, if the failures would popup during the script running i could see whats happening... but after that its a exe-file ... i dont get it.

Did i turn off something in the system so it produces the problem, but what since i tested it also on 3 different XP-systems

Thanx

worldwide
Junior Coder
Posts: 31
Joined: Mon Jul 09, 2007 11:34 am

Post by worldwide » Wed Nov 07, 2007 1:58 pm

Has no one a possible solution for me ?

hhmmm, thats a pitty. No im really stuck.. i evne tested the programm on a new xp installed system and still came up with this failure.

:-(

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Wed Nov 07, 2007 2:11 pm

I just compiled it and it runs without error for me on XP.

worldwide
Junior Coder
Posts: 31
Joined: Mon Jul 09, 2007 11:34 am

Post by worldwide » Thu Nov 08, 2007 5:57 am

I found a problem with my windows2000.

I installed the program on a new XP and then compiled it....now it works ;-)

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Thu Nov 08, 2007 2:07 pm

I have found that 2000 truncates long process names to 15(?) characters, and XP does not. If you are writing a macro to work on both OS's to manage a process with a very long name you need to detect the OS and include conditional logic.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts