+ Post New Thread
Results 1 to 4 of 4
Windows Server 2000/2003 Thread, DelProf anomaly in startup script in Technical; I've seen threads about DelProf not always working as it should. I want to be able to delete local profiles ...
  1. #1

    Join Date
    May 2009
    Location
    UK
    Posts
    291
    Thank Post
    64
    Thanked 21 Times in 20 Posts
    Rep Power
    14

    DelProf anomaly in startup script

    I've seen threads about DelProf not always working as it should. I want to be able to delete local profiles on a client in a test setup. I'm far from an expert with VBS and came across some code:

    Code:
    Option Explicit 
    
    Dim objOU, objComputer, strComputer, objShell
    Dim strPath, intError, intDays 
    
    ' Specify path to delprof.exe. 
    strPath = "\\server\tools$\delprof.exe" 
    
    ' Specify number of days after which delprof 
    ' considers the profile as inactive (and subject to deletion). 
    intDays = 1
    
    ' Bind to the Organizational Unit. 
    Set objOU = GetObject("LDAP://ou=Test_OU,dc=MyDomain,dc=test") 
    'I set this as the OU which contains the client computer
    
    ' 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.
    
    'The next line is for testing purposes, to confirm that the correct computer has been picked up, along
    'with the number of inactive days.
    
    wscript.echo "Running DelProf on " & strComputer & " - " & Cstr(intDays) & " day(s)."
    
        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
    
    'If the following line is commented out, the script doesn't delete the profiles
    'but if I uncomment it, I can watch the deletion(s) happen then click OK and everything
    'has gone, as it should!
    
    wscript.echo "DONE"
    
    Next
    I've added the problem that I have to the code. Basically, it doesn't delete the profiles unless I put in a "Pause" so I can watch the profiles deleted but I want to avoid that (well I do in the "real life" situation).

    I've tried setting the /k switch after %comspec% but that doesn't help either.

    Any ideas (other than deleting the profiles remotely from the server)?

    Thanks in advance.

  2. #2


    Join Date
    Feb 2007
    Location
    51.405546, -0.510212
    Posts
    8,125
    Thank Post
    203
    Thanked 2,390 Times in 1,770 Posts
    Rep Power
    704
    DelProf doesn't seem to work 100% of the time for me either. It often has trouble with locally cached roaming profiles. I have had much better luck with this script.

  3. Thanks to Arthur from:

    Ignatius (14th August 2009)

  4. #3

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,144
    Thank Post
    113
    Thanked 518 Times in 447 Posts
    Blog Entries
    2
    Rep Power
    121
    Do you have a machine startup script? If so, why not just add delprof to that? You would have something like:
    Code:
    set oShell=createobject("wscript.shell")
    intDays=1
    strPath = "\\server\tools$\delprof.exe" 
    sCmd=strPath & " /q /i  /d:" & CStr(intDays)
    oShell.run sCmd,,true
    This leaves out the possibility that it's not connecting to the remote computer and because you're running it at startup there's no risk of files being open etc. The "true" at the end of the run line will make the script wait for this to complete. You could leave it off but you run the risk of a user trying to log on while delprof is deleting their profile which is not good :-)

  5. Thanks to srochford from:

    Ignatius (14th August 2009)

  6. #4

    Join Date
    May 2009
    Location
    UK
    Posts
    291
    Thank Post
    64
    Thanked 21 Times in 20 Posts
    Rep Power
    14
    @Arthur - yes, I've seen that script. I realise that it tweaks the registry and I assume that it does all the necessary manipulations to keep everything tidy. Much better than simply deleting the c:\documents and settings\<username> folder. I might have to resort to that (or DeleteProfiles.exe) but I was intrigued to see that my script works if I insert a delay into it.

    @Steve - yes, it is a machine startup script. I know that DelProf must run with Admin (or System) privileges. I see that you've slimmed down the script to the bare essentials. I'll have a play around with it to see if it works without a delay being required.

SHARE:
+ Post New Thread

Similar Threads

  1. restart system from startup script
    By spaterso in forum Windows
    Replies: 3
    Last Post: 30th July 2009, 08:27 PM
  2. Windows Update in a startup script.
    By MaxBerzon in forum Windows
    Replies: 2
    Last Post: 30th April 2009, 03:48 PM
  3. Startup Script
    By Chuckster in forum Windows
    Replies: 5
    Last Post: 26th February 2009, 12:53 PM
  4. Installing GoogleSketchup 6 via startup script
    By markwilliamson2001 in forum Windows
    Replies: 3
    Last Post: 4th March 2008, 07:26 PM
  5. RM CC3 Startup Script
    By randle in forum Windows
    Replies: 4
    Last Post: 30th July 2007, 02:56 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
  •