' --------------------------------------------------------------------
' Script de sélection des comptes utilisateurs à afficher ou non
' dans l'écran de login de Windows XP
'
' Jean-Claude BELLAMY © 2001
' --------------------------------------------------------------------
Dim network, computer, fso, ts, SAM, Item, member, oIE
Set network = Wscript.CreateObject("WScript.Network")
Set Shell = WScript.CreateObject("WScript.Shell")
' Création du fichier HTML qui va servir de formulaire
fichtml=GetPath() & "logusers.html"
computer=network.ComputerName ' nom de la machine locale
Titre="Liste des comptes sur " & computer
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile(fichtml, True)
ts.writeline ""
ts.writeline "
"
ts.writeline "" & Titre & ""
ts.writeline ""
ts.writeline ""
ts.writeline ""
ts.writeline ""
ts.writeline ""
ts.writeline ""
ts.writeline ""
ts.Close
' Ouverture d'Internet Explorer
Set oIE = WScript.CreateObject("InternetExplorer.Application", "IE_")
oIE.Left = 50
oIE.Top = 100
oIE.Height = 400
oIE.Width = 400
oIE.MenuBar = 0
oIE.ToolBar = 0
oIE.StatusBar = 0
oIE.navigate fichtml
oIE.Visible = 2
Do While (oIE.Busy)
WScript.Sleep 200
Loop
shell.AppActivate Titre
' Attente d'action sur le bouton ou fermeture de la fenêtre
On Error Resume Next
Do
WScript.Sleep 100
Loop While (oIE.Document.Script.CheckVal() = 0)
' Si on ferme directement IE sans passer par un bouton,
' cela provoque une erreur qui est détectée et alors
' on quitte le script
If Err <> 0 Then
fso.DeleteFile fichtml,true
Wscript.quit
end if
test=oIE.Document.Script.CheckVal()
If test=-1 Then
CloseIE
Wscript.quit
end if
str="Etat des comptes au démarrage :" & vbcrlf
' Utilisation de la fonction execute afin de créer dynamiquement
' des commandes faisant intervenir des noms de champs variables
dim f(), res()
redim f(nbusers+1), res(nbusers+1)
for i = 1 to nbusers
f(i) = "function testusr() " & vbcrlf
f(i) = f(i) & "testusr=65536" & vbcrlf
f(i) = f(i) & "if oIE.Document.logusersForm.usr" & i &".Checked then testusr=1" & vbcrlf
f(i) = f(i) & "end function" & vbcrlf
execute f(i)
res(i)=testusr()
if res(i)=1 then etat="affiché" else etat="caché"
str= str & vbcrlf & fullname(i) & " (" & username(i) & ") : " & etat
next
str=str & vbcrlf & vbcrlf & "Confirmation des modifications ?"
rep=MsgBox(str , vbYesNo + vbQuestion, titre)
if rep=vbYes then
for i = 1 to nbusers
shell.RegWrite key & Username(i), res(i), "REG_DWORD"
next
end if
CloseIE
Wscript.quit
'------------------------------------------------------------
' Fonction de récupération du répertoire courant
Function GetPath()
Dim path
path = WScript.ScriptFullName
GetPath = Left(path, InStrRev(path, "\"))
End Function
'------------------------------------------------------------
' Fermeture d'Internet Explorer et suppression du fichier HTML
Sub CloseIE
oIE.Quit
Set oIE = Nothing
fso.DeleteFile fichtml,true
End Sub
'------------------------------------------------------------