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.
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:
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).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 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.
Do you have a machine startup script? If so, why not just add delprof to that? You would have something like:
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 :-)Code:set oShell=createobject("wscript.shell") intDays=1 strPath = "\\server\tools$\delprof.exe" sCmd=strPath & " /q /i /d:" & CStr(intDays) oShell.run sCmd,,true
@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.
There are currently 1 users browsing this thread. (0 members and 1 guests)