I wrote a script that edits the ini file to change DefragType value, then run SD with /SCHEDULE, then puts DefragType back to 0; however, SD never runs with the new DefragType.
Edit: Attached script. Additionally, I tried running SD with the /STARTUP switch but that didn't force it to re-read Config.ini.
Is there a way (i.e. command-line switch) to get SD to re-read the Config.ini file?
VB Script:
Const Defrag = 0
Const FastOptimize = 1
Const FullyOptimize = 2
Const ForReading = 1
Const ForWriting = 2
Function sRegRead(sRegistryKey, sDefault)
Dim oShell, Value
On Error Resume Next
Set oShell = CreateObject("WScript.Shell")
Value = oShell.RegRead(sRegistryKey)
If err.number <> 0 Then
sRegRead = sDefault
Else
sRegRead = Value
End If
Set oShell = Nothing
End Function
Set oShell = CreateObject("Shell.Application")
Set oFolder = oShell.NameSpace(&H1a&)
Set oFolderItem = oFolder.Self
sConfigFile = oFolderItem.Path & "\IObit\Smart Defrag 2\Config.ini"
Set oFolder = oShell.NameSpace(&H26&)
Set oFolderItem = oFolder.Self
sSmartDefragEXE = chr(34) & oFolderItem.Path & " (x86)\Smart Defrag\SmartDefrag.exe" & chr(34)
Set oShell = Nothing
iArg = WScript.Arguments.Count
If iArg < 1 then
iMethod = Defrag
Else
iMethod = int(WScript.Arguments.Item(0))
If iMethod < Defrag or iMethod > FullyOptimize then
iMethod = Defrag
End If
End If
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTextFile = oFSO.OpenTextFile(sConfigFile, ForReading)
Do Until oTextFile.AtEndOfStream
sNextLine = oTextFile.Readline
iLineFinder = InStr(sNextLine, "DefragType")
If iLineFinder <> 0 Then
sNextLine = "DefragType=" & iMethod
End If
sNewFile = sNewFile & sNextLine & vbCrLf
Loop
oTextFile.Close
Set oTextFile = oFSO.OpenTextFile(sConfigFile, ForWriting)
oTextFile.Write sNewFile
oTextFile.Close
Set oShell = CreateObject("WScript.Shell")
oShell.run sSmartDefragEXE & " /SCHEDULE", 7, True
Set oShell = Nothing
sNewFile = Empty
Set oTextFile = oFSO.OpenTextFile(sConfigFile, ForReading)
Do Until oTextFile.AtEndOfStream
sNextLine = oTextFile.Readline
iLineFinder = InStr(sNextLine, "DefragType")
If iLineFinder <> 0 Then
sNextLine = "DefragType=" & Defrag
End If
sNewFile = sNewFile & sNextLine & vbCrLf
Loop
oTextFile.Close
Set oTextFile = oFSO.OpenTextFile(sConfigFile, ForWriting)
oTextFile.Write sNewFile
oTextFile.Close
Set oFSO = Nothing