L'auteur
Mike Gagnon Canada Membre Simple # 0000000025 enregistré le 14/10/2004 Gagnon Mike Pointe Cla H9R 3K8 de la société Carver Technologies Inc. Fiche personnelle
Note des membres
19/201 vote
Contributions > 09 - Automation > WMI (Windows Management Instrumentation)
Série de fonctions sur le système d'exploitation
# 0000000064
ajouté le 17/11/2004 21:30:21 et modifié le 29/03/2006
consulté 9327 fois
Niveau
expert Version(s) Foxpro : VFP 7.0
Description
Voici une série de fonctions pour le système d'exploitation
Code source :
&& Renvoie le nom et de version du logiciel d'exploitation installé sur un ordinateur.
lcComputer = "."
loWMIService = Getobject ("winmgmts:" ;
+ "{impersonationLevel=impersonate}!\\" + lcComputer + "\root\cimv2" )
colOperatingSystems = loWMIService.ExecQuery ;
("Select * from Win32_OperatingSystem" )
For Each loOperatingSystem In colOperatingSystems
?loOperatingSystem.Caption + " " + ;
loOperatingSystem.Version
Next
&&Renvoie des informations sur le registre d'ordinateur.
On Error *
lcComputer = "."
loWMIService = Getobject ("winmgmts:\\" + lcComputer + "\root\cimv2" )
colItems = loWMIService.ExecQuery("Select * from Win32_Registry" )
For Each loItem In colItems
?"Current Size: " + loItem.CurrentSize
?"Description: " + loItem.Description
?"Install Date: " + WMIDateStringToDate(loItem.InstallDate)
?"Maximum Size: " + Transform (loItem.MaximumSize)
?"Name: " + loItem.Name
?"Proposed Size: " + Transform (loItem.ProposedSize)
Next
Function WMIDateStringToDate(lctime)
WMIDateStringToDate = Substr (lctime, 5, 2)+"/" +Substr (lctime,7,2)+"/" +;
SUBSTR (lctime,1,4)+" " +Substr (lctime,9,2)+":" +Substr (lctime,11,2)+":" +Substr (lctime,13,2)
Return WMIDateStringToDate
Endfunc
&& Recherche des informations sur le logiciel d'exploitation installé sur un ordinateur, y compris la langue, le niveau d'encryption, et le numéro de construction.
Clear
dtmConvertedDate = Createobject ("WbemScripting.SWbemDateTime" )
lcComputer = "."
loWMIService = Getobject ("winmgmts:" ;
+ "{impersonationLevel=impersonate}!\\" + lcComputer + "\root\cimv2" )
colOperatingSystems = loWMIService.ExecQuery ;
("Select * from Win32_OperatingSystem" )
For Each loOperatingSystem In colOperatingSystems
?"Boot Device: " + loOperatingSystem.BootDevice
?"Build Number: " + loOperatingSystem.BuildNumber
?"Build Type: " + loOperatingSystem.BuildType
?"Caption: " + loOperatingSystem.Caption
?"Code Set: " + loOperatingSystem.CodeSet
?"Country Code: " + loOperatingSystem.CountryCode
?"Debug: " + Transform (loOperatingSystem.Debug )
?"Encryption Level: " + Transform (loOperatingSystem.EncryptionLevel)
?"Install Date: " +WMIDateStringToDate(loOperatingSystem.InstallDate)
?"Licensed Users: " + ;
loOperatingSystem.NumberOfLicensedUsers
?"Organization: " + loOperatingSystem.Organization
?"OS Language: " + Transform (loOperatingSystem.OSLanguage)
?"OS Product Suite: " + loOperatingSystem.OSProductSuite
?"OS Type: " + Transform (loOperatingSystem.OSType)
?"Primary: " + Transform (loOperatingSystem.Primary )
?"Registered User: " + loOperatingSystem.RegisteredUser
?"Serial Number: " + loOperatingSystem.SerialNumber
?"Version: " + loOperatingSystem.Version
Next
Function WMIDateStringToDate(lctime)
WMIDateStringToDate = Substr (lctime, 5, 2)+"/" +Substr (lctime,7,2)+"/" +;
SUBSTR (lctime,1,4)+" " +Substr (lctime,9,2)+":" +Substr (lctime,11,2)+":" +Substr (lctime,13,2)
Return WMIDateStringToDate
Endfunc
&& Renvoie une liste de toutes les 'Hot Fixes' installés sur un ordinateur.
CLEAR
lcComputer = "."
loWMIService = Getobject ("winmgmts:" ;
+ "{impersonationLevel=impersonate}!\\" + lcComputer + "\root\cimv2" )
colQuickFixes = loWMIService.ExecQuery ;
("Select * from Win32_QuickFixEngineering" )
For Each loQuickFix In colQuickFixes
?"Computer: " + loQuickFix.CSName
?"Description: " + loQuickFix.Description
?"Hot Fix ID: " + loQuickFix.HotFixID
Next
&& Ajouter un tache dans le "Task scheduler"
JobID = 0
lcComputer = "."
loWMIService = GetObject ("winmgmts:" ;
+ "{impersonationLevel=impersonate}!\\" + lcComputer + "\root\cimv2" )
loNewJob = loWMIService.Get ("Win32_ScheduledJob" )
errJobCreated = loNewJob.Create ("Notepad.exe" ,
"********123000.000000-420" , .t. , BITOR (1, 2, 4, 8, 16), , , JobID)
?errJobCreated
&& Vérifier si le mot de passe expire ou non pour un utilisateur dans un domaine
oADs=CREATEOBJECT ("ADSystemInfo" )
?oADs.UserName
oUser=GETOBJECT ("LDAP://" +oADs.UserName)
?oUser.get ("mail" ) && addresse e-mail
IF BITAND (oUser.get ("userAccountControl" ) , 0x10000)>0
?"Mot de passe n'expire pas"
ELSE
oDomain=GETOBJECT ("LDAP://" +oADS.DomainDNSName)
oAge=oDomain.Get ("maxPwdAge" )
nMaxAge=ABS (oAge.HighPart * 2^32+oAge.LowPart) /1e7/86400
?"Max Password Age=" ,nMaxAge
?"Mot de passe expire: " ,oUser.PasswordLastChanged+nMaxAge*86400
ENDIF
&& Lister tous les programmes installés avec Windows Installler
loFSO = Createobject ("Scripting.FileSystemObject" )
loTextFile = loFSO.CreateTextFile("c:\scripts\software.tsv" , .T. )
lcComputer = "."
loWMIService = Getobject ("winmgmts:" ;
+ "{impersonationLevel=impersonate}!\\" + lcComputer + "\root\cimv2" )
colSoftware = loWMIService.ExecQuery ;
("Select * from Win32_Product" )
loTextFile.WriteLine ("Caption" + Chr (9) + ;
"Description" + Chr (9) + "Identifying Number" + Chr (9) + ;
"Install Date" + Chr (9) + "Install Location" + Chr (9) + ;
"Install State" + Chr (9) + "Name" + Chr (9) + ;
"Package Cache" + Chr (9) + "SKU Number" + Chr (9) + "Vendor" + Chr (9) ;
+ "Version" )
For Each loSoftware In colSoftware
loTextFile.WriteLine(loSoftware.Caption + Chr (9) + ;
loSoftware.Description + Chr (9) + ;
TRANSFORM (loSoftware.IdentifyingNumber) + Chr (9) + ;
TRANSFORM (loSoftware.InstallDate2) + Chr (9) + ;
TRANSFORM (loSoftware.InstallLocation) + Chr (9) + ;
TRANSFORM (loSoftware.InstallState) + Chr (9) + ;
loSoftware.Name + Chr (9) + ;
loSoftware.PackageCache + Chr (9) + ;
TRANSFORM (loSoftware.SKUNumber) + Chr (9) + ;
loSoftware.Vendor + Chr (9) + ;
TRANSFORM (loSoftware.Version )+Chr (13)+Chr (10))
Next
loTextFile.Close
Commentaires
Aucun commentaire enregistré ...