delete old profile through bat file

  • Thread starter Thread starter Vijay
  • Start date Start date
V

Vijay

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
 
Vijay said:
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%
 
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 said:
Vijay said:
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 said:
Op,

Why not use the Microsoft service to delete redundant profiles?

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

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

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.
 
Please tell me the bat command only, i think you described with help of vb,

Pegasus said:
SPAMCOP User said:
Op,

Why not use the Microsoft service to delete redundant profiles?

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

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

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.


.
 
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 said:
Please tell me the bat command only, i think you described with help of
vb,

Pegasus said:
SPAMCOP User said:
Op,

Why not use the Microsoft service to delete redundant profiles?

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

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

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.


.
 
Back
Top