wntProfileDel

Deletes a profile from the system. (Windows 2000 or newer)

Syntax:

wntProfileDel( server-name , SID-string [, profile path] )

Parameters:

(s) server-name: is the UNC name of the server on which thefunction will execute (eg, "\\MYSERVER"),or "" for the local computer.

(s) SID-string: specifies the SID of the profile to delete.

(s) profile: path [optional] specifies the location of the profile.

Returns:

(i) Returns @TRUE for success and @FALSE for failure.

 

This function only works on Win2K or newer systems.

The SID-string may be obtained via the function for any account. If an account has been deleted, then it may have left behind some orphaned profiles that can only be identified by a SID string.

The list of profiles that are present on any NT platform family system are stored in the following location in the registry:

 

HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\<SID-string>

 

"<SID-string>" is a sub key whose name is a SID string.

There are several registry values stored under each one of these sub keys. One important value is a REG_EXPAND_SZ value named "ProfileImagePath". It is from this registry value that the location of a profile is obtained if the "ProfilePath" parameter is omitted or is an empty string.

The built-in Reg*() functions in WinBatch may be used to enumerate the sub keys that identify the profiles that currently exist on any given NT platform family system. The wntAcctInfo() function may be used to convert a SID-string to an account name, or vice-versa. If an account has been deleted, then it will not be possible to obtain an account name for the SID-string associated with the deleted account.

If the profile does not exist at the location specified in the "ProfilePath" parameter, then this function will return @FALSE registry sub key for the profile will still be deleted from the list of profiles in the registry even if the profile's location is invalid. This behavior is actually controlled by the DeleteProfile() Win32 API function itself.

Example:
; Load Appropriate Extender
AddExtender('wwwnt34i.dll',0,'wwwnt64i.dll')

key = RegOpenKey(@REGMACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList") profilelist = RegQueryKeys(key) count = ItemCount(profilelist,@TAB) list = "" For x = 0 To count-1    accountSID = ItemExtract(x+1,profilelist,@TAB)    profilepath= RegQueryExpSz(key,StrCat(accountSID,"\[ProfileImagePath]"))    accountname = wntAcctInfo("", accountSID, 2, 1)    list = StrCat(list,accountname,"|",accountSID,"|",profilepath,@TAB) Next RegCloseKey(key) profile = AskItemlist("Choose profile to delete from the local system",list,@TAB,@UNSORTED,@SINGLE) If profile =="" Then Exit accountSID = ItemExtract(2,profile,"|") profilepath = ItemExtract(3,profile,"|") ProfilePath = StrReplace(ProfilePath, "%%SystemDrive%%", Environment("SystemDrive")) ProfilePath = StrReplace(ProfilePath, "%%SystemRoot%%", Environment("SystemRoot")) wntProfileDel( "" , accountSID , profilepath ) Message("Done","Profile Deleted") Exit
See Also:

wntProfileInfo, wntAcctInfo()