FN-GM Posted February 4, 2010 Posted February 4, 2010 Hi, I need a script to delete profiles from Windows 7. I will need to delete the folders from C:\users and remove reg folders from: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList But i dont want to remove all of them for example the administrator one. The folder deleting one is fine but how would i get round this with the registry. The folders are made up of long code (cant remember the name on top of my head) so its hard to identify what folder belongs to who. Does anyone have any ideas? Thanks
Edu-IT Posted February 4, 2010 Posted February 4, 2010 The folders are made up of long code (cant remember the name on top of my head) That would be a GUID?
mac_shinobi Posted February 4, 2010 Posted February 4, 2010 your script would have to enumerate all sub keys under the profile list section and also enumerate each of the profileimage keys to establish which users are which and from there delete the relevant keys Delete Windows User Profile in Registry
ZeroHour Posted February 4, 2010 Posted February 4, 2010 Cant you use the GP setting? it seems to work quite well in my initial testing.
FN-GM Posted February 4, 2010 Author Posted February 4, 2010 That would be a GUID? Cheers, for the life of me i couldnt remeber that Cant you use the GP setting? it seems to work quite well in my initial testing. Can you reresh my memory please
ZeroHour Posted February 4, 2010 Posted February 4, 2010 Computer Settings->Admin Templates->System->User Profiles->Delete cached copies of roaming profiles 1
Gerry Posted February 4, 2010 Posted February 4, 2010 This is a VBScript I put together a while back. It works on XP, but hasn't been tested on Windows 7. ' Ignore any errors On Error Resume Next ' define some constants Const HKEY_LOCAL_MACHINE = &H80000002 Const STR_GUID_PATH = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileGuid" Const ROOT_PROFILE_PATH = "HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\" Const SID_STRING = "SidString" ' some variables strProfiles = "" ' Create a shell Set WSHShell = CreateObject("WScript.Shell") ' Open the Registry Set objRegistry=GetObject("winmgmts:\\.\root\default:StdRegProv") ' Extract the ProfileGUID entries from the registry returned in arrGUIDs objRegistry.EnumKey HKEY_LOCAL_MACHINE, STR_GUID_PATH, arrGUIDs ' Process each of the entries in the ProfileGUID For Each objSubkey In arrGUIDs ' Extract the SID from the GUID entry strRegPath = STR_GUID_PATH & "\" & objSubkey objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE, strRegPath, SID_STRING, sidString ' Extract the profile path from the ProfileList sub tree in the registry relating to the current GUID / SID ProfileRegPath = ROOT_PROFILE_PATH & sidString RegKey = ProfileRegPath & "\ProfileImagePath" profilePath = WSHShell.RegRead (regkey) ' Replace %systemdrive% with "c:" profilePath = replace(profilePath,"%SystemDrive%","C:") ' Extract username from profilePath userName = Right(profilePath, len(profilePath)-InStrRev(profilePath,"\")) ' Create an array containing all the extracted info strProfiles = strProfiles & Username & vbCrLf & "GUID: " & objSubkey & vbCrLf & "SID: " & sidString & vbCrLf & "Path: " & profilePath & vbCrLf & vbCrLf Next Wscript.echo(strProfiles)
ZeroHour Posted February 4, 2010 Posted February 4, 2010 does delprof work on win7? Not sure but tbh I dont think its needed as the GP setting is working well so far for us. Give it a go and post feedback.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now