cmarti
(Hey THIS is FUN)
2003-12-19 05:33 PM
Delprof using Kixtart

How can I get the delprof.exe(deletes profles, from the 2k resource kit) to run using kix. I've tried all of the following:
Code:

Shell '%Comspec% /c Delprof /d:90'
Shell '%Comspec% /c Delprof /?'
Shell '%Comspec% /c Delprof'
Shell 'Delprof'
Shell '%Comspec% /c "Delprof /d:90"'



No matter what I use they all return with this...
Delete inactive profiles on \\MyMachineName (Yes/No)

When I run the command straight from dos it runs ok and prompts to delete profiles unused for x days. It seems as if none of the arguments are being passed to the delprof command. I'm running kix 4.02 on windows 2k sp3.

Thanks in advance...


maciep
(Korg Regular)
2003-12-19 05:54 PM
Re: Delprof using Kixtart

This works for me.

Code:
 shell "delprof /d:90" 



ShaneEP
(MM club member)
2003-12-19 06:07 PM
Re: Delprof using Kixtart

Maybe try specifying the full path to delprof.exe?

cmarti
(Hey THIS is FUN)
2003-12-19 06:08 PM
Re: Delprof using Kixtart

Thanks, but I've already tried that, it didn't work either. This will be running on a terminal server, does that matter?

ShaneEP
(MM club member)
2003-12-19 06:17 PM
Re: Delprof using Kixtart

The following works fine for me...On WinXP Pro Machine. Will try it on a Term Server and let you know what I get.

Code:
$null = SetOption ("WrapAtEOL","On")
Shell 'delprof /D:90'
? "Press Any Key To Continue"
get $null



ShaneEP
(MM club member)
2003-12-19 06:23 PM
Re: Delprof using Kixtart

It also worked as expected on Win2000 server with TS and Citrix. What version of DelProf are you using? I have 5.2.3790.0.

Sealeopard
(KiX Master)
2003-12-19 06:28 PM
Re: Delprof using Kixtart

Why not do it with KiXtart:
Code:

$maxprofileage=20
$profilelist=$HKLM+'\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList'
$profiles=arrayenumkey($profilelist)

for each $usersid in $profiles
if $usersid<>'' and right($usersid,4)<>'-500'
$username=sidtoname($usersid)
$username=right($username,len($username)-instrrev($username,'\'))
if $username=''
$username='account unknown: '+$usersid
endif
$profiledir=expandenvironmentvars(readvalue($profilelist+'\'+$usersid,'ProfileImagePath'))
if $profiledir<>''
$userprofiles=dirlist($profiledir+'.*',1)
for each $userprofile in $userprofiles
$profiledate=getfiletime($userprofile+'\ntuser.dat')
$profiledate=left($profiledate,10)
if datemath($profiledate,@DATE)>$maxprofileage
$shellcommand='rd /s /q '+$userprofile
shell '%COMSPEC% /c '+$shellcommand
if $userprofile=$profiledir
$retcode=delkey($profilelist+'\'+$usersid)
endif
endif
next
endif
endif
next



cmarti
(Hey THIS is FUN)
2003-12-19 06:45 PM
Re: Delprof using Kixtart

CitrixMan, my version was lower than yours so I downloaded the newest version from Microsoft's site. Now I'm running verion 5.2.3790.1060.

Here's what I get on my screen:

E:\>type test.scr
shell '\\cmarti2ksrv\e$\Delprof /d:20'
E:\>kix32 test.scr

Delete inactive profiles on \\CMARTI2KSRV? (Yes/No) n

Nothing deleted.


E:\>delprof /d:20

Delete profiles on \\CMARTI2KSRV that have not been used in the last 20 days? (Y
es/No) n

Nothing deleted.


E:\>


Check out the difference in the output betwen running it from a script and running the delprof command from the command line. I only want to delete unused profiles older than 20 days...

Sealeopard,
Thanks for the code. I hadn't tried to delete the profile through kix because I didn't know what all it involved.

Thanks..


Sealeopard
(KiX Master)
2003-12-19 07:03 PM
Re: Delprof using Kixtart

The principle is to enumerate all profiles on the computer. Then discard all local profiles and the admin profiles (SID ends with -500). Then use the user registry hive file NTUSER.DAT to check when it was last accessed. Calculate the difference between that date and today to see whether the profile is above the delete-threshold. Then delete the profile directory and remove the appropriate registry key.

ShaneEP
(MM club member)
2003-12-19 07:37 PM
Re: Delprof using Kixtart

Pure kix will certainly work...I am just a bit curious/confused as to why the delprof.exe does not work. What version of Kix are you running (it worked with both kix32.exe and wkix32.exe ver 4.22 on mine)? And have you tried it on multiple machines or just the one.

cmarti
(Hey THIS is FUN)
2003-12-19 07:40 PM
Re: Delprof using Kixtart

I'm running kix 4.02, I've also tried using 4.22. I've also tried it on 3 different machines and get the same output...

Les
(KiX Master)
2003-12-19 09:02 PM
Re: Delprof using Kixtart

Could it be because you are running it from/against a remote UNC path?

cmarti
(Hey THIS is FUN)
2003-12-19 09:25 PM
Re: Delprof using Kixtart

I've tried running it from the local machine and it doesn't work either. In my very first post of this thread was how I was running it..

Kdyer
(KiX Supporter)
2003-12-20 06:43 AM
Re: Delprof using Kixtart

If you are interested.. Here is a variation of this that I have talked about recently - Re: Citrix Clean up script

It should be pretty simple to modify to what you need.

Kent


acmp
(Getting the hang of it)
2004-07-09 11:44 AM
Re: Delprof using Kixtart

Bit late this, but never mind.

How will the pure KiX soloution remove special folders such as the recyclebin? As far as I can see it only deletes the profiles sub folder for a user.

Although it's a nice bit of code I just don't think it will work as well as delprof.

I use :
Code:

;===============================================================================================
; delprof.kix
; Last Modified on 21/01/04 at 13:59:52 by acmp
;===============================================================================================

;tidy up profiles on remote PC

;Change Log:-
;21/1/04 Set exit to be when no information is entered rather than prompt and Loop
;21/1/04 Put logging into main IF loop so that it only applies when the process runs OK

Break on

;splash
Big
Color w+/n
?" DelProf!"
Sleep(1)
;Header
Small
CLS
Box(1,1,10,40,"double")
At(2,9)"Profile tidyup by acmp"
At(3,9)"======================"
Color w/n
At(5,4)"Enter a PC name to tidy up."
At(6,4)"This program uses delprof from the"
At(7,4)"NT RES Kit, located in efolders"
At(8,4)"Results are logged in delprof.log"

At(11,1)
:Loop
?"Enter the PC name you wish to tidy (Or [Return] to quit)"@CRLF
Gets $pc

If Asc($pc)<>0
;If $pc<>asc(0)
$pc=Trim($pc)
$free=pipe("dir \\$pc\admin$")
For Each $line In $free
If InStr ($line,"bytes free")
?Trim($line) +" Before delprof"
$splitted=Split(Trim($line)," ",1)
For Each $element In $splitted
$before=$element
Next
EndIf
Next

$status=Pipe("\\server13\efolders\delprof.exe /q /i /c:\\$pc")

For Each $line In $status
?$line
Next

$free=pipe("dir \\$pc\admin$")
For Each $line In $free
If InStr ($line," bytes free")
?Trim($line) +" After delprof"
$splitted=Split(Trim($line)," ",1)
For Each $element In $splitted
$after=$element
Next
EndIf
Next
$entry=$pc+",'"+$before+"','"+$after+"',"+@USERID
writelog2("\\server13\netapps\KixLogs\delprof.log",$entry,1)
Else
Exit
EndIf

?""
?"done"
GoTo("Loop")

Function pipe($command)
;$array = pipe("net users") ; load output of net users into an array
;$array = pipe("dir c:\*.ini /s /b") ; load a listing of all ini files into an array
;$array = pipe("type config.txt") ; load the contents of a text file into an array
;$ipconfig = pipe('ipconfig /all | find "Server"')
;For Each $line In $ipconfig
; ? $line
;Next
Dim $i,$error,$line
Dim $array[255]
Dim $ReDim $ReDim = Ubound($array)
Dim $tempfile $tempfile = "%temp%\pipe.tmp"
If Exist("$tempfile")
Del("$tempfile")
EndIf
If @inwin = 2 ; win9x
Shell '%comspec% /c $command >"$tempfile"'
Else ; winnt
Shell '%comspec% /c $command >"$tempfile" 2>nul'
EndIf
$error=@error
If Open(10,"$tempfile") = 0
$i=0
$line = ReadLine(10)
While NOT @error
If $line
$array[$i] = $line
If $i = $ReDim
$ReDim=$ReDim*2
ReDim preserve $array[$ReDim]
EndIf
$i=$i+1
EndIf
$line = ReadLine(10)
Loop
$=Close(10)
Del "$tempfile"
If $i > 0
ReDim preserve $array[$i-1]
$pipe=$array
Else
$pipe = 0
EndIf
Exit $error
Else
$pipe = 0
Exit @error
EndIf
EndFunction

Function WriteLog2($File, $Text, optional $TimeStamp)
;WriteLog2($File, $text, [0|1])

Dim $RC, $File, $text, $FH, $TimeStamp
$FH=1
$RC=Open ($FH, $File, 5)
While $RC = -3
$FH=$FH +1
$RC=Open ($FH, $File, 5)
Loop
Select
Case $RC=0
If ($TimeStamp=1)
$TimeStamp = "," +@Date + "," + @Time
Else
$TimeStamp = ""
EndIf
$RC=WriteLine ($FH, $Text + $TimeStamp+ @CRLF)
$RC=Close ($FH)
Case $RC=-2
$text = "WriteLog2: Invalid file handle ($FH) specified when trying to Open $File."
;$RC=MessageBox ($text,"Script Error",48)
Case $RC=-1
$text = "WriteLog2: Invalid file name ($File) specified for log file."
;$RC=MessageBox ($text,"Script Error",48)
Case $RC=>0
$text = "System Error($RC) while attempting to open log file ($File)."
;$RC=MessageBox ($text,"Script Error",48)
EndSelect
EndFunction



I have it packaged with KixStart and just run it from a shortcut and it is brill.

acmp<><


Christopher Hill
(Fresh Scripter)
2006-01-20 01:05 PM
Re: Delprof using Kixtart

Quote:

How can I get the delprof.exe(deletes profles, from the 2k resource kit) to run using kix...

No matter what I use they all return with this...
Delete inactive profiles on \\MyMachineName (Yes/No)

When I run the command straight from dos it runs ok and prompts to delete profiles unused for x days. It seems as if none of the arguments are being passed to the delprof command. I'm running kix 4.02 on windows 2k sp3.

Thanks in advance...




This is probably waaay too late for the original poster, but I've just run into the same problem and just in case someone else needs the solution:

delprof will do this if you run it as 'Delprof.exe' instead of 'delprof.exe' (notice the case!) So make sure that your script runs 'delprof.exe' ALL in lower case and you should be OK.

Strange but true...


Arend_
(MM club member)
2006-01-20 09:24 PM
Re: Delprof using Kixtart

This is how it works
Code:

Run "@lserver\netlogon\delprof.exe /Q /D:90"



the /Q makes it quiet, and won't ask for Y/N
(I've been using this for over a year now on clients and terminal servers)