Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

newbie

576 views
Skip to first unread message

wim

unread,
Oct 7, 2002, 10:50:28 AM10/7/02
to
Hello all,

im a student in my final year (IT) and as a test i have to work 3 months in
a company.
My first assignment is making a more stable network and finding a way to do
some things faster. (preferably automaticly.)

I've noticed windows scripting host will be the best way to do this. I'm not
sure if jscript is better than vbscript.. some of the examples i will have
to do are:
- setting a wallpaper
- no sounds scheme
-automating the outlook settings
- installing network printer
- mapping network drives (as i have asked before here)
-automaticly deleting cookies/temp internet files
-disabling personalized menu.
-deleting files if older than ... /bigger than..

i know this is a long list and i will try to write everything myself but if
anyone can give any tips/tricks, ill be glad to accept them :)
ive been through a lot of scripting sites already, but its hard to find a
good and an in-depth tutorial.

so if anyone is willing to give me some advice...

thanks a lot in advance!

wim

Torgeir Bakken (MVP)

unread,
Oct 7, 2002, 11:00:43 AM10/7/02
to
wim wrote:

> I've noticed windows scripting host will be the best way to do this. I'm not
> sure if jscript is better than vbscript..

You will find much more examples of admin scripting in vbscript than in jscript.

> some of the examples i will have
> to do are:

> (snip)


> -deleting files if older than ... /bigger than..

Here is a Michael Harris script that deletes files older than x days using the
filesystemobject. You set the folder the script starts looking in, and the value

of the bIncludeSubFolders parameter tells it to include subfolders or not.

It handles locked files properly.


' folder to start search in...
path = "c:\temp"

' delete files older than 7 days...
killdate = date() - 7

arFiles = Array()
set fso = createobject("scripting.filesystemobject")

' Don't do the delete while you still are looping through a
' file collection returned from the File System Object (FSO).
' The collection may get mixed up.
' Create an array of the file objects to avoid this.
'
SelectFiles path, killdate, arFiles, true

nDeleted = 0
for n = 0 to ubound(arFiles)
'=================================================
' Files deleted via FSO methods do *NOT* go to the recycle bin!!!
'=================================================
on error resume next 'in case of 'in use' files...
arFiles(n).delete true
if err.number <> 0 then
wscript.echo "Unable to delete: " & arFiles(n).path
else
nDeleted = nDeleted + 1
end if
on error goto 0
next

msgbox nDeleted & " of " & ubound(arFiles)+1 _
& " eligible files were deleted"


sub SelectFiles(sPath,vKillDate,arFilesToKill,bIncludeSubFolders)
on error resume next
'select files to delete and add to array...
'
set folder = fso.getfolder(sPath)
set files = folder.files

for each file in files
' uses error trapping around access to the
' Date property just to be safe
'
dtlastmodified = null
on error resume Next
dtlastmodified = file.datelastmodified
on error goto 0
if not isnull(dtlastmodified) Then
if dtlastmodified < vKillDate then
count = ubound(arFilesToKill) + 1
redim preserve arFilesToKill(count)
set arFilesToKill(count) = file
end if
end if
next

if bIncludeSubFolders then
for each fldr in folder.subfolders
SelectFiles fldr.path,vKillDate,arFilesToKill,true
next
end if
end sub


--
torgeir
Microsoft MVP Scripting and WMI
Porsgrunn Norway


wim

unread,
Oct 7, 2002, 11:16:26 AM10/7/02
to

"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message
news:3DA1A19B...@hydro.com...

> wim wrote:
>
> > I've noticed windows scripting host will be the best way to do this. I'm
not
> > sure if jscript is better than vbscript..
>
> You will find much more examples of admin scripting in vbscript than in
jscript.
>
>
>
> > some of the examples i will have
> > to do are:
> > (snip)
> > -deleting files if older than ... /bigger than..
>
> Here is a Michael Harris script that deletes files older than x days using
the
> filesystemobject. You set the folder the script starts looking in, and the
value
>
> of the bIncludeSubFolders parameter tells it to include subfolders or not.
>
> It handles locked files properly.
>

[edited]

> torgeir
> Microsoft MVP Scripting and WMI
> Porsgrunn Norway

Thanks a lot for your answer.
it's much appreciated.

...and ive been looking some things up and i will go with visual basic and
not jscript.

wim


wim

unread,
Oct 8, 2002, 4:49:13 AM10/8/02
to

"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message
news:3DA1A19B...@hydro.com...

>


> sub SelectFiles(sPath,vKillDate,arFilesToKill,bIncludeSubFolders)
> on error resume next
> 'select files to delete and add to array...
> '
> set folder = fso.getfolder(sPath)
> set files = folder.files
>
> for each file in files
> ' uses error trapping around access to the
> ' Date property just to be safe
> '
> dtlastmodified = null
> on error resume Next
> dtlastmodified = file.datelastmodified
> on error goto 0
> if not isnull(dtlastmodified) Then
> if dtlastmodified < vKillDate then
> count = ubound(arFilesToKill) + 1
> redim preserve arFilesToKill(count)
> set arFilesToKill(count) = file
> end if
> end if
> next

> ....

thanks again for the script.. but i dont understand on error goto 0.
could someone explain me that?

thanks in advance

wm


Torgeir Bakken (MVP)

unread,
Oct 8, 2002, 7:20:34 AM10/8/02
to
wim wrote:

Hi

"On Error GoTo 0" disables error handling if you have previously enabled it
using "On Error Resume Next".

Note that it also does a implicit Err.Clear (just as "On Error Resume Next"
does)

0 new messages