Professional User Profile Cleaning     




Scripting Microsoft Delprof.exe

This website provides a short overview of public scripts found on the internet. Notice that these scripts are not created or tested by No-Nonsens inc. We recommend that you test these scripts in an isolated environment (test-lab / virtual computer) before using the product on life data. When in doubt backup your data first.



Profile Deletion Tools: Delprof Scripts: Delete Local Account: Delete Local Profile:  



Disclaimer:  

The scripts on this website are provided "as is" without warranty of any kind, either express or implied, including without limitation, warranties of title or noninfringement or the implied warranties of merchantability or fitness for a particular purpose, and noninfringement of intellectual property. No Nonsens inc. assumes no responsibility for errors or omissions caused by the use of these scripts whatsoever.


Download your trial copy of Remote Profile Cleaner



VB Scripts  

The utility delprof.exe requires administrator privileges. It cannot be run by normal users. Since logon scripts run with the credentials of the user, it would not be appropriate to run this in a logon script.

Assuming this program can run unattended, this could be run in a StartUp script (configured in a Group Policy applied to the computers in the designated OU). StartUp scripts run with System privileges on the local computer when the computer starts up and authenticates to the domain (before there is any user). This would work if the program can be run from a share accessible to the computer (StartUp scripts run with the credentials of the local computer elsewhere in the network). You can grant permissions to delprof.exe to the group "Domain Computers". Remember that the StartUp script will run every time the computer starts, so if you want the utility run just once you will need to run it from a script that checks if it has already been run (perhaps the script can save a "flag" file on the local computer when it runs successfully, which can be checked for existence at the beginning of the StartUp script).

It might make more sense to run delprof.exe remotely. This link documents how to do that: http://support.microsoft.com/kb/315411
It would be a simple matter to create a script that runs delprof.exe remotely for all computers in an OU, with the appropriate switches. It seems the syntax would be:

You may not want to use the /i parameter, which causes delprof to ignore errors. Note the spaces in the command passed to the Run method are needed, one after "/c", one before "/q", and one before "/d". For the script to run delprof successfully on a computer, it must be on and authenticated to the domain, but it does not matter if anyone is logged on.

Option Explicit

Dim objOU, objComputer, strComputer, objShell
Dim strPath, intError

' Specify path to delprof.exe.
strPath = "\\MyServer\MyShare\delprof.exe"

' Specify number of days after which delprof
' considers the profile as inactive (and subject to deletion).
intDays = 20

' Bind to the Organizational Unit.
Set objOU = GetObject("LDAP://ou=MyWorkshop,dc=MyDomain,dc=net")

' Filter on objects of class computer.
objOU.Filter = Array("computer")

' Use the Run method of the wshShell object.
Set objShell = CreateObject("Wscript.Shell")

' Enumerate all computers in the OU.
For Each objComputer In objOU
    ' Retrieve the NetBIOS name of the computer.
    strComputer = objComputer.sAMAccountName
    ' Strip off trailing "$".
    strComputer = Left(strComputer, Len(strComputer) - 1)
    ' Run delprof.exe on the remote computer.
    intError = objShell.Run("%comspec% /c " & strPath & " /q /i /c:\\" & strComputer & " /d:" & CStr(intDays)
    If (intError <> 0) Then
        Wscript.Echo "Error " & CStr(intError) & " on computer " & strComputer
    End If
Next

You may not want to use the /i parameter, which causes delprof to ignore errors. Note the spaces in the command passed to the Run method are needed, one after "/c", one before "/q", and one before "/d".

For the script to run delprof successfully on a computer, it must be on and authenticated to the domain, but it does not matter if anyone is logged on.

The complete article can be found at: microsoft.public.scripting.vbscript      


Download your trial copy of Remote Profile Cleaner



Batch Scripts  

This Batch Script will remove all profiles that are inactive for 20 days or more on all network computers.

@echo off
for /f "Skip=3 Tokens=*" %%i in ('net view') do call :delprof %%i
goto :end
:delprof
set name=%1
delprof /i /q /d:20 /c:\\%name%'
:end

Notice: Adjust the /d: parameter to change the inactive time period. Remove the /q parameter to be prompted to confirm the deletion of each profile.

The complete article can be found at: Experts Exchange      


This site is maintained by No-Nonsens inc. Visit the No-Nonsens inc. website for information about Legal Notices and our Privacy Policy.     




RemoteProfileCleaner.com www.no-nonsens.nl www.michelsimons.nl www.michel-simons.nl www.msimons.nl www.msimons.eu www.msimons.org www.delprof.eu