Discussion:
Number of applications running.
(too old to reply)
Wagner
2008-10-16 18:08:28 UTC
Permalink
How do you know the number of applications that are running.
For example, if I run the WordPad.exe twice, as in my application dBase know that this WordPad.exe running two copies (stays)
Greg Hill
2008-10-16 18:19:41 UTC
Permalink
Post by Wagner
How do you know the number of applications that are running.
For example, if I run the WordPad.exe twice, as in my application dBase
know that this WordPad.exe running two copies (stays)
To know how many times a program is running you will need to get a function
in the binaries group called killprocess.prg.
It was posted by:
From: "Greg Hill" <***@hotmail.com>
Subject: Kill Process function
Date: Fri, 15 Feb 2008 07:50:16 -0800


You will need to make a slight modification to it so that you can count the
instances of the process but that would be very easy to do once you digest
the code inside this function.

There is also a function donated by Jim Sare called appMGR32.prg, that will
bring any open app to the foreground and or simply tell you if it is infact
opened or not.

Hope this helps.
Greg Hill
wagner
2008-10-17 20:30:27 UTC
Permalink
Post by Greg Hill
Post by Wagner
How do you know the number of applications that are running.
For example, if I run the WordPad.exe twice, as in my application dBase
know that this WordPad.exe running two copies (stays)
To know how many times a program is running you will need to get a function
in the binaries group called killprocess.prg.
Subject: Kill Process function
Date: Fri, 15 Feb 2008 07:50:16 -0800
You will need to make a slight modification to it so that you can count the
instances of the process but that would be very easy to do once you digest
the code inside this function.
There is also a function donated by Jim Sare called appMGR32.prg, that will
bring any open app to the foreground and or simply tell you if it is infact
opened or not.
Hope this helps.
Greg Hill
I have an application developed in dBase Plus with the name Myprg.exe, perceby the Windows Task Manager that it appears as PLUSrun.exe, if called more than once the same MyPrg1.exe it appears another PLUSrun.exe, how to identify which this running
Greg Hill
2008-10-18 01:53:44 UTC
Permalink
Post by wagner
I have an application developed in dBase Plus with the name Myprg.exe,
perceby the Windows Task Manager that it appears as PLUSrun.exe, if called
more than >once the same MyPrg1.exe it appears another PLUSrun.exe, how to
identify which this running
What are you trying to do or what are you trying to avoid?

There are ways to track this stuff but it is difficult to help without
knowing the goal?

For example, you can change the title bar text of the app window frame each
time you launch the app adding a number, example:
Lets say your app is named:
Customer Tracker
In your startup code you would run the process counting function to get the
count of PLUSrun.exe apps running and change the title bar as follows:

n = processCount() // get process count stored to n
n = lTrim(str(n))
_app.framewin.text = "Customer Tracker - "+n

Now you can use appMGR32.prg to bring any of those other apps to the
foreground as follows:

set proce to appmgr.prg addi
nWinHandle = showApp("Customer Tracker - 2")

// the 2nd instance of your app will now be in focus of the forground.

Hope this helps

Greg Hill
wagner
2008-10-18 12:32:45 UTC
Permalink
Post by Greg Hill
Post by wagner
I have an application developed in dBase Plus with the name Myprg.exe,
perceby the Windows Task Manager that it appears as PLUSrun.exe, if called
more than >once the same MyPrg1.exe it appears another PLUSrun.exe, how to
identify which this running
What are you trying to do or what are you trying to avoid?
There are ways to track this stuff but it is difficult to help without
knowing the goal?
For example, you can change the title bar text of the app window frame each
Customer Tracker
In your startup code you would run the process counting function to get the
n = processCount() // get process count stored to n
n = lTrim(str(n))
_app.framewin.text = "Customer Tracker - "+n
Now you can use appMGR32.prg to bring any of those other apps to the
set proce to appmgr.prg addi
nWinHandle = showApp("Customer Tracker - 2")
// the 2nd instance of your app will now be in focus of the forground.
Hope this helps
Greg Hill
I can not use the feature to identify the application by the text (app.framewin.text) because TaskbarTray.cc use the class to keep the application minimized.
Is there a way to know for each PLUSrun which the title of this application that this executnado thus able to identify the applications that are running.
Greg Hill
2008-10-18 19:05:11 UTC
Permalink
Post by wagner
Post by Greg Hill
Post by wagner
I have an application developed in dBase Plus with the name Myprg.exe,
perceby the Windows Task Manager that it appears as PLUSrun.exe, if called
more than >once the same MyPrg1.exe it appears another PLUSrun.exe, how to
identify which this running
What are you trying to do or what are you trying to avoid?
There are ways to track this stuff but it is difficult to help without
knowing the goal?
For example, you can change the title bar text of the app window frame each
Customer Tracker
In your startup code you would run the process counting function to get the
n = processCount() // get process count stored to n
n = lTrim(str(n))
_app.framewin.text = "Customer Tracker - "+n
Now you can use appMGR32.prg to bring any of those other apps to the
set proce to appmgr.prg addi
nWinHandle = showApp("Customer Tracker - 2")
// the 2nd instance of your app will now be in focus of the forground.
Hope this helps
Greg Hill
I can not use the feature to identify the application by the text
(app.framewin.text) because TaskbarTray.cc use the class to keep the
application minimized.
Is there a way to know for each PLUSrun which the title of this
application that this executnado thus able to identify the applications
that are running.
All apps have a title, even if they are in minimized in the taskbar or not,
so would argue that it will work.
But you still are not explaining what you are trying to do well enough for
me to help.

Greg Hill
unknown
2008-10-17 08:58:40 UTC
Permalink
On Thu, 16 Oct 2008 14:08:28 -0400 Wagner
Sender: Wagner <***@rcequipe.com.br>
wrote the following in:
Newsgroup: dbase.programming
Post by Wagner
How do you know the number of applications that are running.
For example, if I run the WordPad.exe twice, as in my application dBase know that this WordPad.exe running two copies (stays)
Try the code below my signature. It is based upon code published by Rich, Autotracker. I modified it
to filter out only the exe searched for.

To test it open WordPad twice and the type the following from the command pane:

getProcess("WordPad.exe")

The way I parse the result is not pretty, but I did not have time to find a more elegant way, after
all, it is only an example :-)


Ivar B. Jessen

//-----
function getProcess(cProcess)
cProcess = lower(cProcess)

if file( "pTable.dbf")
drop table pTable
endif
if file("ans1.txt")
delete file "ans1.txt"
endif

create table pTable(fProcess char(15), fProcID integer)

#define vbCrLf chr(13)+chr(10)

extern CLONG GetCurrentProcessId( CVOID ) kernel32
plusHandle = str(GetCurrentProcessID())

sc = new OleAutoClient("MSScriptControl.ScriptControl")
sc.language = "JScript"

str = [function getProcesses(){] + vbCrLf

// Get Object and create enumerator
str += [ var e = new Enumerator( GetObject( "winmgmts:" ).InstancesOf("Win32_process" ) );] +
vbCrLf

// Variable to hold the info we find
str += [ var msg = "" + "\n";] + vbCrLf

// Loop through processes
str += [ for (;!e.atEnd();e.moveNext())] + vbCrLf
str += [ {] + vbCrLf

// Get object from enumerator
str += [ var p = e.item ();] + vbCrLf

// Add process based on name match
str += [ if ( p.Name == ']+cProcess+[' ) {;] + vbCrLf
// Format message with process name and handle
str += [ msg += p.Name + "," + p.Handle + "\n";] + vbCrLf
str += [ }] + vbCrLf
str += [ }] + vbCrLf
// Return the process names and handles
str += [return msg;] + vbCrLf
str += [}] + vbCrLf

sc.addCode( str )
ans = sc.run("getProcesses")
release object sc
sc = NULL

set alternate to ans1.txt
set alternate on
set console off
? ans
set console on
set alternate off
set alternate to

use pTable
append from ans1.txt delim
use
select count(*) as nNr from pTable where fProcess is not null

titleString = "Searching for " + cProcess
msgString = "There " + iif(nNr > 1 or nNr = 0, "are ", "is ") + ;
nNr + " open " + iif(nNr > 1 or nNr = 0, "instances", "instance") + ;
" of " + cProcess

msgbox(msgString, titleString, 0)

use
drop table pTable
delete file "ans1.txt"
//-----
wagner
2008-10-17 14:52:56 UTC
Permalink
Post by unknown
On Thu, 16 Oct 2008 14:08:28 -0400 Wagner
Newsgroup: dbase.programming
Post by Wagner
How do you know the number of applications that are running.
For example, if I run the WordPad.exe twice, as in my application dBase know that this WordPad.exe running two copies (stays)
Try the code below my signature. It is based upon code published by Rich, Autotracker. I modified it
to filter out only the exe searched for.
getProcess("WordPad.exe")
The way I parse the result is not pretty, but I did not have time to find a more elegant way, after
all, it is only an example :-)
Ivar B. Jessen
//-----
function getProcess(cProcess)
cProcess = lower(cProcess)
if file( "pTable.dbf")
drop table pTable
endif
if file("ans1.txt")
delete file "ans1.txt"
endif
create table pTable(fProcess char(15), fProcID integer)
#define vbCrLf chr(13)+chr(10)
extern CLONG GetCurrentProcessId( CVOID ) kernel32
plusHandle = str(GetCurrentProcessID())
sc = new OleAutoClient("MSScriptControl.ScriptControl")
sc.language = "JScript"
str = [function getProcesses(){] + vbCrLf
// Get Object and create enumerator
str += [ var e = new Enumerator( GetObject( "winmgmts:" ).InstancesOf("Win32_process" ) );] +
vbCrLf
// Variable to hold the info we find
str += [ var msg = "" + "\n";] + vbCrLf
// Loop through processes
str += [ for (;!e.atEnd();e.moveNext())] + vbCrLf
str += [ {] + vbCrLf
// Get object from enumerator
str += [ var p = e.item ();] + vbCrLf
// Add process based on name match
str += [ if ( p.Name == ']+cProcess+[' ) {;] + vbCrLf
// Format message with process name and handle
str += [ msg += p.Name + "," + p.Handle + "\n";] + vbCrLf
str += [ }] + vbCrLf
str += [ }] + vbCrLf
// Return the process names and handles
str += [return msg;] + vbCrLf
str += [}] + vbCrLf
sc.addCode( str )
ans = sc.run("getProcesses")
release object sc
sc = NULL
set alternate to ans1.txt
set alternate on
set console off
? ans
set console on
set alternate off
set alternate to
use pTable
append from ans1.txt delim
use
select count(*) as nNr from pTable where fProcess is not null
titleString = "Searching for " + cProcess
msgString = "There " + iif(nNr > 1 or nNr = 0, "are ", "is ") + ;
nNr + " open " + iif(nNr > 1 or nNr = 0, "instances", "instance") + ;
" of " + cProcess
msgbox(msgString, titleString, 0)
use
drop table pTable
delete file "ans1.txt"
//-----
I took the liberty to do some changes
=======================
function getProcess(cProcess)
local plusHandle,sc,str,ans

cProcess = lower(cProcess)

if substr(cProcess,len(cProcess)-3) <> '.exe'
cProcess += '.exe'
endif

#define vbCrLf chr(13)+chr(10)

extern CLONG GetCurrentProcessId( CVOID ) kernel32
plusHandle = str(GetCurrentProcessID())

sc = new OleAutoClient("MSScriptControl.ScriptControl")
sc.language = "JScript"

str = [function getProcesses(){] + vbCrLf

// Get Object and create enumerator
str += [ var e = new Enumerator( GetObject( "winmgmts:" ).InstancesOf("Win32_process" ) );] + vbCrLf

// Variable to hold the info we find
str += [ var msg = "" + "\n";] + vbCrLf

// Loop through processes
str += [ for (;!e.atEnd();e.moveNext())] + vbCrLf
str += [ {] + vbCrLf

// Get object from enumerator
str += [ var p = e.item ();] + vbCrLf

// Add process based on name match
// str += [ if ( p.Name == ']+cProcess+[' ) {;] + vbCrLf
// Format message with process name and handle
str += [ msg += p.Name + "," + p.Handle + "\n";] + vbCrLf
// str += [ }] + vbCrLf
str += [ }] + vbCrLf
// Return the process names and handles
str += [return msg;] + vbCrLf
str += [}] + vbCrLf

sc.addCode( str )
ans = sc.run("getProcesses")
ans = lower(ans)
release object sc
sc = NULL

? cProcess
RETURN nsub(cProcess,ans)

/*=============================================================================
FUNCAO : nsub( expC1,expC2 )

OBJETIVO : numero de vezes que uma sub-string se repete em uma string.

ENTRADA : expC1 = sub_string a ser procurada
expC2 = string a onde ocorrera a busca

RETORNO : expN = retorna quantidade de ocorrencias.

=============================================================================*/
function nsub(pSubString,pString)
local tamanho,String,SubString

String = pString
SubString = pSubString

tamanho = len( string )

string = strtran( string , SubString )

return int(( tamanho - len( String ) ) / len(SubString))
Rich - AutoTraker Inc.
2008-10-17 18:04:26 UTC
Permalink
I see a potencial problem. You changed the name of the process to find to
lower case. JScript is like dBASE in that case must be the same to find a
match.
so "PLUS.exe" may not equil to "plus.exe". I suggest changing the if
statement to use the same case all the time.
str += [ if ( p.Name.toLowerCase() == ']+cProcess.toLowerCase()+[' )
{;] + vbCrLf

Rich...
Post by wagner
Post by unknown
On Thu, 16 Oct 2008 14:08:28 -0400 Wagner
Newsgroup: dbase.programming
Post by Wagner
How do you know the number of applications that are running.
For example, if I run the WordPad.exe twice, as in my application dBase
know that this WordPad.exe running two copies (stays)
Try the code below my signature. It is based upon code published by Rich,
Autotracker. I modified it
to filter out only the exe searched for.
getProcess("WordPad.exe")
The way I parse the result is not pretty, but I did not have time to find
a more elegant way, after
all, it is only an example :-)
Ivar B. Jessen
//-----
function getProcess(cProcess)
cProcess = lower(cProcess)
if file( "pTable.dbf")
drop table pTable
endif
if file("ans1.txt")
delete file "ans1.txt"
endif
create table pTable(fProcess char(15), fProcID integer)
#define vbCrLf chr(13)+chr(10)
extern CLONG GetCurrentProcessId( CVOID ) kernel32
plusHandle = str(GetCurrentProcessID())
sc = new OleAutoClient("MSScriptControl.ScriptControl")
sc.language = "JScript"
str = [function getProcesses(){] + vbCrLf
// Get Object and create enumerator
str += [ var e = new Enumerator( GetObject(
"winmgmts:" ).InstancesOf("Win32_process" ) );] +
vbCrLf
// Variable to hold the info we find
str += [ var msg = "" + "\n";] + vbCrLf
// Loop through processes
str += [ for (;!e.atEnd();e.moveNext())] + vbCrLf
str += [ {] + vbCrLf
// Get object from enumerator
str += [ var p = e.item ();] + vbCrLf
// Add process based on name match
str += [ if ( p.Name == ']+cProcess+[' ) {;] + vbCrLf
// Format message with process name and handle
str += [ msg += p.Name + "," + p.Handle + "\n";] + vbCrLf
str += [ }] + vbCrLf
str += [ }] + vbCrLf
// Return the process names and handles
str += [return msg;] + vbCrLf
str += [}] + vbCrLf
sc.addCode( str )
ans = sc.run("getProcesses")
release object sc
sc = NULL
set alternate to ans1.txt
set alternate on
set console off
? ans
set console on
set alternate off
set alternate to
use pTable
append from ans1.txt delim
use
select count(*) as nNr from pTable where fProcess is not null
titleString = "Searching for " + cProcess
msgString = "There " + iif(nNr > 1 or nNr = 0, "are ", "is ") + ;
nNr + " open " + iif(nNr > 1 or nNr = 0, "instances", "instance") + ;
" of " + cProcess
msgbox(msgString, titleString, 0)
use
drop table pTable
delete file "ans1.txt"
//-----
I took the liberty to do some changes
=======================
function getProcess(cProcess)
local plusHandle,sc,str,ans
cProcess = lower(cProcess)
if substr(cProcess,len(cProcess)-3) <> '.exe'
cProcess += '.exe'
endif
#define vbCrLf chr(13)+chr(10)
extern CLONG GetCurrentProcessId( CVOID ) kernel32
plusHandle = str(GetCurrentProcessID())
sc = new OleAutoClient("MSScriptControl.ScriptControl")
sc.language = "JScript"
str = [function getProcesses(){] + vbCrLf
// Get Object and create enumerator
str += [ var e = new Enumerator( GetObject(
"winmgmts:" ).InstancesOf("Win32_process" ) );] + vbCrLf
// Variable to hold the info we find
str += [ var msg = "" + "\n";] + vbCrLf
// Loop through processes
str += [ for (;!e.atEnd();e.moveNext())] + vbCrLf
str += [ {] + vbCrLf
// Get object from enumerator
str += [ var p = e.item ();] + vbCrLf
// Add process based on name match
// str += [ if ( p.Name == ']+cProcess+[' ) {;] + vbCrLf
// Format message with process name and handle
str += [ msg += p.Name + "," + p.Handle + "\n";] + vbCrLf
// str += [ }] + vbCrLf
str += [ }] + vbCrLf
// Return the process names and handles
str += [return msg;] + vbCrLf
str += [}] + vbCrLf
sc.addCode( str )
ans = sc.run("getProcesses")
ans = lower(ans)
release object sc
sc = NULL
? cProcess
RETURN nsub(cProcess,ans)
/*=============================================================================
FUNCAO : nsub( expC1,expC2 )
OBJETIVO : numero de vezes que uma sub-string se repete em uma string.
ENTRADA : expC1 = sub_string a ser procurada
expC2 = string a onde ocorrera a busca
RETORNO : expN = retorna quantidade de ocorrencias.
=============================================================================*/
function nsub(pSubString,pString)
local tamanho,String,SubString
String = pString
SubString = pSubString
tamanho = len( string )
string = strtran( string , SubString )
return int(( tamanho - len( String ) ) / len(SubString))
unknown
2008-10-17 19:07:55 UTC
Permalink
On Fri, 17 Oct 2008 14:04:26 -0400 Rich - AutoTraker Inc.
Sender: "Rich - AutoTraker Inc." <***@autotraker.com>
wrote the following in:
Newsgroup: dbase.programming
Post by Rich - AutoTraker Inc.
I see a potencial problem. You changed the name of the process to find to
lower case. JScript is like dBASE in that case must be the same to find a
match.
so "PLUS.exe" may not equil to "plus.exe". I suggest changing the if
statement to use the same case all the time.
str += [ if ( p.Name.toLowerCase() == ']+cProcess.toLowerCase()+[' )
{;] + vbCrLf
Rich,

That solved the case problem for the code I posted. Thanks.

As I don't know visual basic or javascript I have a couple of questions.

1) What does the term "\n" in the following lines do?

str += [ var msg = "" + "\n";] + vbCrLf
str += [ msg += p.Name + "," + p.Handle + "\n";] + vbCrLf

2) Is there a way to get the number of running instances of WordPad.exe directly by modifying your
code, instead of the convoluted way I used?


Ivar B. Jessen
Greg Hill
2008-10-17 19:29:42 UTC
Permalink
Post by unknown
On Fri, 17 Oct 2008 14:04:26 -0400 Rich - AutoTraker Inc.
Newsgroup: dbase.programming
Post by Rich - AutoTraker Inc.
I see a potencial problem. You changed the name of the process to find to
lower case. JScript is like dBASE in that case must be the same to find a
match.
so "PLUS.exe" may not equil to "plus.exe". I suggest changing the if
statement to use the same case all the time.
str += [ if ( p.Name.toLowerCase() ==
']+cProcess.toLowerCase()+[' )
{;] + vbCrLf
Rich,
That solved the case problem for the code I posted. Thanks.
As I don't know visual basic or javascript I have a couple of questions.
1) What does the term "\n" in the following lines do?
\n is a carriage return, the same as using chr(13) in dBASE.

Greg Hill
unknown
2008-10-17 19:50:43 UTC
Permalink
On Fri, 17 Oct 2008 12:29:42 -0700 Greg Hill
Sender: "Greg Hill" <***@hotmail.com>
wrote the following in:
Newsgroup: dbase.programming
Post by Greg Hill
Post by unknown
1) What does the term "\n" in the following lines do?
\n is a carriage return, the same as using chr(13) in dBASE.
Greg Hill
Thanks, the same as Newline in Regular Expressions, I should have known :-(


Ivar B. Jessen
Rich - AutoTraker Inc.
2008-10-17 22:20:26 UTC
Permalink
the \n is a line feed

If you just want a count of how many instances of WordPad.exe, try the below
code
Rich...

objLocator = new OleAutoClient("WbemScripting.SWbemLocator")
objWMI=objLocator.ConnectServer(".", "root\cimv2")
objWMI.Security_.ImpersonationLevel=3 // Impersonate
oItems = objWMI.ExecQuery("Select * from Win32_Process where Name =
'wordpad.exe'")
? oItems.count
release object objWMI
release object objLocator
Post by unknown
On Fri, 17 Oct 2008 14:04:26 -0400 Rich - AutoTraker Inc.
Newsgroup: dbase.programming
Post by Rich - AutoTraker Inc.
I see a potencial problem. You changed the name of the process to find to
lower case. JScript is like dBASE in that case must be the same to find a
match.
so "PLUS.exe" may not equil to "plus.exe". I suggest changing the if
statement to use the same case all the time.
str += [ if ( p.Name.toLowerCase() ==
']+cProcess.toLowerCase()+[' )
{;] + vbCrLf
Rich,
That solved the case problem for the code I posted. Thanks.
As I don't know visual basic or javascript I have a couple of questions.
1) What does the term "\n" in the following lines do?
str += [ var msg = "" + "\n";] + vbCrLf
str += [ msg += p.Name + "," + p.Handle + "\n";] + vbCrLf
2) Is there a way to get the number of running instances of WordPad.exe
directly by modifying your
code, instead of the convoluted way I used?
Ivar B. Jessen
unknown
2008-10-18 20:25:35 UTC
Permalink
On Fri, 17 Oct 2008 18:20:26 -0400 Rich - AutoTraker Inc.
Sender: "Rich - AutoTraker Inc." <***@autotraker.com>
wrote the following in:
Newsgroup: dbase.programming
Post by Rich - AutoTraker Inc.
the \n is a line feed
If you just want a count of how many instances of WordPad.exe, try the below
code
Rich...
objLocator = new OleAutoClient("WbemScripting.SWbemLocator")
objWMI=objLocator.ConnectServer(".", "root\cimv2")
objWMI.Security_.ImpersonationLevel=3 // Impersonate
oItems = objWMI.ExecQuery("Select * from Win32_Process where Name =
'wordpad.exe'")
? oItems.count
release object objWMI
release object objLocator
Aha, this code is easier to understand that your previous one, and I was able to use it to extract
the CreationDate and the CommandLine from a running instance of PlusRun.exe ( or any other exe ).

If an exe is started with a command line or with a parameter, the code below will print out the
Creation Date and the Command Line or the Parameter.

It would also be possibel to extract for example the handles for the exe files.

Watch out for word wrap.

Ivar B. Jessen

//-----
/*

Example of use

Start exe files:
run(true, "testProcess2.exe")
run(true, "testProcess1.exe testProcess1.exe") // Use file name as parameter
run(true,"D:\Programmer\dbase\Plus221\Runtime\PlusRun.exe
D:\vdbproj\Utilities\GetRunningProcess\testProcess2.exe")

Get open instances:
getNamedProcess("PlusRun.exe")

Result

3 instances of PlusRun.exe found
--------------------------------------------------
Created Date Command Line

18-10-2008 21:39:56
18-10-2008 21:49:19 D:\vdbproj\Utilities\GetRunningProcess\testProcess2.exe
18-10-2008 22:01:32 testProcess1.exe
*/

function getNamedProcess(cProcess)
*clear
objLocator = new OleAutoClient("WbemScripting.SWbemLocator")
objWMI = objLocator.ConnectServer(".", "root\cimv2")
objWMI.Security_.ImpersonationLevel = 3 // Impersonate
oItems = objWMI.ExecQuery("Select * from Win32_Process where Name = " + ['] + cProcess + ['])
nItems = oItems.count

? nItems + " instances of " + cProcess + " found" at 5
? replicate("-", 50) at 5
? "Created Date" at 5, "Command Line" at 35
?

for i = 0 to oItems.count - 1
for j = 0 to oItems[i].Properties_.count - 1
if oItems[i].Properties_[j].Name.toLowerCase() == "commandline"
cCmdLine = oItems[i].Properties_[j].value
cParam = cCmdLine.right((len(cCmdLine) - rat(" ", cCmdLine)))
endif
next j
for j = 0 to oItems[i].Properties_.count - 1
if oItems[i].Properties_[j].Name.toLowerCase() == "creationdate"
cCreDate = oItems[i].Properties_[j].value
cDate = dtodt(new date(transform(""+cCreDate,"@R 9999,99,99 99:99:99")))
endif
next j
? cDate at 5, cParam at 35
// ? oItems[i].Properties_[j].Name at 5, oItems[i].Properties_[j].value at 35
next i

release object objWMI
release object objLocator
//-----
Rich - AutoTraker Inc.
2008-10-19 13:37:32 UTC
Permalink
dBASE's OleAutoClient will not allow using "winmgmts:" directly so the other
code used the ScriptControl to run JScript which does have a GetObject which
supports winmgmts.
By using this method which is designed actually to access remote machines we
have some of the abilities of Windows Management Instrument.
We can of course get all information on all running processes by removing
the where clause.
Its amazing what information is actually available to you.

Since the dBASE application is a loader app for the runtime, a tipical
command line for the runtime may look like this
"C:\Program Files\dBASE\PLUS\Runtime\PLUSRUN.EXE" -***@005608A0
Which I believe is the memory location of where your code has been placed by
the loader but I haven't as yet determined how to view it.
Rich...

objLocator = new OleAutoClient("WbemScripting.SWbemLocator")
objWMI=objLocator.ConnectServer(".", "root\cimv2")
objWMI.Security_.ImpersonationLevel=3 // Impersonate
oItems = objWMI.ExecQuery("Select * from Win32_Process")
for i = 1 to oItems.count
for j = 1 to oItems[i-1].properties_.count()
a = oItems[i-1].properties_[j-1]
? "Win32_Process."+a.name +"="+ new
string(""+a.value).leftTrim().rightTrim()
endfor
endfor
Post by unknown
On Fri, 17 Oct 2008 18:20:26 -0400 Rich - AutoTraker Inc.
Newsgroup: dbase.programming
Post by Rich - AutoTraker Inc.
the \n is a line feed
If you just want a count of how many instances of WordPad.exe, try the below
code
Rich...
objLocator = new OleAutoClient("WbemScripting.SWbemLocator")
objWMI=objLocator.ConnectServer(".", "root\cimv2")
objWMI.Security_.ImpersonationLevel=3 // Impersonate
oItems = objWMI.ExecQuery("Select * from Win32_Process where Name =
'wordpad.exe'")
? oItems.count
release object objWMI
release object objLocator
Aha, this code is easier to understand that your previous one, and I was
able to use it to extract
the CreationDate and the CommandLine from a running instance of
PlusRun.exe ( or any other exe ).
If an exe is started with a command line or with a parameter, the code
below will print out the
Creation Date and the Command Line or the Parameter.
It would also be possibel to extract for example the handles for the exe files.
Watch out for word wrap.
Ivar B. Jessen
//-----
/*
Example of use
run(true, "testProcess2.exe")
run(true, "testProcess1.exe testProcess1.exe") // Use file name as parameter
run(true,"D:\Programmer\dbase\Plus221\Runtime\PlusRun.exe
D:\vdbproj\Utilities\GetRunningProcess\testProcess2.exe")
getNamedProcess("PlusRun.exe")
Result
3 instances of PlusRun.exe found
--------------------------------------------------
Created Date Command Line
18-10-2008 21:39:56
18-10-2008 21:49:19
D:\vdbproj\Utilities\GetRunningProcess\testProcess2.exe
18-10-2008 22:01:32 testProcess1.exe
*/
function getNamedProcess(cProcess)
*clear
objLocator = new OleAutoClient("WbemScripting.SWbemLocator")
objWMI = objLocator.ConnectServer(".", "root\cimv2")
objWMI.Security_.ImpersonationLevel = 3 // Impersonate
oItems = objWMI.ExecQuery("Select * from Win32_Process where Name = " +
['] + cProcess + ['])
nItems = oItems.count
? nItems + " instances of " + cProcess + " found" at 5
? replicate("-", 50) at 5
? "Created Date" at 5, "Command Line" at 35
?
for i = 0 to oItems.count - 1
for j = 0 to oItems[i].Properties_.count - 1
if oItems[i].Properties_[j].Name.toLowerCase() == "commandline"
cCmdLine = oItems[i].Properties_[j].value
cParam = cCmdLine.right((len(cCmdLine) - rat(" ", cCmdLine)))
endif
next j
for j = 0 to oItems[i].Properties_.count - 1
if oItems[i].Properties_[j].Name.toLowerCase() == "creationdate"
cCreDate = oItems[i].Properties_[j].value
endif
next j
? cDate at 5, cParam at 35
// ? oItems[i].Properties_[j].Name at 5, oItems[i].Properties_[j].value at
35
next i
release object objWMI
release object objLocator
//-----
unknown
2008-10-20 19:22:37 UTC
Permalink
On Sun, 19 Oct 2008 09:37:32 -0400 Rich - AutoTraker Inc.
Sender: "Rich - AutoTraker Inc." <***@autotraker.com>
wrote the following in:
Newsgroup: dbase.programming
Post by Rich - AutoTraker Inc.
Since the dBASE application is a loader app for the runtime, a tipical
command line for the runtime may look like this
Which I believe is the memory location of where your code has been placed by
the loader but I haven't as yet determined how to view it.
Rich...
If it is you own dbase application is <MyApp.exe> and you start it with the following RUN command:

run(true, "<path to PlusRun.exe> <Path to <MyApp.exe>")

the command line will be (with my setup):

"D:\Programmer\dbase\Plus221\Runtime\PlusRun.exe
D:\vdbproj\Utilities\GetRunningProcess\testProcess2.exe")

So now you do not need to find the code in memory, you know what the code is.

If you have started several instances of the same code you could include a parameter in the run
command and that parameter will be included in the CommandLine. If the start parameter is also
included the title bar of the started instance you can then identify each of the several instances
of the same code.

This should be enough information to at least close a specific running instance programmatically.


Ivar B. Jessen
Post by Rich - AutoTraker Inc.
Post by unknown
Newsgroup: dbase.programming
Post by Rich - AutoTraker Inc.
the \n is a line feed
If you just want a count of how many instances of WordPad.exe, try the below
code
Rich...
objLocator = new OleAutoClient("WbemScripting.SWbemLocator")
objWMI=objLocator.ConnectServer(".", "root\cimv2")
objWMI.Security_.ImpersonationLevel=3 // Impersonate
oItems = objWMI.ExecQuery("Select * from Win32_Process where Name =
'wordpad.exe'")
? oItems.count
release object objWMI
release object objLocator
Aha, this code is easier to understand that your previous one, and I was
able to use it to extract
the CreationDate and the CommandLine from a running instance of
PlusRun.exe ( or any other exe ).
If an exe is started with a command line or with a parameter, the code
below will print out the
Creation Date and the Command Line or the Parameter.
It would also be possibel to extract for example the handles for the exe files.
Watch out for word wrap.
Ivar B. Jessen
//-----
/*
Example of use
run(true, "testProcess2.exe")
run(true, "testProcess1.exe testProcess1.exe") // Use file name as parameter
run(true,"D:\Programmer\dbase\Plus221\Runtime\PlusRun.exe
D:\vdbproj\Utilities\GetRunningProcess\testProcess2.exe")
getNamedProcess("PlusRun.exe")
Result
3 instances of PlusRun.exe found
--------------------------------------------------
Created Date Command Line
18-10-2008 21:39:56
18-10-2008 21:49:19
D:\vdbproj\Utilities\GetRunningProcess\testProcess2.exe
18-10-2008 22:01:32 testProcess1.exe
*/
function getNamedProcess(cProcess)
*clear
objLocator = new OleAutoClient("WbemScripting.SWbemLocator")
objWMI = objLocator.ConnectServer(".", "root\cimv2")
objWMI.Security_.ImpersonationLevel = 3 // Impersonate
oItems = objWMI.ExecQuery("Select * from Win32_Process where Name = " +
['] + cProcess + ['])
nItems = oItems.count
? nItems + " instances of " + cProcess + " found" at 5
? replicate("-", 50) at 5
? "Created Date" at 5, "Command Line" at 35
?
for i = 0 to oItems.count - 1
for j = 0 to oItems[i].Properties_.count - 1
if oItems[i].Properties_[j].Name.toLowerCase() == "commandline"
cCmdLine = oItems[i].Properties_[j].value
cParam = cCmdLine.right((len(cCmdLine) - rat(" ", cCmdLine)))
endif
next j
for j = 0 to oItems[i].Properties_.count - 1
if oItems[i].Properties_[j].Name.toLowerCase() == "creationdate"
cCreDate = oItems[i].Properties_[j].value
endif
next j
? cDate at 5, cParam at 35
// ? oItems[i].Properties_[j].Name at 5, oItems[i].Properties_[j].value at
35
next i
release object objWMI
release object objLocator
//-----
wagner
2008-10-20 20:41:03 UTC
Permalink
Post by Rich - AutoTraker Inc.
dBASE's OleAutoClient will not allow using "winmgmts:" directly so the other
code used the ScriptControl to run JScript which does have a GetObject which
supports winmgmts.
By using this method which is designed actually to access remote machines we
have some of the abilities of Windows Management Instrument.
We can of course get all information on all running processes by removing
the where clause.
Its amazing what information is actually available to you.
Since the dBASE application is a loader app for the runtime, a tipical
command line for the runtime may look like this
Which I believe is the memory location of where your code has been placed by
the loader but I haven't as yet determined how to view it.
Rich...
objLocator = new OleAutoClient("WbemScripting.SWbemLocator")
objWMI=objLocator.ConnectServer(".", "root\cimv2")
objWMI.Security_.ImpersonationLevel=3 // Impersonate
oItems = objWMI.ExecQuery("Select * from Win32_Process")
for i = 1 to oItems.count
for j = 1 to oItems[i-1].properties_.count()
a = oItems[i-1].properties_[j-1]
? "Win32_Process."+a.name +"="+ new
string(""+a.value).leftTrim().rightTrim()
endfor
endfor
Post by unknown
On Fri, 17 Oct 2008 18:20:26 -0400 Rich - AutoTraker Inc.
Newsgroup: dbase.programming
Post by Rich - AutoTraker Inc.
the \n is a line feed
If you just want a count of how many instances of WordPad.exe, try the below
code
Rich...
objLocator = new OleAutoClient("WbemScripting.SWbemLocator")
objWMI=objLocator.ConnectServer(".", "root\cimv2")
objWMI.Security_.ImpersonationLevel=3 // Impersonate
oItems = objWMI.ExecQuery("Select * from Win32_Process where Name =
'wordpad.exe'")
? oItems.count
release object objWMI
release object objLocator
Aha, this code is easier to understand that your previous one, and I was
able to use it to extract
the CreationDate and the CommandLine from a running instance of
PlusRun.exe ( or any other exe ).
If an exe is started with a command line or with a parameter, the code
below will print out the
Creation Date and the Command Line or the Parameter.
It would also be possibel to extract for example the handles for the exe files.
Watch out for word wrap.
Ivar B. Jessen
//-----
/*
Example of use
run(true, "testProcess2.exe")
run(true, "testProcess1.exe testProcess1.exe") // Use file name as parameter
run(true,"D:\Programmer\dbase\Plus221\Runtime\PlusRun.exe
D:\vdbproj\Utilities\GetRunningProcess\testProcess2.exe")
getNamedProcess("PlusRun.exe")
Result
3 instances of PlusRun.exe found
--------------------------------------------------
Created Date Command Line
18-10-2008 21:39:56
18-10-2008 21:49:19
D:\vdbproj\Utilities\GetRunningProcess\testProcess2.exe
18-10-2008 22:01:32 testProcess1.exe
*/
function getNamedProcess(cProcess)
*clear
objLocator = new OleAutoClient("WbemScripting.SWbemLocator")
objWMI = objLocator.ConnectServer(".", "root\cimv2")
objWMI.Security_.ImpersonationLevel = 3 // Impersonate
oItems = objWMI.ExecQuery("Select * from Win32_Process where Name = " +
['] + cProcess + ['])
nItems = oItems.count
? nItems + " instances of " + cProcess + " found" at 5
? replicate("-", 50) at 5
? "Created Date" at 5, "Command Line" at 35
?
for i = 0 to oItems.count - 1
for j = 0 to oItems[i].Properties_.count - 1
if oItems[i].Properties_[j].Name.toLowerCase() == "commandline"
cCmdLine = oItems[i].Properties_[j].value
cParam = cCmdLine.right((len(cCmdLine) - rat(" ", cCmdLine)))
endif
next j
for j = 0 to oItems[i].Properties_.count - 1
if oItems[i].Properties_[j].Name.toLowerCase() == "creationdate"
cCreDate = oItems[i].Properties_[j].value
endif
next j
? cDate at 5, cParam at 35
// ? oItems[i].Properties_[j].Name at 5, oItems[i].Properties_[j].value at
35
next i
release object objWMI
release object objLocator
//-----
Problem solved!
Very grateful to all.

wagner
2008-10-17 15:03:33 UTC
Permalink
Post by Wagner
How do you know the number of applications that are running.
For example, if I run the WordPad.exe twice, as in my application dBase know that this WordPad.exe running two copies (stays)
I have an application developed in dBase Plus with the name Myprg.exe, perceby the Windows Task Manager that it appears as PLUSrun.exe, if called more than once the same MyPrg1.exe it appears another PLUSrun.exe, how to identify which this running?
Rich - AutoTraker Inc.
2008-10-17 22:40:12 UTC
Permalink
You can't. The dBASE application EXE is just a loader for the runtime and
doesn't stay in memory.
There is no way to know what code or application each runtime instance is
running. This is something they really need to change.
Each instance of the runtime has a unique command line and PID. Maybe this
is of some help.

But if the window thats visible has a different title you can look for the
window title.
As Greg suggested I think there is code in appMGR32.prg to do that.
If not I'm sure I have code someplace to do that.

Another way if you are trying to keep from having the application run more
than one session at a time.
I use the exact same title in my applcation and when the second session
starts it looks for that title already in a window and if it finds it it
terminates.

Rich...
Post by wagner
Post by Wagner
How do you know the number of applications that are running.
For example, if I run the WordPad.exe twice, as in my application dBase
know that this WordPad.exe running two copies (stays)
I have an application developed in dBase Plus with the name Myprg.exe,
perceby the Windows Task Manager that it appears as PLUSrun.exe, if called
more than once the same MyPrg1.exe it appears another PLUSrun.exe, how to
identify which this running?
Loading...