Yashied,
Вы меня опередили. :)
Мой вариант (чуть-чуть отличается):
Код:
#NoTrayIcon
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=icon.ico
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/striponly
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#Obfuscator_Ignore_Funcs= _OpenWith, _WindowsExplorer_ExtractSelectedFiles, _Exit, _RegRun, _RegRunDel, _ScriptDestroy
#include <HotKey.au3>;Yashied, http://autoit-script.ru/index.php/topic,296.0.html
#include <WinAPIEx.au3>;Yashied, http://autoit-script.ru/index.php/topic,47.0.html
#include <File.au3>
Opt('MustDeclareVars', 1)
Global Const $VK_ESCAPE = 0x1B
Global Const $VK_F4 = 0x73
Global $sTitleScript = @ScriptName & '{[/@$@\]}'
If WinExists($sTitleScript) Then Exit
AutoItWinSetTitle($sTitleScript)
;ключи:
If $CmdLine[0] Then
Switch $CmdLine[1]
Case '-RunYes' ;поместить в автозагрузку текущего пользователя
_RegRun()
Case '-RunNo' ;удалить из автозагрузки текущего пользователя
_RegRunDel()
Case '-Del' ;удалить утилиту
_RegRunDel()
_ScriptDestroy()
EndSwitch
EndIf
_HotKeyAssign($VK_F4, '_OpenWith', $HK_FLAG_DEFAULT, '[REGEXPCLASS:(Explore|Cabinet)WClass]');F4
_HotKeyAssign(BitOR($CK_CONTROL, $CK_SHIFT, $VK_ESCAPE), '_Exit');Ctrl+Shift+Esc - выход
_WinAPI_EmptyWorkingSet()
While 1
Sleep(10)
WEnd
Func _Exit()
Exit
EndFunc ;==>_Exit
Func _OpenWith()
Local $h_Win_Handle, $a_List_Active, $s_Program = @WindowsDir & '\notepad.exe'
$h_Win_Handle = WinGetHandle('[ACTIVE]')
$a_List_Active = _WindowsExplorer_ExtractSelectedFiles($h_Win_Handle)
If Not @error And $a_List_Active[0] Then
For $i = 1 To $a_List_Active[0]
Run($s_Program & ' "' & $a_List_Active[$i] & '"')
Next
Else
_WinAPI_MessageBeep(2)
EndIf
_WinAPI_EmptyWorkingSet()
EndFunc ;==>_OpenWith
;trancexx, http://www.autoitscript.com/forum/topic/89833-windows-explorer-current-folder/page__view__findpost__p__875866
Func _WindowsExplorer_ExtractSelectedFiles($h_Wnd, $o_Error = 0)
Local $a_ExplorerSelectedFiles[1] = [0], $a_WinList, $f_ErrorHandling, $o_ShellApp, $o_ShellApp_Windows, _
$i_ShellApp_Inst_SelectedItems_Count, $o_ShellApp_Inst_SelectedItems, $i_Counter, $s_Path_Selected, _
$s_Attrib_Selected
If Not IsHWnd($h_Wnd) Then Return SetError(1, 0, $a_ExplorerSelectedFiles)
$a_WinList = WinList('[REGEXPCLASS:(Explore|Cabinet)WClass]')
While 1
For $i = 1 To UBound($a_WinList) - 1
If $h_Wnd = $a_WinList[$i][1] Then ExitLoop 2
Next
Return SetError(2, 0, $a_ExplorerSelectedFiles)
WEnd
If Not IsObj($o_Error) And Not ObjEvent('AutoIt.Error') Then $o_Error = ObjEvent('AutoIt.Error', '_WindowsExplorer_ExtractSelectedFiles')
If IsObj($o_Error) Then $f_ErrorHandling = True
$o_ShellApp = ObjCreate('Shell.Application')
If Not IsObj($o_ShellApp) Then Return SetError(3, 0, $a_ExplorerSelectedFiles)
$o_ShellApp_Windows = $o_ShellApp.Windows()
If Not IsObj($o_ShellApp_Windows) Then Return SetError(4, 0, $a_ExplorerSelectedFiles)
For $o_ShellApp_Inst In $o_ShellApp_Windows
If $o_ShellApp_Inst.hwnd = $h_Wnd Then ExitLoop
Next
$i_ShellApp_Inst_SelectedItems_Count = $o_ShellApp_Inst.Document.SelectedItems.Count
If $f_ErrorHandling And $o_Error.number Then Return SetError(5, 0, $a_ExplorerSelectedFiles)
$o_ShellApp_Inst_SelectedItems = $o_ShellApp_Inst.Document.SelectedItems
If $f_ErrorHandling And $o_Error.number Then Return SetError(6, 0, $a_ExplorerSelectedFiles)
For $o_ShellApp_Inst_SelectedItem In $o_ShellApp_Inst_SelectedItems
$s_Path_Selected = $o_ShellApp_Inst_SelectedItem.path
If $f_ErrorHandling And $o_Error.number Then Return SetError(7, 0, $a_ExplorerSelectedFiles)
$s_Attrib_Selected = FileGetAttrib($s_Path_Selected)
If Not StringInStr($s_Attrib_Selected, 'D') Then
$i_Counter += 1
ReDim $a_ExplorerSelectedFiles[$i_Counter + 1]
$a_ExplorerSelectedFiles[$i_Counter] = $s_Path_Selected
$a_ExplorerSelectedFiles[0] = $i_Counter
EndIf
Next
Return SetError(0, 0, $a_ExplorerSelectedFiles)
EndFunc ;==>_WindowsExplorer_ExtractSelectedFiles
Func _RegRun()
Local $s_RegRun = 'HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
If RegRead($s_RegRun, @ScriptName) = '' Or RegRead($s_RegRun, @ScriptName) <> '"' & @ScriptFullPath & '"' Then
RegWrite($s_RegRun, @ScriptName, 'REG_SZ', '"' & @ScriptFullPath & '"')
EndIf
EndFunc ;==>_RegRun
Func _RegRunDel()
Local $s_RegRun = 'HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
RegDelete($s_RegRun, @ScriptName)
EndFunc ;==>_RegRunDel
Func _ScriptDestroy()
Local $s_Temp, $s_Path, $s_Temp, $s_Text_Del, $h_File
$s_Temp = _TempFile(@TempDir, '~', '.bat')
$s_Path = FileGetShortName(@ScriptFullPath)
$s_Text_Del = '@echo off' & @CRLF & ':loop' & @CRLF & 'del ' & $s_Path & @CRLF & 'if exist ' & _
$s_Path & ' goto loop' & @CRLF & 'del ' & $s_Temp
$h_File = FileOpen($s_Temp, 2)
FileWrite($h_File, $s_Text_Del)
FileClose($h_File)
Run($s_Temp, '', @SW_HIDE)
Exit
EndFunc ;==>_ScriptDestroy
|