Remove Profiles in Users folder
Hello everyone, I've been trying to create a vbscript to remove all user profiles except the main profiles on user logoff. I cant use the GPO because profiles are not roaming. below is the script i am currently using or trying to use. This works on XP no problem but i need to get it to work on win7/Server 2008 terminal. On Error Resume Next Path1 = "C:\Users\" Dim fso Dim oFolder Dim oFile Dim oSubFolder Set fso = createobject("Scripting.FileSystemObject") Set objDomain = getObject("LDAP://rootDse") DomainString = objDomain.Get("dnsHostName") If Err <> 0 Then 'Domain not present to validate users against. Exit script to prevent data loss. WScript.Quit End If Set oFolder = fso.GetFolder(Path1) Set colSubfolders = oFolder.Subfolders For Each oSubfolder in colSubfolders 'First check To see if the folder is from multiple profiles in form username.domainname 'Use the folder name to get the user ID If InStr(oSubFolder.Name,".") Then splitArray = Split(oSubFolder.Name,".") UserString = splitArray(0) Else UserString = oSubFolder.Name End If Select Case lcase(UserString) Case "administrator", "all users", "default user", "localservice", "networkservice", "Public", "Default" 'Do nothing Case Else 'Now bind to the user object to see if a valid user. If not delete folder. Err = GetObject("WinNT://" & DomainString & "/" & UserString) If Err <> 0 Then fso.DeleteFolder(Path1 & oSubFolder.Name),true WScript.Echo oSubFolder.Name End If End Select Next Set oSubFolder = Nothing Set oFolder = Nothing Set fso = Nothing theother problem is, that when i run the script it doesnt delete any folders that have a lock on them. So i need to bypass that some how. Users that are logging onto the system do no have admin rights. This script will be placed into the logoff GPO.
May 29th, 2012 11:52am

1. Redirect the output of your script into text file and see what is the reaction. 2. Try to create task with elevated rights withtiming on user disconnest session. Use Domain Admin account Regards Milos
Free Windows Admin Tool Kit Click here and download it now
May 29th, 2012 4:04pm

1. Redirect the output of your script into text file and see what is the reaction. 2. Try to create task with elevated rights withtiming on user disconnest session. Use Domain Admin account Regards Milos
May 29th, 2012 4:12pm

You probably have to reboot first. That's what Microsoft does.
Free Windows Admin Tool Kit Click here and download it now
May 29th, 2012 4:19pm

You probably have to reboot first. That's what Microsoft does.
May 29th, 2012 4:28pm

Hi, Don't forget that you are only referencing the folder object(s) in terms of the profile, and you also need to reference the registry location and clear that too. This will be stored as a SID for the user in question. e.g. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\<SID> You could use WShell.Run and call REG.EXE to wipe the registry key, or you could make WMI calls. These links should be useful: http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/registry/ http://ss64.com/vb/run.html HTH
Free Windows Admin Tool Kit Click here and download it now
May 29th, 2012 4:32pm

Here's a way to delete a profile with wmic: wmic /node:"localhost" path win32_UserProfile where LocalPath="c:\\users\\myuser3" Delete 2>>c:\windows\temp\wmic.err
May 29th, 2012 5:03pm

Here's a way to delete a profile with wmic: wmic /node:"localhost" path win32_UserProfile where LocalPath="c:\\users\\myuser3" Delete 2>>c:\windows\temp\wmic.err
Free Windows Admin Tool Kit Click here and download it now
May 29th, 2012 5:11pm

Hi, For script related question, it is recommended to post the thread in Scripting Forums. Hope this helps. Jeremy Wu TechNet Community Support
May 31st, 2012 6:13am

Hi, For script related question, it is recommended to post the thread in Scripting Forums. Hope this helps. Jeremy Wu TechNet Community Support
Free Windows Admin Tool Kit Click here and download it now
May 31st, 2012 6:16am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics