Intro Download and install Frequently Asked Questions Tips and tricks

Homepage







© J.C. Kessels 2009
MyDefrag Forum
June 19, 2013, 04:50:57 pm *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: Script for automated system optimization  (Read 4485 times)
BloodySword
JkDefrag Hero
*****
Posts: 1114



View Profile
« on: August 07, 2010, 09:30:47 am »

Here a quiet CMD script for optimizing your system:

@echo Killing disruptive processes...
@taskkill /F /IM explorer.exe > nul
@REM taskkill /F /IM another.exe > nul
@echo Deleting USN Journal..
@REM (only on XP and Vista)
@fsutil usn deletejournal /D c:
@echo Clearing recycle bins...
@rd /S /Q C:\$RECYCLE.BIN > nul
@rd /S /Q D:\$RECYCLE.BIN > nul
@echo Optimizing Mozilla's SQLITE databases...
@REM Please change the path's to your needs. You need sqlite3.exe!
@for %%i in ("C:\Users\Dennis\AppData\Roaming\Mozilla\Firefox\Profiles\BloodySword\*.sqlite") do @echo VACUUM; | sqlite3 %%i
@for %%i in ("C:\Users\Dennis\AppData\Local\Mozilla\Firefox\Profiles\BloodySword\*.sqlite") do @echo VACUUM; | sqlite3 %%i
@for %%i in ("C:\Users\Dennis\AppData\Roaming\Thunderbird\Profiles\BloodySword\*.sqlite") do @echo VACUUM; | sqlite3 %%i
@for %%i in ("C:\Users\Dennis\AppData\Local\Thunderbird\Profiles\BloodySword\*.sqlite") do @echo VACUUM; | sqlite3 %%i
@echo Refreshing Prefetch information (layout.ini)...
@rundll32.exe advapi32.dll,ProcessIdleTasks > nul
@echo Optimizing drive C: using MyDefrag script SystemDiskMonthlyNW.MyD...
@"C:\Program Files\MyDefrag\MyDefrag.exe" -r "C:\Program Files\MyDefrag\Scripts\SystemDiskMonthlyNW.MyD" c:
@echo Optimizing drive D: using MyDefrag script DataDiskMonthlyNW.MyD...
@"C:\Program Files\MyDefrag\MyDefrag.exe" -r "C:\Program Files\MyDefrag\Scripts\DataDiskMonthlyNW.MyD" d:
@REM Restarting killed application... or shutting down with shutdown -f -s -t 10
@start "" explorer.exe
@REM shutdown -f -s -t 10


Content for SystemDiskMonthlyNW.MyD:

!include "DataDiskMonthly.MyD"!
WhenFinished(Exit)


Content for DateDiskMonthlyNW.MyD

!include "SystemDiskMonthly.MyD"!
WhenFinished(Exit)
« Last Edit: August 07, 2010, 09:32:39 am by BloodySword » Logged

Greetings from Germany!
Darlis
JkDefrag Hero
*****
Posts: 1725


View Profile WWW
« Reply #1 on: August 07, 2010, 01:03:43 pm »

Note that "fsutil usn deletejournal /D" and "rundll32.exe advapi32.dll,ProcessIdleTasks" may take some time to complete. If they're still working while MyDefrag is running, you'll get lots of unmovable files and "black holes".
Logged

Need help creating a script? Try MyDefrag Script Creator.
BloodySword
JkDefrag Hero
*****
Posts: 1114



View Profile
« Reply #2 on: August 07, 2010, 02:10:10 pm »

In my case, the command is always halting the script for a while till the next command is executed.
A wait after that would indeed be a good idea. But how long and how should this wait be implemented?
Logged

Greetings from Germany!
Darlis
JkDefrag Hero
*****
Posts: 1725


View Profile WWW
« Reply #3 on: August 07, 2010, 03:26:39 pm »

You could use
ping -n 123 localhost > nul
or use an additional tool like wait.exe.

I don't know long the script should wait, it depends on the system (both hardware and software configuration) . But since it's an automated script, how about one or two minutes?
Logged

Need help creating a script? Try MyDefrag Script Creator.
BloodySword
JkDefrag Hero
*****
Posts: 1114



View Profile
« Reply #4 on: August 07, 2010, 05:11:13 pm »

That's a bit long but I think it would be safe then...
But I did not experience any unmovable file or many black holes in wrap around fragmentation.
Logged

Greetings from Germany!
Darlis
JkDefrag Hero
*****
Posts: 1725


View Profile WWW
« Reply #5 on: August 07, 2010, 06:02:34 pm »

Another solution would be to use
fsutil usn deletejournal /N c:
and to not update the prefetch files, since they are updated automatically every three days.
Logged

Need help creating a script? Try MyDefrag Script Creator.
BloodySword
JkDefrag Hero
*****
Posts: 1114



View Profile
« Reply #6 on: August 07, 2010, 10:35:00 pm »

Another solution would be to use
fsutil usn deletejournal /N c:

Notifying is not what I'm intended because it would be done when the system is idle and this would be AFTER defragmentation.

and to not update the prefetch files, since they are updated automatically every three days.

Very bad idea. Think you run the script today and tomorrow the prefetch layout will be updated. Everything was for nothing...
Logged

Greetings from Germany!
Darlis
JkDefrag Hero
*****
Posts: 1725


View Profile WWW
« Reply #7 on: August 08, 2010, 08:18:59 am »

Notifying is not what I'm intended because it would be done when the system is idle and this would be AFTER defragmentation.
Where does it say that this is only being done when the system is idle? According to TechNet it is done right away:
Quote from: TechNet
/d Disables an active USN change journal, and returns input/output (I/O) control while the change journal is being disabled.
/n Disables an active USN change journal and returns I/O control only after the change journal is disabled.
...
Deleting or disabling an active change journal is very time consuming, because the system must access all the records in the master file table (MFT) and set the last USN attribute to 0 (zero). This process can take several minutes, and it can continue after the system restarts, if a restart is necessary. During this process, the change journal is not considered active, nor is it disabled. While the system is disabling the journal, it cannot be accessed, and all journal operations return errors. You should use extreme care when disabling an active journal, because it adversely affects other applications that are using the journal.

Very bad idea. Think you run the script today and tomorrow the prefetch layout will be updated. Everything was for nothing...
The layout does not completely change, so the impact wouldn't be that noticeable. But if you want to keep it: When I update the layout on old PCs with lots of programs, if often takes a whole minute until the process is done. Your system may be faster and the script works for you, but if you want to publish your script for many users with different systems, you have to take this into account, too.
Logged

Need help creating a script? Try MyDefrag Script Creator.
BloodySword
JkDefrag Hero
*****
Posts: 1114



View Profile
« Reply #8 on: August 08, 2010, 11:44:03 am »

Deleting the Jorunal is only an option. It is no must have.

On my system, when I let rebuilt the layout.ini, rundll32.exe stays alife till the process is done and then rundll32.exe closes with error code 0.
Can you check it on XP, or Vista without SP, with SP1, too? I do not have such systems around :/. Perhaps on XP and older Vista versions Rundll32 won't wait for advapi32.dll to complete it's task (perhaps because the real process is done in the prefetch / superfetch service and in this versions the service does not notify when it's finished). On Vista SP2 I'm 80% shure that advapi32.dll will wait till the service completed the task and after that, it will close it's thread wich will exit rundll32.exe. The process never tooked longer than 30 seconds on my machine. The system has about 200'000 files and folders and runs on a 2,5 Inch 5400 RPM Hitachi TravelStar Drive (5K320).
« Last Edit: August 08, 2010, 11:55:07 am by BloodySword » Logged

Greetings from Germany!
Darlis
JkDefrag Hero
*****
Posts: 1725


View Profile WWW
« Reply #9 on: August 08, 2010, 12:47:13 pm »

When I execute the command in the commandline I immediately get the I/O control back, but rundll32 stays longer active. It's the same on XP SP3 and 7.
If you don't use any special command to wait for rundll32 (or Vista just does that?) then MyDefrag would start right away while the updating is in progress...
Logged

Need help creating a script? Try MyDefrag Script Creator.
BloodySword
JkDefrag Hero
*****
Posts: 1114



View Profile
« Reply #10 on: August 12, 2010, 06:08:43 pm »

I tested it and you are right. Will be fixed in about 14 days, I'm busy now.
Logged

Greetings from Germany!
poutnik
JkDefrag Hero
*****
Posts: 1106


View Profile
« Reply #11 on: August 12, 2010, 08:46:55 pm »

In my case, the command is always halting the script for a while till the next command is executed.
A wait after that would indeed be a good idea. But how long and how should this wait be implemented?

what about   start /wait "command"   ?
Logged

It can be fast, good or easy. You can pick just 2 of them....
Treating Spacehog zone by the same effort as Boot zone is like cleaning a garden by the same effort as a living room.
BloodySword
JkDefrag Hero
*****
Posts: 1114



View Profile
« Reply #12 on: August 15, 2010, 04:00:29 pm »

This won't work because the task is executed in the service for prefetching and not in the dll itself. The dll is only flipping the domino and exits (and also rundll32)
Logged

Greetings from Germany!
Rohk
JkDefrag Hero
*****
Posts: 130


View Profile
« Reply #13 on: December 21, 2010, 01:58:49 pm »

So is it safer to wait some time after updating prefetch files?
ping localhost -n 20 -w 1000 > nul , waits for 20 seconds, is it enough?

I also added ccleaner to the script instead of only clearing recycle bins.
Start /wait CCleaner.exe /Auto

And for task kills I use another small utility called EndItAll. It kills all the user predefined processes.
Start /wait enditall.exe /K
Logged
BloodySword
JkDefrag Hero
*****
Posts: 1114



View Profile
« Reply #14 on: January 04, 2011, 08:42:03 am »

Thanks, I used a wait.exe wich I have written in VB6 some time ago. You can give a delay in milliseconds wich will use "sleep" api call.

I also use ccleaner now. With ccleaner (if configured) you can remove the database optimization lines for Firefox. Ccleaner optimizes also the databaes of Google Chrome (wich I use now instead of the slowfox!).
Logged

Greetings from Germany!
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.5 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!