Jump to content

AutoIT script help


Mekrel

Recommended Posts

Hi all

I have made a simple but nice AutoIT script which searches for my fixed drives and uses the drive letters it returns with Diskeeper via command line to defrag all my hard drives.

The script is compiled and I would like a control panel link to run this script. Which I know how to do.

Im trying to make the placement of the compiled script into system32, and the adding of the control panel unattended using a reg file to add the link to control panel.

Doing this needs a free generated GUID which I can get from MS's guid generator. Being as its unattended, I need a new guid each time in case others change during different reformats.

So using Autoit im making guid.exe generate one and paste to the clipboard and then autoit to write the reg file.

I have most of this done, however im getting line breaks where I do not want them :no:

Here is my script:

; Run the GUID APP
Run(@ScriptDir & "\GUIDGEN.EXE")

; Wait for the APP to launch and ready to send Commands to
WinWait("Create GUID", 'Choose the desired format below, then select "Copy" to copy the results to the clipboard (the results can then be pasted into your source code).')

; Select Registry GUID generation by check box
ControlCommand("Create GUID", 'Choose the desired format below, then select "Copy" to copy the results to the clipboard (the results can then be pasted into your source code).', "Button5", "Check", "")

; Create a new GUID
ControlClick("Create GUID", 'Choose the desired format below, then select "Copy" to copy the results to the clipboard (the results can then be pasted into your source code).', "Button8", "left", "1")

; Copy the new GUID to clipboard
ControlClick("Create GUID", 'Choose the desired format below, then select "Copy" to copy the results to the clipboard (the results can then be pasted into your source code).', "Button7", "left", "1")

; Exit the program
ControlClick("Create GUID", 'Choose the desired format below, then select "Copy" to copy the results to the clipboard (the results can then be pasted into your source code).', "Button9", "left", "1")

$file = FileOpen(@ScriptDir & "\CP.reg", 1)

; Check if file opened for writing OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf

$bak = ClipGet()
FileWrite($file, "Windows Registry Editor Version 5.00" & @CRLF)
FileWrite($file, "" & @CRLF)
FileWrite($file, "[HKEY_CLASSES_ROOT\CLSID\" & $bak & "]" & @CRLF)
FileWrite($file, '@="nFrag"' & @CRLF)
FileWrite($file, '"InfoTip"="Runs a System Wide defragmentation"' & @CRLF)
FileWrite($file, "[HKEY_CLASSES_ROOT\CLSID\" & $bak & "\DefaultIcon]" & @CRLF)
FileWrite($file, '@="%SystemRoot%\\\\System32\\\\nFrag.exe,0"' & @CRLF)
FileWrite($file, "[HKEY_CLASSES_ROOT\CLSID\" & $bak & "\Shell\Open]" & @CRLF)
FileWrite($file, "[HKEY_CLASSES_ROOT\CLSID\" & $bak & "\Shell\Open\command]" & @CRLF)
FileWrite($file, '@="nFrag.exe"' & @CRLF)
FileWrite($file, "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel\NameSpace\" & $bak & "]" & @CRLF)
FileWrite($file, '@="nFrag Defragmenter"' & @CRLF)
FileClose($file)

and it produces:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\CLSID\{5816954A-C354-4644-82D5-3E673DAAB415}
]
@="nFrag"
"InfoTip"="Runs a System Wide defragmentation"
[HKEY_CLASSES_ROOT\CLSID\{5816954A-C354-4644-82D5-3E673DAAB415}
\DefaultIcon]
@="%SystemRoot%\\\\System32\\\\nFrag.exe,0"
[HKEY_CLASSES_ROOT\CLSID\{5816954A-C354-4644-82D5-3E673DAAB415}
\Shell\Open]
[HKEY_CLASSES_ROOT\CLSID\{5816954A-C354-4644-82D5-3E673DAAB415}
\Shell\Open\command]
@="nFrag.exe"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel\NameSpace\{5816954A-C354-4644-82D5-3E673DAAB415}
]
@="nFrag Defragmenter"

Notice where the guid is placed {xxxxxxxxx..etc} there is a unwanted line break.

I cant seem to see what is causing this? any assistance would be greatly appreciated :)

(nologic, your never on msn when I need you :whistle::lol: )

Link to comment
Share on other sites


Not sure what's causing it either, but here's a workaround... Trim the crlf from the string returned by clipget()

$bak = ClipGet()
$bak = stringleft($bak,stringlen($bak)-2)

EDIT- Ya beat me to it. Glad you sorted it out. Yeah, needs both cr and lf trimmed.

Edited by dman
Link to comment
Share on other sites

Thanks anyway mate :)

but your code is abit more neat. Only just started to dab into AutoIT and I need to refine alot of my code sometimes as it can be neater / more efficient.

Just like when I learnt CSS and XHTML :P

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...