#190701 - 2008-11-20 06:36 PM
Weekly Cleanup Script
|
skyworksvideo
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.
; 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
Registered: 2000-07-28
Posts: 11623
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.
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
|
|
|
|
#190714 - 2008-11-21 03:25 PM
Re: Weekly Cleanup Script
[Re: Arend_]
|
skyworksvideo
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
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
2 registered
(morganw, mole)
and 414 anonymous users online.
|
|
|