Page 1 of 1 1
Topic Options
#190701 - 2008-11-20 06:36 PM Weekly Cleanup Script
skyworksvideo Offline
Just in Town

Registered: 2008-11-20
Posts: 2
Hello all. New to the board here. I have not had much experience with scripting and can do very basic tasks but would like to make a script that can defragment, check disk and perform disk cleanup weekly for my users. I have a script that I tried to use but it doesn't seem to work unless defrag and such have reduced their time to seconds. The computers shutdown normally on friday and it is like the script isn't being applied. I have the below script in the Logoff section of the AD Group Policy that is being applied. Any ideas / help would be greatly appreciated, and hopefully through the use of this board I can learn more about scripting and help others! Thanks.

 Code:
; Global PM Script
; SIJ 11/08/08
;
; -------------------------
;
; All Users
SETCONSOLE ("HIDE")

WriteValue ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion", "RegisteredOwner", "SIJ", "REG_SZ")
WriteValue ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion", "RegisteredOrganization", "SIJ", "REG_SZ")

WriteValue
("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Active
Setup Temp Folders", "StateFlags0001", "00000002", "REG_DWORD")
WriteValue
("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Compress
old files", "StateFlags0001", "00000002", "REG_DWORD")
WriteValue
("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Content
Indexer Cleaner", "StateFlags0001", "00000002", "REG_DWORD")
WriteValue
("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Downloaded
Program Files", "StateFlags0001", "00000002", "REG_DWORD")
WriteValue
("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Internet
Cache Files", "StateFlags0001", "00000002", "REG_DWORD")
WriteValue
("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Memory
Dump Files", "StateFlags0001", "00000002", "REG_DWORD")
WriteValue
("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Microsoft_Event_Reporting_2.0_Temp_Files",
"StateFlags0001", "00000002", "REG_DWORD")
WriteValue
("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Old
ChkDsk Files", "StateFlags0001", "00000002", "REG_DWORD")
WriteValue
("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Remote
Desktop Cache Files", "StateFlags0001", "00000002", "REG_DWORD")
WriteValue
("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Setup
Log Files", "StateFlags0001", "00000002", "REG_DWORD")
WriteValue
("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary
Files", "StateFlags0001", "00000002", "REG_DWORD")
WriteValue
("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\WebClient
and WebPublisher Cache", "StateFlags0001", "00000002", "REG_DWORD")

IF @Day='Friday'
	RUN "chkdsk.exe C: /F"
	RUN "cleanmgr.exe /dc /sagerun:1"
	RUN "defrag.exe C:"
	RUN "shutdown.exe -s"
ENDIF




Edited by NTDOC (2008-11-21 10:49 PM)
Edit Reason: added CODE TAGS

Top
#190704 - 2008-11-20 08:24 PM Re: Weekly Cleanup Script [Re: skyworksvideo]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11611
Loc: CA
Well you have a few issues

Unless your users have local Admin rights on the system they can't run any of this. (if they do have local Admin rights then that is a no no as well)

Okay so let's suppose they do have local Admin rights. Well you can't use the RUN command because basically that tries to run each command one after the other without waiting for the first to finish. You should use the SHELL command so that it waits.

On your command for CHKDSK - that needs input which you did not supply so basically it will run that but never complete (unless the user sees it and is able to press the Y key for it).

Here is a method you can use to supply that command.
 Code:
CMD /C ECHO Y|CHKDSK C: /F


Without using SAGESET I'm not sure you can use the SAGERUN command like that.
How to Automate the Disk Cleanup Tool in Windows XP

The Shutdown command switch is a forward slash / not a hyphen -

Basically what happens is that it sees the CHKDSK command but can't finish it as it's waiting for input,
then it sees and runs CLEANMGR, but then it gets the DEFRAG command but because CLEANMGR is running it may be too high of CPU and Disk utilization already at this point so it can't do much.
Then it gets the SHUTDOWN command, but basically all these commands happen within seconds of each other so you're luck you don't actually cause some type of data corruption.

Try using SHELL for each and input the CHKDSK as shown and hopefully all should be okay.

Now think about how to manage this without the user needing to be an Admin.

Top
#190711 - 2008-11-21 10:21 AM Re: Weekly Cleanup Script [Re: NTDOC]
Arend_ Moderator Online   sleepy
MM club member
*****

Registered: 2005-01-17
Posts: 1887
Loc: Hilversum, The Netherlands
Run it as startup script, then the script has admin privilidges.
Top
#190714 - 2008-11-21 03:25 PM Re: Weekly Cleanup Script [Re: Arend_]
skyworksvideo Offline
Just in Town

Registered: 2008-11-20
Posts: 2
Thanks to you both. I will try those suggestions and let you know the result. The users do have local admin on their machine because after a 25 hour server rebuild project, Outlook profiles and other things weren't working unless they had local admin so we are working on that one step at a time. Now you mentioned running it as a Startup script. Wouldn't that slow things down when the system boots, thus not allowing someone to get right to work? Just trying to see what we can do for them with this. Thanks again!

Edit: I should probably be able to find this in the config or readme, but is there a way to output the success of this script to a log file so I can ensure that it is running properly?


Edited by skyworksvideo (2008-11-21 03:28 PM)

Top
#190721 - 2008-11-21 08:56 PM Re: Weekly Cleanup Script [Re: skyworksvideo]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11611
Loc: CA
Different ways to do different things. Myself I would probably create a scheduled task for it, but that's my preference. In fact I do already have a couple of the same tasks you're doing as scheduled tasks for my user's machines.
Top
#190725 - 2008-11-21 10:40 PM Re: Weekly Cleanup Script [Re: NTDOC]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4350
Loc: New Jersey
Task scheduler is definitely the way to go. You can specify any credentials without relying on the user being logged on, having admin rights, or anything else.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#190772 - 2008-11-27 11:47 AM Re: Weekly Cleanup Script [Re: Glenn Barnas]
BillBarnard Offline
Starting to like KiXtart

Registered: 2007-03-14
Posts: 141
Loc: Leighton Buzzard, Bedfordshire...
Just a small additionla note on CHKDSK C: /f
This command won't execute until the next reboot on the C: drive.
See output below...

C:\>chkdsk c: /f
The type of the file system is NTFS.
Cannot lock current drive.

Chkdsk cannot run because the volume is in use by another
process. Would you like to schedule this volume to be
checked the next time the system restarts? (Y/N)


Regards, Bill
_________________________
Bill

Top
#191885 - 2009-01-23 04:06 PM Re: Weekly Cleanup Script [Re: BillBarnard]
BillBarnard Offline
Starting to like KiXtart

Registered: 2007-03-14
Posts: 141
Loc: Leighton Buzzard, Bedfordshire...
One quick update on the shutdown command syntax.
It accepts both forward slashes and hyphens for its switches.

U:\>shutdown
Usage: shutdown [-i | -l | -s | -r | -a] [-f] [-m \\computername] [-t xx] [-c "c
omment"] [-d up:xx:yy]

No args Display this message (same as -?)
-i Display GUI interface, must be the first option
-l Log off (cannot be used with -m option)
-s Shutdown the computer
-r Shutdown and restart the computer
-a Abort a system shutdown
-m \\computername Remote computer to shutdown/restart/abort
-t xx Set timeout for shutdown to xx seconds
-c "comment" Shutdown comment (maximum of 127 characters)
-f Forces running applications to close without war
ning
-d [u][p]:xx:yy The reason code for the shutdown
u is the user code
p is a planned shutdown code
xx is the major reason code (positive integer le
ss than 256)
yy is the minor reason code (positive integer le
ss than 65536)
_________________________
Bill

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 353 anonymous users online.
Newest Members
Praveer, Ollero, rayyo, Foxlicht, DonChild
17742 Registered Users

Generated in 0.073 seconds in which 0.052 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org