#NoTrayIcon
#include <Array.au3>
#include <WinAPI.au3>
If $CmdLine[0] <> 0 Then
If UBound(ProcessList('Copy_path.exe')) > 2 Then Exit
_Selected()
Else
If RegRead('HKCR\*\shell\Действия с файлами\command', '') = '' Then
If MsgBox(32 + 1, '', 'Добавить пункт в контекстное меню?') = 2 Then Exit
RegWrite('HKCR\*\shell\Действия с файлами\command', '', 'REG_SZ', @ScriptDir & '\Copy_path.exe "%1"')
Else
If MsgBox(32 + 1, '', 'Удалить пункт из контекстного меню?') = 2 Then Exit
RegDelete('HKCR\*\shell\Действия с файлами')
EndIf
EndIf
Func _Selected()
Local $hWnd = _WinAPI_GetForegroundWindow()
$class = _WinAPI_GetClassName($hWnd)
If $class = 'CabinetWClass' Then
$aSelection = _WindowsExplorer_ExtractSelectedDirAndFiles($hWnd)
_ArrayDisplay($aSelection)
EndIf
EndFunc
Func _WindowsExplorer_ExtractSelectedDirAndFiles($hWnd)
Local $aExplorerSelectedFiles[2] = [0, ""]
If Not IsHWnd($hWnd) Then Return SetError(1, 0, $aExplorerSelectedFiles)
Local $aWinList = WinList("[REGEXPCLASS:(Explore|Cabinet)WClass]")
While 1
For $i = 1 To UBound($aWinList) - 1
If $hWnd = $aWinList[$i][1] Then ExitLoop 2
Next
Return SetError(2, 0, $aExplorerSelectedFiles)
WEnd
Local $oShellApp = ObjCreate("Shell.Application")
If Not IsObj($oShellApp) Then Return SetError(3, 0, $aExplorerSelectedFiles)
Local $oShellApp_Windows = $oShellApp.Windows()
If Not IsObj($oShellApp_Windows) Then Return SetError(4, 0, $aExplorerSelectedFiles)
For $oShellApp_Inst In $oShellApp_Windows
If $oShellApp_Inst.hwnd = $hWnd Then ExitLoop
Next
Local $oShellApp_Inst_SelectedItems_Count = $oShellApp_Inst.document.SelectedItems.Count
Local $oShellApp_Inst_LocationURL = $oShellApp_Inst.LocationURL
Local $aHexCodes = StringRegExp($oShellApp_Inst_LocationURL, '%([[:xdigit:]]{2})', 3)
If Not @error Then
$oShellApp_Inst_LocationURL = StringRegExpReplace($oShellApp_Inst_LocationURL, '%([[:xdigit:]]{2})', ';')
For $i = 0 To UBound($aHexCodes) - 1
$oShellApp_Inst_LocationURL = StringReplace($oShellApp_Inst_LocationURL, ';', ChrW('0x' & $aHexCodes[$i]), 1)
Next
EndIf
$oShellApp_Inst_LocationURL = StringReplace($oShellApp_Inst_LocationURL, 'file:///', '')
$aExplorerSelectedFiles[0] = $oShellApp_Inst_SelectedItems_Count
$aExplorerSelectedFiles[1] = StringReplace($oShellApp_Inst_LocationURL, '/', '\')
ReDim $aExplorerSelectedFiles[$aExplorerSelectedFiles[0] + 2]
$oShellApp_Inst_SelectedItems = $oShellApp_Inst.document.SelectedItems
Local $iCounter = 2
For $oShellApp_Inst_SelectedItem In $oShellApp_Inst_SelectedItems
$aExplorerSelectedFiles[$iCounter] = $oShellApp_Inst_SelectedItem.path
$iCounter += 1
Next
$oShellApp = 0
$oShellApp_Windows = 0
Return $aExplorerSelectedFiles
EndFunc