Hi,
I want to find out How many time my application is run in memory.
Can anyone help me where to start?
Thanks.
rhlawek wrote:And I just realized I may have misinterpreted the question. Are you asking how many instances of your application are in memory? (and not how long it's been running as I commented about.)
This can also still be done easily with powershell, though I'd need to look that up.
rhlawek wrote:(Get-Process | Where-Object {$_.Name -eq 'YourApp'}).count
Antonio Linares wrote:Dear Hakan,
Do you mean that you want to allow just one single execution of your app ?
cRelauFle := cFilePath(GetModuleFileName( GetInstance() ))+'\Relaunch.Bat'
hFile := FCreate( cRelauFle, 0 ) // 0 Normal/Default,Read/Write
if hFile >= 0
FWrite( hFile, "COPY "+::cRoot+"Convert32.exe "+cFilePath(GetModuleFileName( GetInstance() ))+"\Convert32.exe /Y" +CRLF )
FWrite( hFile, GetModuleFileName( GetInstance() ) +CRLF )
FWrite( hFile, "exit" +CRLF )
FClose( hFile )
SysRefresh()
*--
WinExec( cRelauFle, 0 ) // 0 not show Cmd.exe Window, 1 yes
ENDIF
QUIT
IF HowManyApp("Notepad.exe") > 1
MsgInfo("more that 1 Instance running ! ")
FUNCTION HowManyApp(cApp)
LOCAL oProcesses, oProcess, oWMI, oLocator
LOCAL nRet := 0
oLocator := CreateObject( "wbemScripting.SwbemLocator" )
IF EMPTY( oLocator )
msginfo( "can not create wbemScripting.SwbemLocator" )
RETURN 0
ELSE
oWMI := oLocator:ConnectServer()
ENDIF
IF EMPTY( oWMI )
msginfo( "can not connect oLocator:ConnectServer()" )
RETURN 0
ELSE
oProcesses = oWMI:ExecQuery( "SELECT * FROM Win32_Process" )
IF oProcesses:Count > 0
FOR EACH oProcess in oProcesses
IF UPPER( TRIM( oProcess:Name ) ) = UPPER( TRIM( cApp ) )
nRet += 1
ENDIF
NEXT
ENDIF
ENDIF
oProcesses := NIL
oWMI := NIL
oLocator := NIL
RETURN nRet
Jimmy wrote:hi,
when run same App "more" than once it will use same "Name" in each Instance
- Code: Select all Expand view
IF HowManyApp("Notepad.exe") > 1
MsgInfo("more that 1 Instance running ! ")
- Code: Select all Expand view
FUNCTION HowManyApp(cApp)
LOCAL oProcesses, oProcess, oWMI, oLocator
LOCAL nRet := 0
oLocator := CreateObject( "wbemScripting.SwbemLocator" )
IF EMPTY( oLocator )
msginfo( "can not create wbemScripting.SwbemLocator" )
RETURN 0
ELSE
oWMI := oLocator:ConnectServer()
ENDIF
IF EMPTY( oWMI )
msginfo( "can not connect oLocator:ConnectServer()" )
RETURN 0
ELSE
oProcesses = oWMI:ExecQuery( "SELECT * FROM Win32_Process" )
IF oProcesses:Count > 0
FOR EACH oProcess in oProcesses
IF UPPER( TRIM( oProcess:Name ) ) = UPPER( TRIM( cApp ) )
nRet += 1
ENDIF
NEXT
ENDIF
ENDIF
oProcesses := NIL
oWMI := NIL
oLocator := NIL
RETURN nRet
Jimmy wrote:hi,
when run same App "more" than once it will use same "Name" in each Instance
- Code: Select all Expand view
IF HowManyApp("Notepad.exe") > 1
MsgInfo("more that 1 Instance running ! ")
- Code: Select all Expand view
FUNCTION HowManyApp(cApp)
LOCAL oProcesses, oProcess, oWMI, oLocator
LOCAL nRet := 0
oLocator := CreateObject( "wbemScripting.SwbemLocator" )
IF EMPTY( oLocator )
msginfo( "can not create wbemScripting.SwbemLocator" )
RETURN 0
ELSE
oWMI := oLocator:ConnectServer()
ENDIF
IF EMPTY( oWMI )
msginfo( "can not connect oLocator:ConnectServer()" )
RETURN 0
ELSE
oProcesses = oWMI:ExecQuery( "SELECT * FROM Win32_Process" )
IF oProcesses:Count > 0
FOR EACH oProcess in oProcesses
IF UPPER( TRIM( oProcess:Name ) ) = UPPER( TRIM( cApp ) )
nRet += 1
ENDIF
NEXT
ENDIF
ENDIF
oProcesses := NIL
oWMI := NIL
oLocator := NIL
RETURN nRet
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 51 guests