Un petit coup de main serait bienvenue

maximeh2 Messages postés 3 Date d'inscription vendredi 23 janvier 2009 Statut Membre Dernière intervention 21 juillet 2009 - 13 juil. 2009 à 22:00
maximeh2 Messages postés 3 Date d'inscription vendredi 23 janvier 2009 Statut Membre Dernière intervention 21 juillet 2009 - 21 juil. 2009 à 10:04
Salut, et merci si vous voulez bien m'aider.

En fait c'est très simple, je cherche a faire un petit soft ou script qui me permet de contrôler le répertoire programme files de windows, simplement en y comptant le nombre de répertoire, et qu'en fonction d'un chiffre, si il le dépasse, il crée alors un fichier texte contenant l'ip de la machine et sa mac adresse dans un répertoire.

Étant vraiment pas bon en dev, je me permet de vous demander umblement votre aide...

Merci d'avance.

A bientôt

4 réponses

cs_rt15 Messages postés 3874 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 7 novembre 2014 13
20 juil. 2009 à 09:55
Salut,

Un petit script vbscript peut faire le boulot.
Mettre ce code dans un fichier d'extension .vbs.

Const MAX_FOLDER_COUNT = 90
Const LOG_FILE = "c:\ProgramFiles.log"

Dim objShell           ' Shell
Dim objProcessEnv      ' Récupération de l'environnement processeur
Dim strProgramFiles    ' Path vers program files
Dim objFso             ' FileSystemObject
Dim objProgramFiles    ' Le folder program files

Dim objFile            ' Fichier ou écrire les adresses MAC et IP
Const ForWriting = 2

Dim objWMIService      ' WMI
Dim objNetworkConfigs  ' Ensemble des configs réseaux
Dim objNetworkConfig   ' Une config réseau

' Récupération du shell
Set objShell = WScript.CreateObject("WScript.Shell")

' Récupération de l'environnement Process, dont la variable ProgramFiles fait parti
Set objProcessEnv = objShell.Environment("Process")

' Récupération de la variable
strProgramFiles = objProcessEnv("ProgramFiles")

Set objFso = CreateObject("Scripting.FileSystemObject")
Set objProgramFiles = objFso.GetFolder(strProgramFiles)

' Si il n'y a pas trop de sous dossiers, on sort
If objProgramFiles.SubFolders.Count <= MAX_FOLDER_COUNT Then WScript.Quit

' Ouverture du fichier, pour écriture, en le re-créant
Set objFile = objFso.OpenTextFile(LOG_FILE, ForWriting, True)

' Récupération du service WMI
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")

' Exécution d'une requête de recherche des configurations réseaux
Set objNetworkConfigs = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration")

' Pour toutes les configurations réseaux
For Each objNetworkConfig In objNetworkConfigs
  If objNetworkConfig.IPEnabled Then
    objFile.WriteLine objNetworkConfig.MACAddress
    objFile.WriteLine objNetworkConfig.IPAddress(0) ' On ne récupère que la première IP
    Exit For ' On regarde que la première config
  End If
Next
0
maximeh2 Messages postés 3 Date d'inscription vendredi 23 janvier 2009 Statut Membre Dernière intervention 21 juillet 2009
20 juil. 2009 à 11:23
Merci ca fonctionne super bien...

par contre je pense que maintenant et j'espère que ça ne va pas beaucoup changer trop le code, est il possible que le fichier log soit nommer du genre le "nom de la machine".log

merci encore
0
cs_rt15 Messages postés 3874 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 7 novembre 2014 13
20 juil. 2009 à 11:38
Arf, j'avais oublié de fermer le fichier...

Pour le nom du PC, une méthode simple est de passer par la variable d'environnement COMPUTERNAME.
Const MAX_FOLDER_COUNT = 90
Const LOG_FOLDER = "c:"

Dim objShell           ' Shell
Dim objProcessEnv      ' Récupération de l'environnement processeur
Dim strProgramFiles    ' Path vers program files
Dim objFso             ' FileSystemObject
Dim objProgramFiles    ' Le folder program files

Dim objFile            ' Fichier ou écrire les adresses MAC et IP
Const ForWriting = 2

Dim objWMIService      ' WMI
Dim objNetworkConfigs  ' Ensemble des configs réseaux
Dim objNetworkConfig   ' Une config réseau

' Récupération du shell
Set objShell = WScript.CreateObject("WScript.Shell")

' Récupération de l'environnement Process, dont la variable ProgramFiles fait parti
Set objProcessEnv = objShell.Environment("Process")

' Récupération de la variable
strProgramFiles = objProcessEnv("ProgramFiles")

Set objFso = CreateObject("Scripting.FileSystemObject")
Set objProgramFiles = objFso.GetFolder(strProgramFiles)

' Si il n'y a pas trop de sous dossiers, on sort
If objProgramFiles.SubFolders.Count <= MAX_FOLDER_COUNT Then WScript.Quit

' Ouverture du fichier, pour écriture, en le re-créant
Set objFile = objFso.OpenTextFile(LOG_FOLDER & objProcessEnv("COMPUTERNAME") & ".log", ForWriting, True)

' Récupération du service WMI
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")

' Exécution d'une requête de recherche des configurations réseaux
Set objNetworkConfigs = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration")

' Pour toutes les configurations réseaux
For Each objNetworkConfig In objNetworkConfigs
  If objNetworkConfig.IPEnabled Then
    objFile.WriteLine objNetworkConfig.MACAddress
    objFile.WriteLine objNetworkConfig.IPAddress(0) ' On ne récupère que la première IP
    Exit For ' On regarde que la première config
  End If
Next
objFile.Close
0
maximeh2 Messages postés 3 Date d'inscription vendredi 23 janvier 2009 Statut Membre Dernière intervention 21 juillet 2009
21 juil. 2009 à 10:04
Un très grand merci pour ton aide, ça fonctionne nickel.

A bientôt peut être
0
Rejoignez-nous