Besoin d'aide pour modifier un .vbs svp

Besoin d'aide pour modifier un .vbs svp - VB/VBA/VBS - Programmation

Marsh Posté le 21-07-2004 à 13:14:06    

Bonjour,
je n'y conais absolument rien en vbs, par contre j'ai récupérer un petit script qui me plait bien (recupere la date de derniere connexion d'un utilisateur), mais je voudrais le modifier pour qu'il écrive le résultat dans un fichier au lieu qu'il m'ouvre une fenetre par utilisateur .
Si il y a une ame charitable de passage...
Merci


On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2" )
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkLoginProfile" )
For Each objItem in colItems
    dtmWMIDate = objItem.LastLogon
    strReturn = WMIDateStringToDate(dtmWMIDate)
    Wscript.Echo "Name: " & objItem.Name & " Last Logon: " & strReturn
     
Next
Function WMIDateStringToDate(dtmWMIDate)
    If Not IsNull(dtmWMIDate) Then
    WMIDateStringToDate = CDate(Mid(dtmWMIDate, 5, 2) & "/" & _
         Mid(dtmWMIDate, 7, 2) & "/" & Left(dtmWMIDate, 4) _
             & " " & Mid (dtmWMIDate, 9, 2) & ":" & _
                 Mid(dtmWMIDate, 11, 2) & ":" & Mid(dtmWMIDate, _
                     13, 2))
    End If
End Function


 
PS : ce script ne récupère que les accès sur un ordi, y a t'il moyens de récupére les accès pour tous les postes du domaine ?


Message édité par kayasax le 21-07-2004 à 13:18:16
Reply

Marsh Posté le 21-07-2004 à 13:14:06   

Reply

Marsh Posté le 23-07-2004 à 08:13:24    

Code :
  1. On Error Resume Next
  2. strComputer = "."
  3. Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2" )
  4. Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkLoginProfile" )



Set FSys = CreateObject("Scripting.FileSystemObject" )
Set F = fso.CreateTextFile("c:\temp\", "STATS-LOGON.TXT", ForWriting, True)

Code :
  1. For Each objItem in colItems
  2.    dtmWMIDate = objItem.LastLogon
  3.    strReturn = WMIDateStringToDate(dtmWMIDate)


   F.Write "Name: " & objItem.Name & " Last Logon: " & strReturn

Code :
  1. Next
  2. Function WMIDateStringToDate(dtmWMIDate)
  3.    If Not IsNull(dtmWMIDate) Then
  4.    WMIDateStringToDate = CDate(Mid(dtmWMIDate, 5, 2) & "/" & _
  5.         Mid(dtmWMIDate, 7, 2) & "/" & Left(dtmWMIDate, 4) _
  6.             & " " & Mid (dtmWMIDate, 9, 2) & ":" & _
  7.                 Mid(dtmWMIDate, 11, 2) & ":" & Mid(dtmWMIDate, _
  8.                     13, 2))
  9.    End If
  10. End Function


 
 
voila je t'ai rajouter du code en gras, ce sont les lignes qui te permetront d'insérer dans un fichier.
 
ca devrait fonctionner (a tester !!!).
 
bonne journee

Reply

Marsh Posté le 23-07-2004 à 15:51:58    

ok merci

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed