Jump to content

Recommended Posts

Posted

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

Posted
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 :)

Posted

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)

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...