Code : Tout sélectionner
#include <GuiConstantsEx.au3>
#include <ListviewConstants.au3>
#include <Array.au3>
#Include <File.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <Security.au3>
script_user()
Func script_user()
; creation de l'interface graphique .
Local $hGUI = GUICreate("SUPRESSION DES USERS SOUS WINDOWS 7",900,500)
; création du label
Local $label = GUICtrlCreateLabel ("ATTENTION SEUL LES UTILISATEURS DEVANT UTILISER LE POSTE SONT A SELECTIONNER DANS LA LISTE",10,50,900,20)
GUICtrlSetFont ($label,12,700,4)
GUISetBkColor(0x00E0FFFF)
;bouton pour verifier les utilisateurs
Local $idverif = GUICtrlCreateButton ("valider", 610,100,185,125)
;bouton FERMETURE DE L'INTERFACE GRAPHIQUE
Local $idClose = GUICtrlCreateButton("FERMER", 610, 300, 185, 125)
; création du menu déroulant.
$listview = GUICtrlCreateListView(" | ", 110, 90, 350, 360, $LVS_NOCOLUMNHEADER, $LVS_EX_CHECKBOXES+ $WS_EX_CLIENTEDGE)
GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 0, 40)
;recuperation des noms dans c:\users\
$list = _GetUserProfileList()
For $i = 1 To $list[0][0]
$color = 0
$sProfile = $list[$i][0]
If $sProfile = "" Then
$sProfile = $list[$i][1]
$color = 0xff0000
EndIf
GUICtrlCreateListViewItem("|" &$sProfile,$listview)
GUICtrlSetImage(-1, "shell32.dll", -4)
GUICtrlSetColor(-1, $color)
Next
; OUVERTURE DE L'INTERFACE
GUISetState(@SW_SHOW, $hGUI)
; boucle de verification des users.
While 1
Switch GUIGetMsg()
;bouton fermer enclenché
Case $GUI_EVENT_CLOSE, $idClose
ExitLoop
;bouton valider enclenché
Case $idverif
$iChecked = False
For $i = 1 To $list[0][0]
If _GUICtrlListView_GetItemChecked ( $listview, $i - 1) Then
$iChecked = True
$sText = _GUICtrlListView_GetItemText($listview, $i - 1, 1)
; MsgBox(0, "", $list[$i][1])
_WinAPI_DeleteProfile($list[$i][2], $list[$i][1])
EndIf
Next
If NOT $iChecked Then MsgBox(48, "", "merci de séléctionner une ligne")
EndSwitch
WEnd
EndFunc
Func _GetUserProfileList()
Local $sKey = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
Local $iCount = 0, $sSubKey, $sProfileImagePath, $aAccountInfos
Local $aReturn[1][3]
While 1
$iCount += 1
$sSubKey = RegEnumKey($sKey, $iCount)
If @error Then ExitLoop
If StringRegExp($sSubKey, "(?i)S-1-5-21-(\d+-){3}\d+") Then
$sProfileImagePath = StringReplace( _ExpandEnvStringsEx ( RegRead($sKey & "\" & $sSubKey, "ProfileImagePath") ), "::", ":")
If FileExists($sProfileImagePath) Then
Redim $aReturn[ UBound($aReturn) + 1][3]
$aAccountInfos = _Security__LookupAccountSid($sSubKey)
If IsArray($aAccountInfos) Then $aReturn[ UBound($aReturn) - 1][0] = $aAccountInfos[0]
$aReturn[ UBound($aReturn) - 1][1] = $sProfileImagePath
$aReturn[ UBound($aReturn) - 1][2] = $sSubKey
EndIf
EndIf
WEnd
$aReturn[0][0] = UBound($aReturn) - 1
Return $aReturn
EndFunc
Func _ExpandEnvStringsEx($sString)
Local $aVars = StringRegExp($sString, "%([^%]+)%", 3)
Local $iCount = 0
If IsArray($aVars) Then
For $i = 0 To UBound($aVars) - 1
$sVal = EnvGet($aVars[$i])
If $sVal <> "" Then
$sString = StringReplace($sString, "%" & $aVars[$i] & "%", $sVal )
$iCount += 1
EndIf
Next
SetExtended( $iCount )
Else
SetExtended(0)
EndIf
Return $sString
EndFunc
Func _WinAPI_DeleteProfile($sSidString, $sProfilePath, $sComputerName = Null)
Local $ret = DllCall("Userenv.dll", "bool", "DeleteProfile", "str", $sSidString, "str", $sProfilePath, "str", $sComputerName)
If @error Then Return SetError(1, 0, 0)
Return $ret[0]
EndFunc