View Full Version : [Visual C++] gestione processi
ciao gentilissimi amici.
sapete se esiste qualche API di windows che permetta di monitorare un determinato processo in esecuzione, controllandone per esempio l'occupazione in ram? e altre informazioni riguardo allo stato della macchina, quali: utilizzo cpu, banda rete lan, ecc.
vi ringrazio :)
variabilepippo
07-10-2008, 15:23
La Process API (PSAPI) ed i Performance Counters potrebbero tornarti utili. Per tutto il resto (e non solo) c'è WMI... :D
bellooo che ficataaaa!! :D grande!!
ma serve il .NET per sviluppare con queste moltitudini di API?
riesci a darmi qualche dritta in più? per adesso ho solo il Visual C++ 2005 express edition...:sofico:
Vincenzo1968
07-10-2008, 16:49
bellooo che ficataaaa!! :D grande!!
ma serve il .NET per sviluppare con queste moltitudini di API?
riesci a darmi qualche dritta in più? per adesso ho solo il Visual C++ 2005 express edition...:sofico:
Ciao Zhurlo,
no, non serve il .net per PSAPI. Puoi vedere qui:
http://msdn.microsoft.com/en-us/library/ms684884(VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms682050(VS.85).aspx
In .net ci sarà sicuramente qualcosa che ti facilita enormemente il compito. Ma non ti consiglio, in questo caso di usare il C++ con le estensioni per il CLR: molto meglio usare C#. La express edition puoi scaricarla gratuitamente.
variabilepippo
07-10-2008, 17:10
Un metodo migliore rispetto all'allocazione statica del buffer è mostrato in Enumerating Windows Processes (http://www.alexfedotov.com/articles/enumproc.asp):
The EnumProcesses function does not provide a way to know how much space is needed to receive all the identifiers. To deal with this limitation, we call EnumProcesses in a loop, increasing the the buffer size until the returned array size becomes less than the buffer size we allocated.
ciao ragazzi, ho provato qualche programmino di scripting in vbscript e mi sto divertendo un sacco :D
tipo questo:
' Check command line parameters
Select Case WScript.Arguments.Count
Case 0
' Default if none specified is local computer (".")
Set objWMIService = GetObject( "winmgmts://./root/cimv2" )
Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
For Each objItem in colItems
strComputer = objItem.Name
Next
Case 1
' Command line parameter can either be a computer
' name or "/?" to request online help
strComputer = UCase( Wscript.Arguments(0) )
if InStr( strComputer, "?" ) > 0 Then Syntax
Case Else
' Maximum is 1 command line parameter
Syntax
End Select
' Define constants
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
' Header line for screen output
strMsg = vbCrLf & "CPU type for " & strComputer & ":" & vbCrLf & vbCrLf
' Enable error handling
On Error Resume Next
' Connect to specified computer
Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
' Display error number and description if applicable
If Err Then ShowError
' Query processor properties
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
' Display error number and description if applicable
If Err Then ShowError
' Prepare display of results
For Each objItem In colItems
strMsg = strMsg _
& "Device ID : " & objItem.DeviceID & vbCrLf _
& "CPU Type : " & Strip( objItem.Name ) & vbCrLf & vbCrLf
Next
' Display results
WScript.Echo strMsg
'Done
WScript.Quit(0)
Sub ShowError()
strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _
Err.Description & vbCrLf & vbCrLf
Syntax
End Sub
Sub Syntax()
strMsg = strMsg & vbCrLf _
& "CPUType.vbs, Version 1.00" & vbCrLf _
& "Display CPU type for any computer " _
& "on the network" & vbCrLf & vbCrLf _
& "Usage: CSCRIPT //NOLOGO CPUTYPE.VBS " _
& "[ computer_name ]" & vbCrLf & vbCrLf _
& "Where: " & Chr(34) & "computer_name" & Chr(34) _
& " is the optional name of a remote" & vbCrLf _
& " computer (default is local computer " _
& "name)" & vbCrLf & vbCrLf _
& "Written by Rob van der Woude" & vbCrLf _
& "http://www.robvanderwoude.com" & vbCrLf & vbCrLf _
& "Created with Microsoft's Scriptomatic 2.0 tool" & vbCrLf _
& "http://www.microsoft.com/downloads/details.aspx?" & vbCrLf _
& " FamilyID=09dfc342-648b-4119-b7eb-783b0f7d1178&DisplayLang=en" & vbCrLf
WScript.Echo strMsg
WScript.Quit(1)
End Sub
Private Function Strip( strInput )
Do While Left( strInput, 1 ) = " "
strInput = Mid( strInput, 2 )
Loop
Strip = strInput
End Function
che stampa le informazioni legate alla CPU.
Ho qui per voi una domanda: è possibile inserire questo script all'interno di una pagina web e stampare il risultato all'interno della pagina? senza finestre di alert quindi.
Ho provato a inserire il codice all'interno dei TAG <script language="VBScript"></script>ma non stampa nulla (uso internet explorer 6.0)
più tardi proverò a scrivere un programmino in Visual C++, vedremo che succederà........ :sofico: :oink: :ciapet:
ciau raghi, ho provato a sosituire WScript.Echo con document.write, ma anche in questo caso non da segni di vita :(
aiutino?? :sofico: :mc: :sofico: :mc: :sofico:
altro problema: ho provato un semplice programmino in Visual C++ 2005 (Enterprise edition) ma quando faccio Build non mi trova la libreria <comdef.h> e neanche <Wbemidl.h>
come faccio? :cry:
altro problema: ho provato un semplice programmino in Visual C++ 2005 (Enterprise edition) ma quando faccio Build non mi trova la libreria <comdef.h> e neanche <Wbemidl.h>
come faccio? :cry:
aiutino riguardo questo problema irrisolto? :mc:
Ho risolto installando l'SDK :D grazie raghiiiii :D :D :D :sofico: :D :D :oink: :ciapet:
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.