Mes test et mes recherches sur wmi, processus et internet

Contenu du snippet

Il était une fois ou j'ai du faire des recherches sur l'utilisation des objets wmi et manipulation d'internet, concretement ça ne servira pas directement tel quel mais ç'est peut être pratique pour ceux qui pourrons recupérer les bouts de codes qui pourons leur être util. pas de zip, c'est à copier dans un .txt et renommer .vbs ou autre pg vb

Source / Exemple :


public sub quickList(arg,suffix)

dim obj
dim fw
dim fname
dim fserv
dim fsw
fname = GetTempFile("listingChampProcessIexp.txt")
fserv = GetTempFile("listingSercices.txt")
Set obj = WScript.CreateObject("Scripting.FileSystemObject")

'*******************************************************************************

if obj.fileExists(fname) then
fname = GetTempFile("listingChampProcessIexp" & suffix & ".txt")
end if

'*******************************************************************************

set fw = obj.createTextFile(fname,true)
set fsw = obj.createTextFile(fserv,true)
Set objWMI = GetObject("winmgmts:root\cimv2")

'*******************************************************************************
    reqVbs = "Select * from Win32_process"
For Each oproc In objWMI.execquery(reqVbs)
if oproc.Name="iexplore.exe" then

fw.writeline "Caption; " & oproc.Caption
fw.writeline   "CommandLine; " & oproc.CommandLine
fw.writeline   "CreationClassName; " & oproc.CreationClassName
fw.writeline   "CreationDate; " & oproc.CreationDate
fw.writeline   "CSCreationClassName; " & oproc.CSCreationClassName
fw.writeline   "CSName; " & oproc.CSName
fw.writeline   "Description; " & oproc.Description
fw.writeline   "ExecutablePath; " & oproc.ExecutablePath
fw.writeline   "ExecutionState; " & oproc.ExecutionState
fw.writeline   "Handle; " & oproc.Handle
fw.writeline   "HandleCount; " & oproc.HandleCount
fw.writeline   "InstallDate; " & oproc.InstallDate
fw.writeline   "KernelModeTime; " & oproc.KernelModeTime
fw.writeline   "MaximumWorkingSetSize; " & oproc.MaximumWorkingSetSize
fw.writeline   "MinimumWorkingSetSize; " & oproc.MinimumWorkingSetSize
fw.writeline   "Name; " & oproc.Name
fw.writeline   "OSCreationClassName; " & oproc.OSCreationClassName
fw.writeline   "OSName; " & oproc.OSName
fw.writeline   "OtherOperationCount; " & oproc.OtherOperationCount
fw.writeline   "OtherTransferCount; " & oproc.OtherTransferCount
fw.writeline   "PageFaults; " & oproc.PageFaults
fw.writeline   "PageFileUsage; " & oproc.PageFileUsage
fw.writeline   "ParentProcessId; " & oproc.ParentProcessId
fw.writeline   "PeakPageFileUsage; " & oproc.PeakPageFileUsage
fw.writeline  "PeakVirtualSize; " & oproc.PeakVirtualSize
fw.writeline   "PeakWorkingSetSize; " & oproc.PeakWorkingSetSize
fw.writeline   "Priority; " & oproc.Priority
fw.writeline   "PrivatePageCount; " & oproc.PrivatePageCount
fw.writeline   "ProcessId; " & oproc.ProcessId
fw.writeline   "QuotaNonPagedPoolUsage; " & oproc.QuotaNonPagedPoolUsage
fw.writeline   "QuotaPagedPoolUsage; " & oproc.QuotaPagedPoolUsage
fw.writeline   "QuotaPeakNonPagedPoolUsage; " & oproc.QuotaPeakNonPagedPoolUsage
fw.writeline   "QuotaPeakPagedPoolUsage; " & oproc.QuotaPeakPagedPoolUsage
fw.writeline   "ReadOperationCount; " & oproc.ReadOperationCount
fw.writeline   "ReadTransferCount; " & oproc.ReadTransferCount
fw.writeline   "SessionId; " & oproc.SessionId
fw.writeline   "Status; " & oproc.Status
fw.writeline   "TerminationDate; " & oproc.TerminationDate
fw.writeline   "ThreadCount; " & oproc.ThreadCount
fw.writeline   "UserModeTime; " & oproc.UserModeTime
fw.writeline   "VirtualSize; " & oproc.VirtualSize
fw.writeline   "WindowsVersion; " & oproc.WindowsVersion
fw.writeline   "WorkingSetSize; " & oproc.WorkingSetSize
fw.writeline   "WriteOperationCount; " & oproc.WriteOperationCount
fw.writeline   "WriteTransferCount; " & oproc.WriteTransferCount

end if ' FIN DE oproc.Name="iexplore.exe"
    Next
call jexecute(fname)

'*******************************************************************************

'*******************************************************************************

if arg then
reqVbs = "select * from win32_service"
For Each oproc In objWMI.execquery(reqVbs)

        'Wscript.echo oproc.Name & " = " & oproc.State
	fsw.writeline oproc.Name & " = " & oproc.State

    Next
call jexecute(fserv)

end if
    
fw.close
fsw.close
Set objWMI = Nothing
set obj = nothing

end sub

'*******************************************************************************
'*******************************************************************************
'*******************************************************************************
public sub pro()

'*******************************************************************************

dim obj
dim fw
dim fname
dim fserv
dim fsw
fname = GetTempFile("listingChampProcessIexp.txt")
fserv = GetTempFile("listingSercices.txt")
Set obj = WScript.CreateObject("Scripting.FileSystemObject")
set fw = obj.createTextFile(fname,true)
set fsw = obj.createTextFile(fserv,true)

Set objWMI = GetObject("winmgmts:root\cimv2")
'*******************************************************************************

if msgbox("liste process",vbyesNo,"liste process") = vbYes then
    reqVbs = "Select * from Win32_process"
For Each oproc In objWMI.execquery(reqVbs)
if oproc.Name="iexplore.exe" then

fw.writeline "Caption; " & oproc.Caption
fw.writeline   "CommandLine; " & oproc.CommandLine
fw.writeline   "CreationClassName; " & oproc.CreationClassName
fw.writeline   "CreationDate; " & oproc.CreationDate
fw.writeline   "CSCreationClassName; " & oproc.CSCreationClassName
fw.writeline   "CSName; " & oproc.CSName
fw.writeline   "Description; " & oproc.Description
fw.writeline   "ExecutablePath; " & oproc.ExecutablePath
fw.writeline   "ExecutionState; " & oproc.ExecutionState
fw.writeline   "Handle; " & oproc.Handle
fw.writeline   "HandleCount; " & oproc.HandleCount
fw.writeline   "InstallDate; " & oproc.InstallDate
fw.writeline   "KernelModeTime; " & oproc.KernelModeTime
fw.writeline   "MaximumWorkingSetSize; " & oproc.MaximumWorkingSetSize
fw.writeline   "MinimumWorkingSetSize; " & oproc.MinimumWorkingSetSize
fw.writeline   "Name; " & oproc.Name
fw.writeline   "OSCreationClassName; " & oproc.OSCreationClassName
fw.writeline   "OSName; " & oproc.OSName
fw.writeline   "OtherOperationCount; " & oproc.OtherOperationCount
fw.writeline   "OtherTransferCount; " & oproc.OtherTransferCount
fw.writeline   "PageFaults; " & oproc.PageFaults
fw.writeline   "PageFileUsage; " & oproc.PageFileUsage
fw.writeline   "ParentProcessId; " & oproc.ParentProcessId
fw.writeline   "PeakPageFileUsage; " & oproc.PeakPageFileUsage
fw.writeline  "PeakVirtualSize; " & oproc.PeakVirtualSize
fw.writeline   "PeakWorkingSetSize; " & oproc.PeakWorkingSetSize
fw.writeline   "Priority; " & oproc.Priority
fw.writeline   "PrivatePageCount; " & oproc.PrivatePageCount
fw.writeline   "ProcessId; " & oproc.ProcessId
fw.writeline   "QuotaNonPagedPoolUsage; " & oproc.QuotaNonPagedPoolUsage
fw.writeline   "QuotaPagedPoolUsage; " & oproc.QuotaPagedPoolUsage
fw.writeline   "QuotaPeakNonPagedPoolUsage; " & oproc.QuotaPeakNonPagedPoolUsage
fw.writeline   "QuotaPeakPagedPoolUsage; " & oproc.QuotaPeakPagedPoolUsage
fw.writeline   "ReadOperationCount; " & oproc.ReadOperationCount
fw.writeline   "ReadTransferCount; " & oproc.ReadTransferCount
fw.writeline   "SessionId; " & oproc.SessionId
fw.writeline   "Status; " & oproc.Status
fw.writeline   "TerminationDate; " & oproc.TerminationDate
fw.writeline   "ThreadCount; " & oproc.ThreadCount
fw.writeline   "UserModeTime; " & oproc.UserModeTime
fw.writeline   "VirtualSize; " & oproc.VirtualSize
fw.writeline   "WindowsVersion; " & oproc.WindowsVersion
fw.writeline   "WorkingSetSize; " & oproc.WorkingSetSize
fw.writeline   "WriteOperationCount; " & oproc.WriteOperationCount
fw.writeline   "WriteTransferCount; " & oproc.WriteTransferCount

end if ' FIN DE oproc.Name="iexplore.exe"
    Next
call jexecute(fname)

'*******************************************************************************

end if ' FIN DE if msgbox("liste process",vbyesNo,"liste process") = vbYes

'*******************************************************************************

if msgbox("liste sercices",vbyesNo,"liste services") = vbYes then
reqVbs = "select * from win32_service"
For Each oproc In objWMI.execquery(reqVbs)

        'Wscript.echo oproc.Name & " = " & oproc.State
	fsw.writeline oproc.Name & " = " & oproc.State

    Next
call jexecute(fserv)

end if
'*******************************************************************************

if msgbox("afficher nom processeur",vbyesNo,"truc acec processor") = vbYes then
reqVbs = "select * from win32_Processor"
For Each oproc In objWMI.execquery(reqVbs)
'if oproc.Name="iexplorer.exe" then
        Wscript.echo oproc.Name & " = " & oproc.ProcessorId
'end if
    Next  
end if
'*******************************************************************************

    
fw.close
fsw.close
Set objWMI = Nothing
set obj = nothing
end sub

'*******************************************************************************
'*******************************************************************************
'*****************METHODE MAIN LA PRINCIPALE QUOI!!!***********************
'*******************************************************************************
'*******************************************************************************
'*******************************************************************************

Dim WshShell,obj
Set WshShell=WScript.CreateObject("WScript.Shell")

if msgbox ("test sur les processus?",vbyesNo,"test processus?") = vbYes then
call pro
end if

if msgbox ("autre test sur les nom de processus?",vbYesNo,"autre test?") = vbYes then
call autreTest
end if

dim testnet
Dim IE
Set IE = CreateObject("InternetExplorer.Application")
testnet = msgbox ("test chrono conexion internet?",vbyesNo,"test net?")
Dim a
a = inputbox("url A tester","url a tester")
if a = "" then a = "http://www.google.fr/"
'*****je voulais voir les differances de processus*******************************
call quickList(false,"")
'************************************************************************************
With IE
        .Left = 200
        .Top = 200
        .Height = 400
        .Width = 400
        .menubar = 0
        .toolbar = 1
        .statusBar = 0
        .navigate2 a
        .Visible = 1
End With

if testnet = vbYes then

dim t
t = time
Dim iered
If Not IsNull(IE.readystate) Then
iered = IE.readystate
End If
Do While iered < 4
iered = IE.readystate
Loop

dim f
f = time

'*****je voulais voir les differances de processus*******************************
call quickList(false,"2")

dim diff
diff = minute(f)-minute(t)

msgbox f & " - " & t & " = " & diff 
end if

'*******************************************************************************
'*******************************************************************************
'*******************************************************************************

if false then
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colProcessList = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'Notepad.exe'")
    
For Each objProcess in colProcessList
    objProcess.Terminate()
Next

end if

'*******************************************************************************
'*******************************************************************************
'*******************************************************************************

public sub autreTest()

dim wshShell
Set WshShell = CreateObject("Wscript.Shell")
    msgbox "- Nom du processeur : " & WshShell.RegRead("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0\ProcessorNameString")
    msgbox "- Fréquence : " & WshShell.RegRead("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0\~mhz")
    msgbox "- Fabriquant : " & WshShell.RegRead("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0\VendorIdentifier")
    msgbox "- Identifiant du processeur : " & WshShell.RegRead("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0\Identifier")

end sub

'*******************************************************************************
'***pour la proc pro avoir des mess aulieu de tout ecrire dans un .txt****
'*******************************************************************************
'	Wscript.echo "handle " & oproc.Handle
'	Wscript.echo "caption " & oproc.Caption
'	Wscript.echo "CommandLine " & oproc.CommandLine
'	Wscript.echo "CSCreationClassName " & oproc.CSCreationClassName
'	Wscript.echo "CSName " & oproc.CSName
'	Wscript.echo "Description " & oproc.Description
'	Wscript.echo "ExecutionState " & oproc.ExecutionState
'	Wscript.echo "HandleCount " & oproc.HandleCount
'	Wscript.echo "KernelModeTime " & oproc.KernelModeTime
'	Wscript.echo "OSName " & oproc.OSName
'	Wscript.echo "OtherOperationCount " & oproc.OtherOperationCount
'	Wscript.echo " PrivatePageCount " & oproc.PrivatePageCount
'	Wscript.echo "ProcessId " & oproc.ProcessId
'       Wscript.echo oproc.Name & " = " & oproc.ExecutablePath & " statut "

'*******************************************************************************
'***********************CREATION DE FICHIER DANS REP TEMP******************
'*******************************************************************************
Function GetTempFile(File)
' WshShell declaree dans main
GetTempFile=WshShell.ExpandEnvironmentStrings("%TEMP%") & "\" & File
End Function
'*******************************************************************************
'*******************************************************************************
'*******************************************************************************
Public sub jexecute(path)
dim executeur
set executeur = wscript.createObject("Wscript.shell")
executeur.run(path)
set executeur = nothing
end sub

Conclusion :


l'important c'est l'utilisation des objets GetObject("winmgmts:root\cimv2") ou CreateObject("InternetExplorer.Application") le reste c'est de la déco

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.