Shell

Shell automation module.

Summary
ShellShell automation module.
RestartRestarts shell.
SMShowShow start menu on particular location.
SMAddAdd shortcuts to start menu programs group.
GetCommonPathReturn location of standard system folders.
GetQuickLaunchReturns files from the quick launch location.
SetHook
EGetCountGet the number of items in the view.
EGetIEObjectGet IWebBrowser2 interface pointer from open explorer windows.
GetPathReturns the currently open file system path in the given explorer window.
GetSelectionGet selected item(s)
GetViewGets the current view of desired Explorer window.
ESelectItemSelect item by index.
SetPathOpen the folder in given explorer window
SetViewSets the view in desired Explorer window
ExamplesDisplay info about active Explorer window
About

Restart

Shell_Restart()

Restarts shell.

Remarks

The effect is the same as killing the explorer.exe using task manager and starting it again.  Function will try to prevent execution of start-up group when explorer is started again.

Returns

Pid of the new shell instance.

SMShow

Shell_SMShow(X = "",
Y = "",
Transparency = "",
bHideShadow = 1)

Show start menu on particular location.

Parameters

X, YCoordinate on which to show Start Menu.  Omit both parameters to show the Start Menu on its original location.
TransparencyWindow transparency, by default 255.
bHideShadowHide Start Menu Shadow.  On some systems showing the menu on non-default position will bug up shadow.  Enabled by default.

Remarks

ESC key will not close the window if you used X and Y parameters.  To close the window you can use the following code:

ESC:: WinHide, ahk_class DV2ControlHost

SMAdd

Shell_SMAdd(Parent,  
FileName = "",
o1 = "",
o2 = "",
o3 = "",
o4 = "",
o5 = "",
o6 = "",
o7 = "")

Add shortcuts to start menu programs group.

Parameters

ParentName of the parent folder, relative to the Programs folder.  Specify “!” to add file to the StartUp group.
FileNameName of the file.  If omited, only Parent will be created.  If starts with the “!”, file will be added to the Start Menu for all users.  FileName doesn’t have to exist.
o1..o7Named parameters: Name, WDir, Args, Desc, Icon, Shortcut, IconNumber, RunState.  Those parameters will be passed to FileCrateShortuct.  If Name is not present function will use name of the input file.

GetCommonPath

Shell_GetCommonPath(Name)

Return location of standard system folders.

Parameters

NameName of the sysetem folder.

Folders

Bellow is the list of available folders and their typical locations :

APPDATAC:\Documents and Settings\username\Application Data.
COOKIESC:\Documents and Settings\username\Cookies.
COMMON_APPDATAC:\Documents and Settings\All Users\Application Data.
COMMON_DOCUMENTSC:\Documents and Settings\All Users\Documents.
COMMON_PROGRAMSC:\Documents and Settings\All Users\Start Menu\Programs.
COMMON_STARTMENUC:\Documents and Settings\All Users\Start Menu.
COMMON_STARTUPC:\Documents and Settings\All Users\Start Menu\Programs\Startup.
DESKTOPC:\Documents and Settings\username\Desktop.
FONTSC:\Windows\Fonts.
FAVORITESC:\Documents and Settings\username\Favorites.
LOCAL_APPDATAC:\Documents and Settings\username\Local Settings\Application Data.
MYMUSICC:\Documents and Settings\User\My Documents\My Music.
MYPICTURESC:\Documents and Settings\username\My Documents\My Pictures.
MYVIDEOC:\Documents and Settings\username\My Documents\My Videos.
PERSONALC:\Documents and Settings\username\My Documents.
PROGRAM_FILES_COMMONC:\Program Files\Common.
PROGRAM_FILESC:\Program Files.
PROGRAMSC:\Documents and Settings\username\Start Menu\Programs.
PROFILEC:\Documents and Settings\username.
PROFILESC:\Documents and Settings.
RESOURCESC:\WINDOWS\Resources\ (For theme and other windows resources).
SENDTOC:\Documents and Settings\username\SendTo.
STARTMENUC:\Documents and Settings\username\Start Menu.
STARTUPC:\Documents and Settings\username\Start Menu\Programs\Startup.
SYSTEMC:\Windows\System32.
WINDOWSC:\Windows.

Returns

Full path

Reference

http://msdn.microsoft.com/en-us/library/bb762494(VS.85).aspx

GetQuickLaunch

Shell_GetQuickLaunch()

Returns files from the quick launch location.

SetHook

Shell_SetHook(Handler = "")

Parameter

HandlerName of the function to call on shell events.  Omit to disable the active hook.

Handler

EventEvent for which handler is called.
ParamParameter of the handler.  Parameters are given bellow for each reason.
OnShell(Reason, Param) {
    static WINDOWCREATED=1, WINDOWDESTROYED=2, WINDOWACTIVATED=4, GETMINRECT=5, REDRAW=6, TASKMAN=7, APPCOMMAND=12
}

Param

WINDOWACTIVATEDThe HWND handle of the activated window.
WINDOWREPLACINGThe HWND handle of the window replacing the top-level window.
WINDOWCREATEDThe HWND handle of the window being created.
WINDOWDESTROYEDThe HWND handle of the top-level window being destroyed.
GETMINRECTA pointer to a RECT structure.
TASKMANCan be ignored.
REDRAWThe HWND handle of the window that needs to be redrawn.

Remarks

Requires explorer to be set as a shell in order to work.

Returns

0 on failure, name of the previous hook procedure on success.

Reference

http://msdn.microsoft.com/en-us/library/ms644989(VS.85).aspx

EGetCount

Shell_EGetCount(pHwnd,  
flag = "")

Get the number of items in the view.

Parameters

pHwndHandle to windows explorer instance.
flagset “sel” to get number of selected items.

Returns

Number of items, or -1 on failure.

EGetIEObject

Shell_EGetIEObject(hwndFind = "")

Get IWebBrowser2 interface pointer from open explorer windows.

Parameters

hwndFindReturn interface pointer for instance with given hwnd.

Returns

IWebBrowser2 interface pointer.

GetPath

Shell_EGetPath(pHwnd)

Returns the currently open file system path in the given explorer window.

Parameters

pHwndHandle to windows explorer instance.

Returns

Path of currently open folder.

GetSelection

Shell_EGetSelection(pHwnd)

Get selected item(s)

Parameters

hwndHandle of Explorer window.

Returns

Path of each selected item.

GetView

Shell_EGetView(pHwnd)

Gets the current view of desired Explorer window.

Parameters

pHwndHandle to windows explorer instance.

Returns: View mode type, see SetView

ESelectItem

Shell_ESelectItem(hwnd,  
idx1,  
idx2 = "")

Select item by index.

Parameters

hwndHandle of Explorer window.
idx10 based index of item to select.
idx2All items up to the idx2 will be selected.  Keep in mind that this method selects items 1 by 1 thus selecting large amount of items isn’t efficient.

SetPath

Shell_ESetPath(pHwnd,
pPath)

Open the folder in given explorer window

Parameters

pHwndHandle to windows explorer instance
pPathpath to be set or one of the tree symbols: > (go forward), < (go back), | (go up) Returns: True on success

SetView

Shell_ESetView(pHwnd,
pView)

Sets the view in desired Explorer window

Parameters

pHwndHandle to windows explorer instance.
pViewNumber, view mode type.  ICON (1), SMALLICON (2), LIST (3), DETAILS (4), THUMBNAIL (5), TILE (6), THUMBSTRIP (7)

Examples

Display info about active Explorer window

       h := WinExist("ahk_class ExploreWClass")

       p := "Path: " Shell_GetPath( h )
       s := "Sel:`n" Shell_GetSelection( hwnd)

       msgbox %p%`n%s%
Shell_Restart()
Restarts shell.
Shell_SMShow(X = "",
Y = "",
Transparency = "",
bHideShadow = 1)
Show start menu on particular location.
Shell_SMAdd(Parent,  
FileName = "",
o1 = "",
o2 = "",
o3 = "",
o4 = "",
o5 = "",
o6 = "",
o7 = "")
Add shortcuts to start menu programs group.
Shell_GetCommonPath(Name)
Return location of standard system folders.
Shell_GetQuickLaunch()
Returns files from the quick launch location.
Shell_SetHook(Handler = "")
Shell_EGetCount(pHwnd,  
flag = "")
Get the number of items in the view.
Shell_EGetIEObject(hwndFind = "")
Get IWebBrowser2 interface pointer from open explorer windows.
Shell_EGetPath(pHwnd)
Returns the currently open file system path in the given explorer window.
Shell_EGetSelection(pHwnd)
Get selected item(s)
Shell_EGetView(pHwnd)
Gets the current view of desired Explorer window.
Shell_ESelectItem(hwnd,  
idx1,  
idx2 = "")
Select item by index.
Shell_ESetPath(pHwnd,
pPath)
Open the folder in given explorer window
Shell_ESetView(pHwnd,
pView)
Sets the view in desired Explorer window
Close