How many time my application is run in memory (SOLVED)

How many time my application is run in memory (SOLVED)

Postby Horizon » Fri May 13, 2022 8:39 pm

Hi,

I want to find out How many time my application is run in memory.

Can anyone help me where to start?

Thanks.
Last edited by Horizon on Sun May 15, 2022 10:06 am, edited 1 time in total.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1288
Joined: Fri May 23, 2008 1:33 pm

Re: How many time my application is run in memory

Postby rhlawek » Fri May 13, 2022 9:10 pm

Do you mean how long one of your programs has been running?

From powershell:

New-TimeSpan -Start (get-process <yourapplication>).StartTime

Internal to the program? I would just set a variable with DateTime() on entry, then diff that with current DateTime() to get total runtime of the app.
User avatar
rhlawek
 
Posts: 193
Joined: Sun Jul 22, 2012 7:01 pm

Re: How many time my application is run in memory

Postby rhlawek » Fri May 13, 2022 9:18 pm

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.
User avatar
rhlawek
 
Posts: 193
Joined: Sun Jul 22, 2012 7:01 pm

Re: How many time my application is run in memory

Postby rhlawek » Fri May 13, 2022 9:19 pm

(Get-Process | Where-Object {$_.Name -eq 'YourApp'}).count
User avatar
rhlawek
 
Posts: 193
Joined: Sun Jul 22, 2012 7:01 pm

Re: How many time my application is run in memory

Postby Horizon » Sat May 14, 2022 7:04 pm

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.


Yes this is.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1288
Joined: Fri May 23, 2008 1:33 pm

Re: How many time my application is run in memory

Postby Horizon » Sat May 14, 2022 7:07 pm

rhlawek wrote:(Get-Process | Where-Object {$_.Name -eq 'YourApp'}).count


As far as I know, in order to run powershell, firstly, we should install it. I could not install it to customer computer. I need something different.

Thank you.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1288
Joined: Fri May 23, 2008 1:33 pm

Re: How many time my application is run in memory

Postby Antonio Linares » Sat May 14, 2022 8:11 pm

Dear Hakan,

Do you mean that you want to allow just one single execution of your app ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41315
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: How many time my application is run in memory

Postby Horizon » Sat May 14, 2022 8:47 pm

Antonio Linares wrote:Dear Hakan,

Do you mean that you want to allow just one single execution of your app ?


Hi Antonio,

This is not my purpose. My application can run more than once instances.

I want to copy my app exe from server by using batch file at ConvertW32.exe.
Code: Select all  Expand view
                        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


for example, my customer runs two instance of my application. in this situation, I release a new version on server. My customer exit one program and run my application again (or run a new instance of my app), the new version found message comes. I want to find out how many instance of my app. run in memory at this computer. if more than one, I will warn my customer to exit other instances or I will force to close other instances.

Thats my purpose.

Using FindWindow() function find the first instance hWnd.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1288
Joined: Fri May 23, 2008 1:33 pm

Re: How many time my application is run in memory

Postby Antonio Linares » Sat May 14, 2022 9:20 pm

regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41315
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: How many time my application is run in memory

Postby Natter » Sun May 15, 2022 5:47 am

As a rule, the class name of the main window is TWindow (you can make a unique name) And using Enum() to determine the number of running instances of the task
Natter
 
Posts: 1120
Joined: Mon May 14, 2007 9:49 am

Re: How many time my application is run in memory

Postby Jimmy » Sun May 15, 2022 6:26 am

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
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1586
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: How many time my application is run in memory

Postby Antonio Linares » Sun May 15, 2022 7:58 am

many thanks Jimmy! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41315
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: How many time my application is run in memory (SOLVED)

Postby Horizon » Sun May 15, 2022 10:06 am

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


Thank you very much Jimmy. It works very well.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1288
Joined: Fri May 23, 2008 1:33 pm

Re: How many time my application is run in memory

Postby Horizon » Sun May 15, 2022 10:41 am

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


Hi Jimmy,

Is it possible to read Open Files in Shared folders via WMI?. (My Computer, Manage, System Tools, Shared folder, Open Files)

Thanks in advance.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1288
Joined: Fri May 23, 2008 1:33 pm

Re: How many time my application is run in memory (SOLVED)

Postby MarcoBoschi » Tue May 17, 2022 9:05 am

8)
User avatar
MarcoBoschi
 
Posts: 1015
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 77 guests