Jump to content
Sign in to follow this  
JasonDW

Google Desktop Search Shortcut Menu

Recommended Posts

JasonDW

This is my first simple script. It basically adds right-click functionality for Google desktop search for folders.

Currently to get google desktop search to only search a particular directory (must be indexed) you have to type 'under: c:\xxx\xxxx\xxxx searchphrase'

When using network drives that may be very deep and long it is difficult.

It makes use of the 'Window key -G' shortcut for Google desktop search....if that doesn't work on your system then this won't work.

It seems like many people out there would like this functionality and I am all about efficiency.

I am happy to receive comments...it is my first try after all.... :P

NOTE: This makes changes to your registry.

Tested on windows XP SP3.

CODE
#include <File.au3>

#include <Date.au3>

#include <String.au3>

#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#include <Array.au3>

#include <Debug.au3>

; ====================================================================================================

=======================

; Title .........: GSEARCH.au3

; Description....: Add a 'Google Search' to the shortcut menu for a folder.

; When used it copies the folder in the Google Desktop search window.

; Syntax.........: GSEARCH.au3 %1

; Author ........: Jason Webb (jasondweb at gmail dot com)

; Modified.......: 2/23/2009

; Remarks .......: To be implemented as a shortcut menu item (right-click).

; Tested in Windows XP SP3.

; Uses 'Window Key - G' to start desktop search window...there is a chance this may not work on all systems

; Enhancements...:

; - Add ability to set some other search operators

; - currently unable to delete itself on un-install..not sure if there is a way to do this.

; - actually capture the google search window to be sure the text ends up in the right window

;~ ====================================================================================================

=======================

Dim $sInstallPath, $iUserResponse = 1, $sSplashText, $aDBOutput[20], $iLine, $tTSTART

If $cmdline[0] = 0 Then

$sSplashText = "Title .........: GSEARCH.au3" & @CRLF _

& "Description....: Add a 'Google Search' to the shortcut menu for a folder." & @CRLF _

& " It copies the selected folder path into the Google Desktop search window to limit the search." & @CRLF _

& "Syntax.........: GSEARCH.au3 %1" & @CRLF _

& "Author ........: Jason Webb (jasondweb at gmail dot com)" & @CRLF _

& "Modified.......: 2/23/2009" & @CRLF _

& "Remarks .......: To be implemented as a shortcut menu item (right-click)." & @CRLF _

& " Tested in Windows XP SP3." & @CRLF _

& " Uses 'Window Key - G' to start desktop search window...there is a chance this may not work on all systems" & @CRLF _

& " To test hit 'Window Key - G' and confirm that google search comes up" & @CRLF _

& " NOTE: This program adds registry entries. Ensure you understand the implications and have the correct permissions" & @CRLF _

& " " & @CRLF _

& "Installation Instructions:" & @CRLF _

& " Run GSEARCH.exe without arguments" & @CRLF _

& " Click 'Install'" & @CRLF _

& " A new option will be added to the right-click menu on FOLDERS - 'Google Search'." & @CRLF _

& " " & @CRLF _

& " NOTE:- This will only return results for folders that are indexed by google search" & @CRLF _

& " " & @CRLF _

& "" & @CRLF _

& " To Uninstall, find installed location, Run GSEARCH.exe without arguments and click 'Uninstall'" & @CRLF

#Region ### START Koda GUI section ### Form=

$frmSplash = GUICreate("GSEARCH", 900, 400, 193, 125)

$btnOK = GUICtrlCreateButton("OK", 425, 360, 75, 25, $BS_CENTER)

$Label1 = GUICtrlCreateLabel($sSplashText, 16, 16, 868, 340)

GUICtrlSetFont(-1, 9, 400, 0, "Courier New")

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

$tTSTART = _NowCalc()

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE, $btnOK

ExitLoop

EndSwitch

If _DateDiff("s", $tTSTART, _NowCalc()) > 60 Then ExitLoop

WEnd

GUISetState(@SW_HIDE)

#Region ### START Koda GUI section ### Form=H:\Documents\AutoIT\frmGSEARCH.kxf

$frmGSEARCH = GUICreate("GSEARCH Options", 230, 85, 193, 125)

$btnInstall = GUICtrlCreateButton("&Install", 16, 16, 75, 25, 0)

$btnUninstall = GUICtrlCreateButton("&Uninstall", 16, 48, 75, 25, 0)

$btnCancel = GUICtrlCreateButton("&Cancel", 105, 48, 75, 25, 0)

$btnSplash = GUICtrlCreateButton("&Show Startup Text", 105, 16, 105, 25, 0)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ### Exit

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE, $btnCancel

Exit

Case $btnSplash

GUISetState(@SW_HIDE)

GUISwitch($frmSplash)

GUISetState(@SW_SHOW)

$tTSTART = _NowCalc()

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE, $btnOK

ExitLoop

EndSwitch

If _DateDiff('s', $tTSTART, _NowCalc()) > 60 Then ExitLoop

WEnd

GUISetState(@SW_HIDE)

GUISwitch($frmGSEARCH)

GUISetState(@SW_SHOW)

Case $btnInstall

; ask user for installation directory.

; copy this .exe file to install directory

Do

$sInstallPath = FileSelectFolder("Choose folder to install to", "", 1, @WorkingDir)

If $sInstallPath = "" Then Exit

If FileCopy(@ScriptFullPath, $sInstallPath, 1) Then

$aDBOutput[$iLine] = "Created : " & $sInstallPath & "\" & @ScriptName

$iLine += 1

ExitLoop

EndIf

$iUserResponse = MsgBox(5 + 48, "Error", "File could not be installed to : " & $sInstallPath)

Until $iUserResponse <> 4

If $iUserResponse = 2 Then Exit

; confirm registry entries to be added

; add reg entries

If MsgBox(1, "Reg Entries", "Registry entries will now be added to allow access through shortcut (right-click) menu. Menu option '" & "Google Search" & "'") = 2 Then

If MsgBox(4, "Cancel??", "You decided to Cancel the install. Do you want to delete the file @ : " & $sInstallPath & " ?") = 6 Then

FileDelete($sInstallPath)

EndIf

Exit

EndIf

SetError(0)

If RegWrite("HKEY_CLASSES_ROOT\folder\Shell\GSEARCH", "", "REG_SZ", "Google Search") Then

$aDBOutput[$iLine] = "Registry Written : key:HKEY_CLASSES_ROOT\folder\Shell\GSEARCH, value: " & "Google Search"

$iLine += 1

Else

$aDBOutput[$iLine] = "ERROR: Registry write UNSUCCESSFUL : key:HKEY_CLASSES_ROOT\folder\Shell\GSEARCH, value: " & "Google Search"

$iLine += 1

EndIf

If RegWrite("HKEY_CLASSES_ROOT\folder\Shell\GSEARCH\Command", "", "REG_SZ", Chr(34) & $sInstallPath & "\" & @ScriptName & Chr(34) & " " & Chr(34) & "%1" & Chr(34)) Then

$aDBOutput[$iLine] = "Registry Written : key:HKEY_CLASSES_ROOT\Folder\Shell\GSEARCH\Command, value: " & Chr(34) & $sInstallPath & "\" & @ScriptName & Chr(34) & " " & Chr(34) & "%1" & Chr(34)

$iLine += 1

Else

$aDBOutput[$iLine] = "ERROR: Registry write UNSUCCESSFUL : key:HKEY_CLASSES_ROOT\Folder\Shell\GSEARCH\Command, value: " & Chr(34) & $sInstallPath & "\" & @ScriptName & Chr(34) & " " & Chr(34) & "%1" & Chr(34)

$iLine += 1

EndIf

If @error <> 0 Then

MsgBox(0, "Error", "Error writing registry values. See notepad output for information.")

;~ Could set it to reverse installation at this point...

;~ RegDelete("HKEY_CLASSES_ROOT\*\Shell\GSEARCH")

;~ RegDelete("HKEY_CLASSES_ROOT\Folder\Shell\GSEARCH")

;~ FileDelete($sInstallPath)

Exit

EndIf

_DebugSetup("GSEARCH Installation Record")

_DebugOut(_ArrayToString($aDBOutput, @CRLF))

MsgBox(0, "Success", "Installation successfully completed. A file has been created in Notepad. Please save this to record the installion steps" & @CRLF _

& "To Uninstall please run the file " & $sInstallPath & "\" & @ScriptName & " again and click Uninstall")

Exit

Case $btnUninstall

; confirm with user to uninstall

; del .ini if exists

; del reg entries

; msgbox that this .exe must be deleted manually

If MsgBox(4, "Sure?", "Are you sure you want to Uninstall??") = 7 Then Exit

If RegWrite("HKEY_CLASSES_ROOT\folder\Shell\GSEARCH") Then

$aDBOutput[$iLine] = "Registry key (and subkeys) deleted : key:HKEY_CLASSES_ROOT\folder\Shell\GSEARCH"

$iLine += 1

Else

$aDBOutput[$iLine] = "ERROR: Registry key (and subkeys) delete UNSUCCESSFUL : key:HKEY_CLASSES_ROOT\folder\Shell\GSEARCH"

$iLine += 1

EndIf

If FileDelete(@ScriptFullPath) Then

$aDBOutput[$iLine] = "Deleted : " & @ScriptFullPath

$iLine += 1

Else

$aDBOutput[$iLine] = "ERROR: UNABLE to delete : " & @ScriptFullPath

$iLine += 1

EndIf

_DebugSetup("GSEARCH Un-installation Report Record")

_DebugOut(_ArrayToString($aDBOutput, @CRLF))

Exit

EndSwitch

WEnd

EndIf

Send("#g")

Send("Under:" & Chr(34) & $cmdline[1] & Chr(34))

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.