+ 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
    16,374
    Thank Post
    906
    Thanked 1,811 Times in 1,559 Posts
    Blog Entries
    12
    Rep Power
    468

    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. #2

    Edu-IT's Avatar
    Join Date
    Nov 2007
    Posts
    7,459
    Thank Post
    408
    Thanked 672 Times in 614 Posts
    Rep Power
    192
    The folders are made up of long code (cant remember the name on top of my head)
    That would be a GUID?

  3. #3

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    10,053
    Thank Post
    3,584
    Thanked 1,123 Times in 1,025 Posts
    Rep Power
    377
    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

  4. #4

    ZeroHour's Avatar
    Join Date
    Dec 2005
    Location
    Edinburgh, Scotland
    Posts
    5,837
    Thank Post
    974
    Thanked 1,405 Times in 850 Posts
    Blog Entries
    1
    Rep Power
    460
    Cant you use the GP setting? it seems to work quite well in my initial testing.

  5. #5

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,374
    Thank Post
    906
    Thanked 1,811 Times in 1,559 Posts
    Blog Entries
    12
    Rep Power
    468
    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

  6. #6

    ZeroHour's Avatar
    Join Date
    Dec 2005
    Location
    Edinburgh, Scotland
    Posts
    5,837
    Thank Post
    974
    Thanked 1,405 Times in 850 Posts
    Blog Entries
    1
    Rep Power
    460
    Computer Settings->Admin Templates->System->User Profiles->Delete cached copies of roaming profiles

  7. Thanks to ZeroHour from:

    FN-GM (4th February 2010)

  8. #7
    Gerry's Avatar
    Join Date
    Jun 2007
    Location
    North Wales
    Posts
    431
    Thank Post
    60
    Thanked 38 Times in 35 Posts
    Rep Power
    25
    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)

  9. #8


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    7,059
    Thank Post
    232
    Thanked 926 Times in 795 Posts
    Rep Power
    309
    does delprof work on win7?

  10. #9

    ZeroHour's Avatar
    Join Date
    Dec 2005
    Location
    Edinburgh, Scotland
    Posts
    5,837
    Thank Post
    974
    Thanked 1,405 Times in 850 Posts
    Blog Entries
    1
    Rep Power
    460
    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, 04:53 PM
  2. Delete local profiles.
    By firefighting in forum How do you do....it?
    Replies: 8
    Last Post: 28th April 2011, 09:28 PM
  3. delete certain profiles
    By chrbb in forum Scripts
    Replies: 4
    Last Post: 4th February 2010, 06:15 PM
  4. Delete profiles
    By FN-GM in forum Windows 7
    Replies: 7
    Last Post: 4th February 2010, 12:38 PM
  5. Delete printers from Profiles
    By Simcfc73 in forum Windows
    Replies: 3
    Last Post: 15th January 2008, 07: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
  •