+ Post New Thread
Results 1 to 9 of 9
Scripts Thread, Delete Profiles Script Windows 7 in Coding and Web Development; Hi, I need a script to delete profiles from Windows 7. I will need to delete the folders from C:\users ...
  1. #1

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    13,899
    Blog Entries
    8
    Thank Post
    728
    Thanked 1,370 Times in 1,200 Posts
    Rep Power
    363

    Delete Profiles Script Windows 7

    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

  2. IDG Tech News
  3. #2

    Edu-IT's Avatar
    Join Date
    Nov 2007
    Posts
    6,216
    Thank Post
    377
    Thanked 497 Times in 457 Posts
    Rep Power
    147
    The folders are made up of long code (cant remember the name on top of my head)
    That would be a GUID?

  4. #3

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    7,711
    Thank Post
    1,574
    Thanked 740 Times in 691 Posts
    Rep Power
    254
    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

  5. #4

    ZeroHour's Avatar
    Join Date
    Dec 2005
    Location
    Scotland
    Posts
    5,826
    Blog Entries
    1
    Thank Post
    785
    Thanked 1,137 Times in 682 Posts
    Rep Power
    320
    Cant you use the GP setting? it seems to work quite well in my initial testing.

  6. #5

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    13,899
    Blog Entries
    8
    Thank Post
    728
    Thanked 1,370 Times in 1,200 Posts
    Rep Power
    363
    Quote Originally Posted by Edu-IT View Post
    That would be a GUID?
    Cheers, for the life of me i couldnt remeber that

    Quote Originally Posted by ZeroHour View Post
    Cant you use the GP setting? it seems to work quite well in my initial testing.
    Can you reresh my memory please

  7. #6

    ZeroHour's Avatar
    Join Date
    Dec 2005
    Location
    Scotland
    Posts
    5,826
    Blog Entries
    1
    Thank Post
    785
    Thanked 1,137 Times in 682 Posts
    Rep Power
    320
    Computer Settings->Admin Templates->System->User Profiles->Delete cached copies of roaming profiles

  8. Thanks to ZeroHour from:

    FN-GM (4th February 2010)

  9. #7
    Gerry's Avatar
    Join Date
    Jun 2007
    Location
    North Wales
    Posts
    431
    Thank Post
    60
    Thanked 38 Times in 35 Posts
    Rep Power
    22
    This is a VBScript I put together a while back. It works on XP, but hasn't been tested on Windows 7.

    Code:
    ' 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)

  10. #8


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    4,752
    Thank Post
    170
    Thanked 641 Times in 554 Posts
    Rep Power
    204
    does delprof work on win7?

  11. #9

    ZeroHour's Avatar
    Join Date
    Dec 2005
    Location
    Scotland
    Posts
    5,826
    Blog Entries
    1
    Thank Post
    785
    Thanked 1,137 Times in 682 Posts
    Rep Power
    320
    Quote Originally Posted by sted View Post
    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.

SHARE:
+ Post New Thread

Similar Threads

  1. Script to Delete Profiles - PLEASE HELP
    By Mr_M_Cox in forum Scripts
    Replies: 13
    Last Post: 22nd February 2013, 03:53 PM
  2. Delete local profiles.
    By firefighting in forum How do you do....it?
    Replies: 8
    Last Post: 28th April 2011, 08:28 PM
  3. delete certain profiles
    By chrbb in forum Scripts
    Replies: 4
    Last Post: 4th February 2010, 05:15 PM
  4. Delete profiles
    By FN-GM in forum Windows 7
    Replies: 7
    Last Post: 4th February 2010, 11:38 AM
  5. Delete printers from Profiles
    By Simcfc73 in forum Windows
    Replies: 3
    Last Post: 15th January 2008, 06:29 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •