Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get the usage of the cpu? 3

Status
Not open for further replies.

Hannes214

IS-IT--Management
Jan 30, 2006
45
DE
Hi :)

I have an other problem too...
I need to know, how many the CPU is in use...
I don't want to enumerate the running processes.... only the usage of the CPU ... can someona help ???



 
Can nobody help me?

I only need to know the usage / exploitation of the CPU...

...for a little application, thats inform me, if the usage / exploitation is a special time over 90% ....

IT-Management
( an FoxPro-Newbi :eek:) )
 

The Application should run without human help!
I don't wanne sit before the screen the whole time and look at the Task Manager......

IT-Management
( an FoxPro-Newbi :eek:) )
 
Thanks for so far...

but only FoxPro-Code would be much better ^^

...perhaps, someone else has some ideas...

IT-Management
( an FoxPro-Newbi :eek:) )
 
..and the programm always shows 100 % ...

IT-Management
( an FoxPro-Newbi :eek:) )
 

only FoxPro-Code would be much better

Forget it. There's no pure FoxPro command or function that does what you want.

Try the DLL that Jim suggested. The fact that it's written in VB shouldn't make any difference. You can still access it from your VFP program.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
yes.. but it shows 100% the whole time.. there must be something wrong...

IT-Management
( an FoxPro-Newbi :eek:) )
 

Can you contact the people who wrote it?
no... :(

Why not? Their website link is provided on Universal Thread where you got the library, and the site has some e-mail info. You can at least try.
 
Reports Process CPU time to date in seconds. You can compare it to seconds() at start time to current seconds() with a timer and do a % calc yourself.

Code:
lcExeName=[vfp7.exe]

lcComputer = "."
loWMIService = Getobject("winmgmts:" ;
    + "{impersonationLevel=impersonate}!\\" + lcComputer + "\root\cimv2")
colProcessList = loWMIService.ExecQuery ;
    ("Select * from Win32_Process")

FOR EACH loProcess In colProcessList
  IF TRANSFORM(loProcess.Name)=lcExeName
    ? "Name "+ TRANSFORM(loProcess.Name)
    ? "Process ID: " + TRANS(loProcess.ProcessID)
    ? "App Command Line: " + TRANS(loProcess.CommandLine)
    ? "CPU usage to date: " + ;
          TRANSFORM((VAL(loProcess.KernelModeTime)+;
          VAL(loProcess.UserModeTime)) / 10000000)
  ENDIF 
NEXT
 
Do I need FoxPro 7 for the code or is FoxPro 6 enough?


IT-Management
( an FoxPro-Newbi :eek:) )
 
..next problem..
there is no WMI-install-software for Win 2k ox XP..
and the 4 offert install-programms abort with the information, that it only can install on a Win NT SP4 or Win 95/98 ...

now i realize, that my idee to get informations about the usage/utilization of the CPU is very difficult...

IT-Management
( an FoxPro-Newbi :eek:) )
 
WMI is part of XP or W2k, no need to install it there, I think. Simply try it. Change lcExename to [vfp6.exe] and it displays vfp6.exe cpu usage.

You may simply watch the 'System Idle Process', to compute idle time of the cpu rather than usage.

Code:
lcComputer = "."
loWMIService = Getobject("winmgmts:" ;
    + "{impersonationLevel=impersonate}!\\" + lcComputer + "\root\cimv2")
colProcessList = loWMIService.ExecQuery ;
    ("Select * from Win32_Process where name='System Idle Process'")

FOR EACH loProcess In colProcessList
    ? "Name "+ TRANSFORM(loProcess.Name)
    ? "Process ID: " + TRANS(loProcess.ProcessID)
    ? "App Command Line: " + TRANS(loProcess.CommandLine)
    ? "CPU usage to date: " + ;
          TRANSFORM((VAL(loProcess.KernelModeTime)+;
          VAL(loProcess.UserModeTime)) / 10000000)
NEXT

Bye, Olaf.
 

now i realize, that my idee to get informations about the usage/utilization of the CPU is very difficult...

The code that Baltman and Olaf posted seems to work fine. At least, it does for me. Just run it and see.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
I get the OLE-Error-Cod 0x800401ae for:

oWMIService = Getobject("winmgmts:" ;
+ "{impersonationLevel=impersonate}!\\" + lcComputer + "\root\cimv2")

.. That the File can't open by the "moniker" ???

IT-Management
( an FoxPro-Newbi :eek:) )
 
Are you seting lcComputer to the server name and execute this at a client machine? I'm getting the error then. This won't work that simple. Execute it with "." or the local computer name.

I get that same error if I insert a name of another machine in the LAN. It may be possible to do this remote, but I don't know how. The simplest would be compiling an exe and let that run directly on the server. If you want to run it while no one is logged on you need to make this a service, which is possible with VFP by using srvAny (google for it). If you need the information remote, then simply let that exe write a log file or table and browse that on your client...

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top