[HELP] Action et Fichier log à l'ouverture de session
4 réponses
m
Bonjour,
Dans mon AD, à l'ouverture de session des utilisateurs, je voudrai utilisé à
la place de mes batchs un script VBS.
j'ai un script qui me permet de me connecter à mon AD et d'effectuer
quelques fonctions par rapport au groupe ou au utilisateurs (mappage
réseaux par exemple).
J'ai un autre script qui me permet de connaitre la version de l'OS (2000,XP
ou autre), en revanche ce que je ne sais pas faire, c'est en fonction de
l'OS lancer tel ou tel Action. Par exemple :
Si OS = Windows XP ALORS actions 1
SI OS = win 2000 ALORS actions 2
etc.......
D'autre part, Actuellement j'écris à chaque ouverture de session dans 1
fichier Log les renseignements de mes machines.
J'aimerai fabriquer un fichier avec les renseignements qui porte le nom du
computername. C'est a dire si ma machine s'appelle PC-TOTO, avoir un fichier
PC-TOTO.txt par exemple avec dans ce fichier les informations relative à
cette machine.
D'ou mes interrogations :
1 .Comment faire pour, suivant la version de l'OS appliquer telle ou telle
action ?
2. Comment faire pour fabriquer un fichier avec le nom de la machine et les
infos relative a cette machine à l'interieur de ce fichier ?
Merci de votre aide.
Script pour connaitre la version de l'OS :
' fonction pour ouverture de fichier
Const ForReading = 1, ForWriting = 2
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\temp\log.txt", ForWriting,true)
'fonction pour recolter informations de la machine
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOS in colOSes
f.writeline ("Computer Name: " & objOS.CSName) ' Ecriture dans le fichier
log
f.writeline ("Caption: " & objOS.Caption) 'Name
f.writeline ("Version: " & objOS.Version) 'Version & build
f.writeline ("Service Pack: " & objOS.ServicePackMajorVersion & "." & _
objOS.ServicePackMinorVersion )
Next
If InStr (objOS.Caption, "Windows XP") Then ' action 1 End If
If InStr (objOS.Caption, "Windows 2000") Then ' action 2 End If
Next
-- Gilles LAURENT Me contacter : http://cerbermail.com/?zoTY7ZkLcD
m
j'ai une erreur je ne sais pas d'ou elle viens......
Si vous pouviez m'aider....
Script complet :
Dim WSHNetwork Dim a,b,c,groupe,text a = Chr(13) & Chr(10) Set WshShell = Wscript.CreateObject("Wscript.Shell") Set WSHNetwork = WScript.CreateObject("WScript.Network") Set b = GetObject("WinNT://" & WSHNetwork.userdomain & "/" & WSHNetwork.username) groupe="" For Each c in b.Groups groupe=groupe & " - " & c.name & a Next '*************************************************************************** ** Set colDrives = WSHNetwork.EnumNetworkDrives If colDrives.Count <> 0 Then For i = 0 To colDrives.Count - 1 Step 2 if colDrives(i)<>"" Then If (colDrives(i))<>"Z:" Then WshNetwork.RemoveNetworkDrive colDrives(i) End if Next End if '*************************************************************************** ** text=b.fullname & " bienvenue sur le domaine " & WSHNetwork.UserDomain & a text=text & "Vous etes connecté en tant que : " & WSHNetwork.username & a text=text & "Vous utilisez le poste nommé " & WSHNetwork.computername & a text=text & "Vous etes membre des groupes : " & a text=text & groupe WshShell.Popup text,6,"Nom de l'entreprise",0
For Each c in b.Groups Select Case c.name
' Case "Admins du domaine":
' Case "Utilisa. du domaine" :
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!" & strComputer & "rootcimv2") Set colOSes = objWMIService.ExecQuery ( _ "Select * from Win32_OperatingSystem")
For Each objOS in colOSes
Set f = fso.OpenTextFile (_ "C:temp" & objOS.CSName & ".txt", _ ForWriting, _ True)
If InStr (objOS.Caption, "Windows XP") Then ' action 1 End If
If InStr (objOS.Caption, "Windows 2000") Then ' action 2 End If
Next
-- Gilles LAURENT Me contacter : http://cerbermail.com/?zoTY7ZkLcD
j'ai une erreur je ne sais pas d'ou elle viens......
Si vous pouviez m'aider....
Script complet :
Dim WSHNetwork
Dim a,b,c,groupe,text
a = Chr(13) & Chr(10)
Set WshShell = Wscript.CreateObject("Wscript.Shell")
Set WSHNetwork = WScript.CreateObject("WScript.Network")
Set b = GetObject("WinNT://" & WSHNetwork.userdomain & "/" &
WSHNetwork.username)
groupe=""
For Each c in b.Groups
groupe=groupe & " - " & c.name & a
Next
'***************************************************************************
**
Set colDrives = WSHNetwork.EnumNetworkDrives
If colDrives.Count <> 0 Then
For i = 0 To colDrives.Count - 1 Step 2
if colDrives(i)<>"" Then
If (colDrives(i))<>"Z:" Then WshNetwork.RemoveNetworkDrive colDrives(i)
End if
Next
End if
'***************************************************************************
**
text=b.fullname & " bienvenue sur le domaine " & WSHNetwork.UserDomain & a
text=text & "Vous etes connecté en tant que : " & WSHNetwork.username & a
text=text & "Vous utilisez le poste nommé " & WSHNetwork.computername & a
text=text & "Vous etes membre des groupes : " & a
text=text & groupe
WshShell.Popup text,6,"Nom de l'entreprise",0
For Each c in b.Groups
Select Case c.name
' Case "Admins du domaine":
' Case "Utilisa. du domaine" :
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")
Set colOSes = objWMIService.ExecQuery ( _
"Select * from Win32_OperatingSystem")
For Each objOS in colOSes
Set f = fso.OpenTextFile (_
"C:temp" & objOS.CSName & ".txt", _
ForWriting, _
True)
j'ai une erreur je ne sais pas d'ou elle viens......
Si vous pouviez m'aider....
Script complet :
Dim WSHNetwork Dim a,b,c,groupe,text a = Chr(13) & Chr(10) Set WshShell = Wscript.CreateObject("Wscript.Shell") Set WSHNetwork = WScript.CreateObject("WScript.Network") Set b = GetObject("WinNT://" & WSHNetwork.userdomain & "/" & WSHNetwork.username) groupe="" For Each c in b.Groups groupe=groupe & " - " & c.name & a Next '*************************************************************************** ** Set colDrives = WSHNetwork.EnumNetworkDrives If colDrives.Count <> 0 Then For i = 0 To colDrives.Count - 1 Step 2 if colDrives(i)<>"" Then If (colDrives(i))<>"Z:" Then WshNetwork.RemoveNetworkDrive colDrives(i) End if Next End if '*************************************************************************** ** text=b.fullname & " bienvenue sur le domaine " & WSHNetwork.UserDomain & a text=text & "Vous etes connecté en tant que : " & WSHNetwork.username & a text=text & "Vous utilisez le poste nommé " & WSHNetwork.computername & a text=text & "Vous etes membre des groupes : " & a text=text & groupe WshShell.Popup text,6,"Nom de l'entreprise",0
For Each c in b.Groups Select Case c.name
' Case "Admins du domaine":
' Case "Utilisa. du domaine" :
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!" & strComputer & "rootcimv2") Set colOSes = objWMIService.ExecQuery ( _ "Select * from Win32_OperatingSystem")
For Each objOS in colOSes
Set f = fso.OpenTextFile (_ "C:temp" & objOS.CSName & ".txt", _ ForWriting, _ True)
If InStr (objOS.Caption, "Windows XP") Then ' action 1 End If
If InStr (objOS.Caption, "Windows 2000") Then ' action 2 End If
Next
-- Gilles LAURENT Me contacter : http://cerbermail.com/?zoTY7ZkLcD
Gilles LAURENT
"m" a écrit dans le message de news:O6U%23H% | j'ai une erreur je ne sais pas d'ou elle viens...... | Si vous pouviez m'aider....
| Dim WSHNetwork | Dim a,b,c,groupe,text
Soit on déclare toutes les variables, soit rien du tout ! Donc vous pouvez supprimer les deux lignes ci-dessus
+++ Convention
+ pour ajouter une ligne - pour supprimer une ligne
+ Const ForWriting = 2
| a = Chr(13) & Chr(10) | Set WshShell = Wscript.CreateObject("Wscript.Shell") | Set WSHNetwork = WScript.CreateObject("WScript.Network")
+ Set fso = WScript.CreateObject ("Scripting.FileSystemObject")
| Set b = GetObject("WinNT://" & WSHNetwork.userdomain & "/" & | WSHNetwork.username) | groupe="" | For Each c in b.Groups | groupe=groupe & " - " & c.name & a | Next | '*********************************************************************** **** | ** | Set colDrives = WSHNetwork.EnumNetworkDrives | If colDrives.Count <> 0 Then | For i = 0 To colDrives.Count - 1 Step 2 | if colDrives(i)<>"" Then | If (colDrives(i))<>"Z:" Then WshNetwork.RemoveNetworkDrive | colDrives(i) End if | Next | End if | '*********************************************************************** **** | ** | text=b.fullname & " bienvenue sur le domaine " & | WSHNetwork.UserDomain & a text=text & "Vous etes connecté en tant que | : " & WSHNetwork.username & a text=text & "Vous utilisez le poste | nommé " & WSHNetwork.computername & a text=text & "Vous etes membre | des groupes : " & a | text=text & groupe | WshShell.Popup text,6,"Nom de l'entreprise",0 | | | For Each c in b.Groups | Select Case c.name
- Select Case c.name
| | | ' Case "Admins du domaine": | | ' Case "Utilisa. du domaine" : | | strComputer = "." | Set objWMIService = GetObject("winmgmts:" _ | & "{impersonationLevel=impersonate}!" & strComputer & | "rootcimv2") Set colOSes = objWMIService.ExecQuery ( _ | "Select * from Win32_OperatingSystem") | | For Each objOS in colOSes | | Set f = fso.OpenTextFile (_ | "C:temp" & objOS.CSName & ".txt", _ | ForWriting, _ | True) | | f.WriteLine ("Computer Name: " & objOS.CSName) | f.WriteLine ("Caption: " & objOS.Caption) | f.WriteLine ("Version: " & objOS.Version) | f.WriteLine ("Service Pack: " & _ | objOS.ServicePackMajorVersion & "." & _ | objOS.ServicePackMinorVersion ) | | If InStr (objOS.Caption, "Windows XP") Then | ' action 1 | End If | | If InStr (objOS.Caption, "Windows 2000") Then | ' action 2 | End If | | Next | End Select
- End Select
| Next
-- Gilles LAURENT Me contacter : http://cerbermail.com/?zoTY7ZkLcD
"m" <minidoux24@hotmail.com> a écrit dans le message de
news:O6U%23H%23e7GHA.2120@TK2MSFTNGP03.phx.gbl
| j'ai une erreur je ne sais pas d'ou elle viens......
| Si vous pouviez m'aider....
| Dim WSHNetwork
| Dim a,b,c,groupe,text
Soit on déclare toutes les variables, soit rien du tout !
Donc vous pouvez supprimer les deux lignes ci-dessus
+++ Convention
+ pour ajouter une ligne
- pour supprimer une ligne
+ Const ForWriting = 2
| a = Chr(13) & Chr(10)
| Set WshShell = Wscript.CreateObject("Wscript.Shell")
| Set WSHNetwork = WScript.CreateObject("WScript.Network")
+ Set fso = WScript.CreateObject ("Scripting.FileSystemObject")
| Set b = GetObject("WinNT://" & WSHNetwork.userdomain & "/" &
| WSHNetwork.username)
| groupe=""
| For Each c in b.Groups
| groupe=groupe & " - " & c.name & a
| Next
|
'***********************************************************************
****
| **
| Set colDrives = WSHNetwork.EnumNetworkDrives
| If colDrives.Count <> 0 Then
| For i = 0 To colDrives.Count - 1 Step 2
| if colDrives(i)<>"" Then
| If (colDrives(i))<>"Z:" Then WshNetwork.RemoveNetworkDrive
| colDrives(i) End if
| Next
| End if
|
'***********************************************************************
****
| **
| text=b.fullname & " bienvenue sur le domaine " &
| WSHNetwork.UserDomain & a text=text & "Vous etes connecté en tant que
| : " & WSHNetwork.username & a text=text & "Vous utilisez le poste
| nommé " & WSHNetwork.computername & a text=text & "Vous etes membre
| des groupes : " & a
| text=text & groupe
| WshShell.Popup text,6,"Nom de l'entreprise",0
|
|
| For Each c in b.Groups
| Select Case c.name
- Select Case c.name
|
|
| ' Case "Admins du domaine":
|
| ' Case "Utilisa. du domaine" :
|
| strComputer = "."
| Set objWMIService = GetObject("winmgmts:" _
| & "{impersonationLevel=impersonate}!\" & strComputer &
| "rootcimv2") Set colOSes = objWMIService.ExecQuery ( _
| "Select * from Win32_OperatingSystem")
|
| For Each objOS in colOSes
|
| Set f = fso.OpenTextFile (_
| "C:temp" & objOS.CSName & ".txt", _
| ForWriting, _
| True)
|
| f.WriteLine ("Computer Name: " & objOS.CSName)
| f.WriteLine ("Caption: " & objOS.Caption)
| f.WriteLine ("Version: " & objOS.Version)
| f.WriteLine ("Service Pack: " & _
| objOS.ServicePackMajorVersion & "." & _
| objOS.ServicePackMinorVersion )
|
| If InStr (objOS.Caption, "Windows XP") Then
| ' action 1
| End If
|
| If InStr (objOS.Caption, "Windows 2000") Then
| ' action 2
| End If
|
| Next
| End Select
- End Select
| Next
--
Gilles LAURENT
Me contacter : http://cerbermail.com/?zoTY7ZkLcD
"m" a écrit dans le message de news:O6U%23H% | j'ai une erreur je ne sais pas d'ou elle viens...... | Si vous pouviez m'aider....
| Dim WSHNetwork | Dim a,b,c,groupe,text
Soit on déclare toutes les variables, soit rien du tout ! Donc vous pouvez supprimer les deux lignes ci-dessus
+++ Convention
+ pour ajouter une ligne - pour supprimer une ligne
+ Const ForWriting = 2
| a = Chr(13) & Chr(10) | Set WshShell = Wscript.CreateObject("Wscript.Shell") | Set WSHNetwork = WScript.CreateObject("WScript.Network")
+ Set fso = WScript.CreateObject ("Scripting.FileSystemObject")
| Set b = GetObject("WinNT://" & WSHNetwork.userdomain & "/" & | WSHNetwork.username) | groupe="" | For Each c in b.Groups | groupe=groupe & " - " & c.name & a | Next | '*********************************************************************** **** | ** | Set colDrives = WSHNetwork.EnumNetworkDrives | If colDrives.Count <> 0 Then | For i = 0 To colDrives.Count - 1 Step 2 | if colDrives(i)<>"" Then | If (colDrives(i))<>"Z:" Then WshNetwork.RemoveNetworkDrive | colDrives(i) End if | Next | End if | '*********************************************************************** **** | ** | text=b.fullname & " bienvenue sur le domaine " & | WSHNetwork.UserDomain & a text=text & "Vous etes connecté en tant que | : " & WSHNetwork.username & a text=text & "Vous utilisez le poste | nommé " & WSHNetwork.computername & a text=text & "Vous etes membre | des groupes : " & a | text=text & groupe | WshShell.Popup text,6,"Nom de l'entreprise",0 | | | For Each c in b.Groups | Select Case c.name
- Select Case c.name
| | | ' Case "Admins du domaine": | | ' Case "Utilisa. du domaine" : | | strComputer = "." | Set objWMIService = GetObject("winmgmts:" _ | & "{impersonationLevel=impersonate}!" & strComputer & | "rootcimv2") Set colOSes = objWMIService.ExecQuery ( _ | "Select * from Win32_OperatingSystem") | | For Each objOS in colOSes | | Set f = fso.OpenTextFile (_ | "C:temp" & objOS.CSName & ".txt", _ | ForWriting, _ | True) | | f.WriteLine ("Computer Name: " & objOS.CSName) | f.WriteLine ("Caption: " & objOS.Caption) | f.WriteLine ("Version: " & objOS.Version) | f.WriteLine ("Service Pack: " & _ | objOS.ServicePackMajorVersion & "." & _ | objOS.ServicePackMinorVersion ) | | If InStr (objOS.Caption, "Windows XP") Then | ' action 1 | End If | | If InStr (objOS.Caption, "Windows 2000") Then | ' action 2 | End If | | Next | End Select
- End Select
| Next
-- Gilles LAURENT Me contacter : http://cerbermail.com/?zoTY7ZkLcD