PDA

View Full Version : delete old profile through bat file


Vijay
November 24th 09, 12:49 PM
hi,

I want to delete old user profile (old more than one day ) ,
Please tell me the bat file command to delete these profiles......

thanks,,

vijay

Pegasus [MVP]
November 24th 09, 01:46 PM
"Vijay" > wrote in message
...
> hi,
>
> I want to delete old user profile (old more than one day ) ,
> Please tell me the bat file command to delete these profiles......
>
> thanks,,
>
> vijay

Seems a dangerous thing to do, like running around with a few razor blades
in your hands. Still - it's your machine. Remember to unwrapped wrapped
lines, to remove the line numbers, to set the exclusions and to test it from
a Console screen before activating it. To make this tool fully active you
must change this line
[20] %VB% 'oFSO.DeleteFolder(oFolder.Path)
like so:
[20] %VB% oFSO.DeleteFolder(oFolder.Path)

Note: When you use this tool, all responsibility lies with you.

[01] @echo off
[02] set Active=false
[03] set Exclusions=/Administrator/LocalService/NetworkService/Default User/
[04] set Scr=c:\TempVBS.vbs
[05] set VB=echo^>^>%Scr%
[06] cd 1>nul 2>%Scr%
[07]
[08] %VB% Set oFSO = CreateObject("Scripting.FileSystemObject")
[09] %VB% Set oWshShell = CreateObject("WScript.Shell")
[10] %VB% sProfiles =
oWshShell.ExpandEnvironmentStrings("%AllUsersProfile%\..")
[11] %VB% sProfiles = oFSO.GetAbsolutePathName(sProfiles)
[12] %VB% For Each oFolder In oFSO.GetFolder(sProfiles).SubFolders
[13] %VB% If InStr(1, "%Exclusions%", "/" ^& oFolder.Name ^& "/", 1) = 0
Then
[14] %VB% If oFSO.FileExists(oFolder.Path ^& "\ntuser.dat") Then
[15] %VB% dFileDate = oFSO.GetFile(oFolder.Path ^&
"\ntuser.dat").DateLastModified
[16] %VB% If DateDiff("d", dFileDate, Date()) ^> 1 Then
[17] %VB% WScript.Echo "Deleting", oFolder.Path
[18] %VB% If %Active% Then
[19] %VB% On Error Resume Next
[20] %VB% 'oFSO.DeleteFolder(oFolder.Path)
[21] %VB% if err.number ^> 0 then WScript.Echo Err.Description
[22] %VB% On Error Goto 0
[23] %VB% End If
[24] %VB% End If
[25] %VB% End If
[26] %VB% End If
[27] %VB% Next
[28] cscript //nologo %Scr%
[29] del %Scr%

Spamcop User
November 24th 09, 11:54 PM
Op,

Why not use the Microsoft service to delete redundant profiles?

==============

What about the owner profile, Pergasus? Not in your default exclusions

--
SPAMCOP User


"Pegasus [MVP]" > wrote in message
...
>
> "Vijay" > wrote in message
> ...
>> hi,
>>
>> I want to delete old user profile (old more than one day ) ,
>> Please tell me the bat file command to delete these profiles......
>>
>> thanks,,
>>
>> vijay
>
> Seems a dangerous thing to do, like running around with a few razor blades
> in your hands. Still - it's your machine. Remember to unwrapped wrapped
> lines, to remove the line numbers, to set the exclusions and to test it
> from a Console screen before activating it. To make this tool fully active
> you must change this line
> [20] %VB% 'oFSO.DeleteFolder(oFolder.Path)
> like so:
> [20] %VB% oFSO.DeleteFolder(oFolder.Path)
>
> Note: When you use this tool, all responsibility lies with you.
>
> [01] @echo off
> [02] set Active=false
> [03] set Exclusions=/Administrator/LocalService/NetworkService/Default
> User/
> [04] set Scr=c:\TempVBS.vbs
> [05] set VB=echo^>^>%Scr%
> [06] cd 1>nul 2>%Scr%
> [07]
> [08] %VB% Set oFSO = CreateObject("Scripting.FileSystemObject")
> [09] %VB% Set oWshShell = CreateObject("WScript.Shell")
> [10] %VB% sProfiles =
> oWshShell.ExpandEnvironmentStrings("%AllUsersProfile%\..")
> [11] %VB% sProfiles = oFSO.GetAbsolutePathName(sProfiles)
> [12] %VB% For Each oFolder In oFSO.GetFolder(sProfiles).SubFolders
> [13] %VB% If InStr(1, "%Exclusions%", "/" ^& oFolder.Name ^& "/", 1) = 0
> Then
> [14] %VB% If oFSO.FileExists(oFolder.Path ^& "\ntuser.dat") Then
> [15] %VB% dFileDate = oFSO.GetFile(oFolder.Path ^&
> "\ntuser.dat").DateLastModified
> [16] %VB% If DateDiff("d", dFileDate, Date()) ^> 1 Then
> [17] %VB% WScript.Echo "Deleting", oFolder.Path
> [18] %VB% If %Active% Then
> [19] %VB% On Error Resume Next
> [20] %VB% 'oFSO.DeleteFolder(oFolder.Path)
> [21] %VB% if err.number ^> 0 then WScript.Echo Err.Description
> [22] %VB% On Error Goto 0
> [23] %VB% End If
> [24] %VB% End If
> [25] %VB% End If
> [26] %VB% End If
> [27] %VB% Next
> [28] cscript //nologo %Scr%
> [29] del %Scr%
>
>

Pegasus [MVP]
November 25th 09, 12:03 AM
"SPAMCOP User" > wrote in message
...
> Op,
>
> Why not use the Microsoft service to delete redundant profiles?
>
> ==============
>
> What about the owner profile, Pergasus? Not in your default exclusions
>
> --
> SPAMCOP User

That's why I wrote "Remember to [..] set the exclusions". If the OP wants to
use such a dangerous tool then he must have the sense
a) To set his own exclusions, and
b) To fully test the script before activating it.

Vijay
November 25th 09, 10:33 AM
Please tell me the bat command only, i think you described with help of vb,

"Pegasus [MVP]" wrote:

>
> "SPAMCOP User" > wrote in message
> ...
> > Op,
> >
> > Why not use the Microsoft service to delete redundant profiles?
> >
> > ==============
> >
> > What about the owner profile, Pergasus? Not in your default exclusions
> >
> > --
> > SPAMCOP User
>
> That's why I wrote "Remember to [..] set the exclusions". If the OP wants to
> use such a dangerous tool then he must have the sense
> a) To set his own exclusions, and
> b) To fully test the script before activating it.
>
>
> .
>

Pegasus [MVP]
November 25th 09, 10:38 AM
I did give you a batch file. While there is a VB Script file embedded in it,
this is irrelevant. Just leave it as it is (with the exception of these
lines:

[20] %VB% 'oFSO.DeleteFolder(oFolder.Path)
[20] %VB% oFSO.DeleteFolder(oFolder.Path)
)

"Vijay" > wrote in message
...
> Please tell me the bat command only, i think you described with help of
> vb,
>
> "Pegasus [MVP]" wrote:
>
>>
>> "SPAMCOP User" > wrote in message
>> ...
>> > Op,
>> >
>> > Why not use the Microsoft service to delete redundant profiles?
>> >
>> > ==============
>> >
>> > What about the owner profile, Pergasus? Not in your default exclusions
>> >
>> > --
>> > SPAMCOP User
>>
>> That's why I wrote "Remember to [..] set the exclusions". If the OP wants
>> to
>> use such a dangerous tool then he must have the sense
>> a) To set his own exclusions, and
>> b) To fully test the script before activating it.
>>
>>
>> .
>>

Willard
November 26th 09, 02:39 PM
What is the "Microsoft Service" and where do you find lt ??

SPAMCOP User wrote:
> Op,
>
> Why not use the Microsoft service to delete redundant profiles?
>
> ==============
>
> What about the owner profile, Pergasus? Not in your default exclusions
>
>

Pegasus [MVP]
November 26th 09, 04:35 PM
It's not a "Microsoft Service" that Spamcop was thinking about but rather
the "User Profile Deletion Utility" (Delprof.exe) - see here:
http://www.microsoft.com/downloads/details.aspx?familyid=901a9b95-6063-4462-8150-360394e98e1e&displaylang=en


"Willard" > wrote in message
...
> What is the "Microsoft Service" and where do you find lt ??
>
> SPAMCOP User wrote:
>> Op,
>>
>> Why not use the Microsoft service to delete redundant profiles?
>>
>> ==============
>>
>> What about the owner profile, Pergasus? Not in your default exclusions
>>
>>

Google