Code: Select all
;-------- http://ahkscript.org/boards/viewtopic.php?f=6&t=6396 ---
;- see script MoveTogether() from user 'wolf_II'
; attach a DOS-Window to ahk_script
; https://autohotkey.com/boards/viewtopic.php?f=6&t=43192
;- MODIFIED=20180219
;- Created =20150213
;---------------------------------------------
/*
- send DOS-command to LV/EDIT by Input-Edit or select by Listbox
- XP / WIN-10 AHK / DOS COMMANDS HELP
- this script creates one DOS-HELP -file
- see in Listbox the DOS commands like this = CD /?
- click on DOS-COMMAND > see details
- if use DIR can click on file/folder to open it
*/
;---------------------------------------------
filename1=DOS_COMMANDS
autotrim,off
transform,s,chr,32
transform,q,chr,34
f1=%a_scriptdir%\doscommands.txt
ifnotexist,%f1%
runwait,%comspec% /c help >"%f1%",,hide
;notespadx=%a_windir%\notespad.exe
notespadx=%a_programfiles%\IDM Computer Solutions\UltraEdit-32\uedit32.exe
gosub,CREA ;- <<< gosub create DOS commands in Listbox
;--------- ATTACH-DOS --------------------
DetectHiddenWindows On
;Run, %COMSPEC% /T:0A /k "title %title2% & mode con lines=32048 cols=120&CD\&@echo off",,,pid2 ; define title / lines / colons / color
Run, %ComSpec% /k "@echo off",,hide, pid
WinWait, ahk_pid %pid%
DllCall("AttachConsole", "UInt", pid)
Wsh := ComObjCreate("Wscript.Shell")
cmdx := comspec . " /c"
;-----------------------------------------
;-----------------------------------------
Gui,2:default
Gui,2:Color,Black
Gui,2:Color,ControlColor, Black
Gui,2:Font,s12 cYellow norm ,Lucida Console
RSSINI=%A_scriptdir%\%filename1%_INI.ini
ifnotexist,%rssini%
{
IniWrite,%a_scriptdir% , %rssini% ,Dir1 , Directory
IniWrite,%a_desktop% , %rssini% ,Dir2 , Directory
}
IniRead , path1 , %rssini% ,Dir1 , Directory
IniRead , path2 , %rssini% ,Dir2 , Directory
;----------------------------
Menu,S0,add,DOS-Help ,MH0
;--
Menu,S1,add,Volume ,MH1
Menu,S1,add,Charmap ,MH1
Menu,S3,add,EDIT_ThisScript,MH3
Menu,S4,add,CD_Desktop ,MH4
Menu,S5,add,CD_Dir1 ,MH5
Menu,S6,add,CD_Dir2 ,MH6
Menu, aaaa, Add, DIR-1 , 1B ;- 1submenuA-1
Menu, aaaa, Add, DIR-2 , 2B ;- 1submenuA-2
;----------------------
Menu, MyMenuBar, Add,SELECT-DIR, :aaaa ;- 1MAIN-A
;----------------------------
menu,myMenuBar,Add,Help ,:S0
menu,myMenuBar,Add,Commands ,:S1
menu,myMenuBar,Add,ThisScript ,:S3
menu,myMenuBar,Add,CD_Desktop ,:S4
menu,myMenuBar,Add,CD_Dir1 ,:S5
menu,myMenuBar,Add,CD_Dir2 ,:S6
;----------------------------
gui,2:menu,MyMenuBar
;----------------------------
Gui,2:Show ,x10 y10 w1400 H850 , %filename1%
Gui,2:add,text,x0 y0 w0 h0 T12 ;- empty for focus
Gui,2:add,Edit ,x5 y3 w240 h28 vEd1 -hscroll ,dir ;- type in a DOS command
Gui,2:add,button ,x0 y0 w0 h0 gExec0 default ,<GO ;- default button to run
Gui,2:add,button ,x247 y3 w30 h25 gBack ,<< ;- directory one path back
Gui,2:add,Edit ,x280 y5 w1040 h26 vEd2 ;- show directory
Gui,2:add,button ,x1325 y5 w70 h25 gFolder ,OPEN ;- open directory
Gui,2:add,Listbox,x5 y40 w250 h803 vLB1 gExec1,%e1x% ;- select DOS command
e1x=
;Gui,2:font,s10 norm ,Terminal ;- font terminal to show the correct ASCII characters
Gui,2:font,s12 norm,Lucida Console
Gui,2:Add,Listview ,x260 y40 w1140 h800 BackgroundBlack +altsubmit vLV1 gMlv -hdr,Column1 ;- show result
LV_ModifyCol(1,1120)
Guicontrol,2:Focus,T12
GuiControl,2:,Ed2,%path1%
;gosub,commanddir
gosub,start
return
;============================================================================================
;-------- CLOSE ------------------------
esc::
2Guiclose:
Gui,2:submit,nohide
IniWrite,%ed2%,%rssini%,Dir1,Directory
DllCall("FreeConsole")
Process ,Exist, %pid%
if (ErrorLevel == pid)
Process, Close, %pid%
exitapp
;--------------------------------------
;============ START ==================
start:
Gui,2:submit,nohide
setworkingdir,%Ed2%
lb1:="@echo off&ver&vol&chcp&@echo ======== Hello = " . a_username . " ==================&@echo -------- Autohotkey-DOS -------&CD&date /t&time /t"
exec := Wsh.Exec(cmdx . " " . LB1)
output:= exec.StdOut.ReadAll()
Gui,2: ListView,lv1
LV_Delete()
Loop,parse,output,`n,`r
{
x:= a_loopfield
LV_Add("",x)
}
LV_Add("","==========================================================")
LV_Modify(LV_GetCount(), "Vis") ;-- scrolls to last line
return
;=======================================
;--------- DIRECTORY -------------------
;====== back & commanddir ===============
back:
Gui,2:submit,nohide
e=
StringSplit,CX,ed2,`\
C:=(CX0-1)
if (c=0)
return
loop,%c%
E =% E . CX%A_Index% . "\"
stringtrimright,e,e,1
GuiControl,2:,Ed2,%e%
e=
;-------------------------------------
commanddir:
Gui,2:submit,nohide
setworkingdir,%Ed2%
lb1:="dir"
exec := Wsh.Exec(cmdx . " " . LB1)
output:= exec.StdOut.ReadAll()
Gui,2: ListView,lv1
;LV_Delete()
Loop,parse,output,`n,`r
{
x:= a_loopfield
LV_Add("",x)
}
LV_Add("","==========================================================")
LV_Modify(LV_GetCount(), "Vis") ;-- scrolls to last line
return
;======================================
;============ EXEC ====================
exec0:
Gui,2:submit,nohide
lb1=%ed1%
goto,cont
;--------------------------------------
exec1:
Gui,2:submit,nohide
;--------------------------------------
cont:
;if lb1 contains type edit this script
; {
; GuiControl,2:,Ed2,%a_scriptdir%
; return
; }
k1:=""
k2:=""
;-- case-1 programs -----
;----- run direct --------------------------
GuiControl,2:,E1,
stringmid,v1,lb1,1,1
if (v1="#")
{
stringsplit,k,lb1,`;,
if k2<>
{
try {
run,"%k2%"
} catch {
erl:= errorlevel
msgbox, 262208,ERROR,Not found =%lb1%`nERROR=%erl%
}
return
}
else
{
stringtrimleft,new,lb1,1
try {
run,%new%
} catch {
erl:= errorlevel
msgbox, 262208,ERROR,Not found =%lb1%`nERROR=%erl%
}
return
}
return
}
;------ change directories and open folder ----
if lb1 contains % "cd "
{
stringsplit,k,lb1,`;,
stringmid,str1,k2,1,2
if (str1="::")
{
run, "%k2%"
return
}
if k2<>
{
GuiControl,2:,Ed2,%k2%
gosub,commanddir
run,%k2%
return
}
GuiControl,2:,Ed2,%k2%
gosub,commanddir
;controlsend,,`ndir`n,ahk_pid %pid2%
return
}
stringmid,lb1e,lb1,1,3
if (lb1e="cd\")
{
stringsplit,h,lb1,`"
GuiControl,2:,Ed2,C:\
gosub,commanddir
return
}
;---------------------------------------------
;=============================================
exec := Wsh.Exec(cmdx . " " . LB1 )
;=============================================
if lb1 contains ping
goto,exec2 ; << goto
if lb1 contains type edit this script
GuiControl,2:,Ed2,%a_scriptdir%
;----- CASE-1 -----------------
output:= exec.StdOut.ReadAll()
;------------------------------
if (lb1="Path")
loop,parse,output,`;
{
exo .= a_loopfield "`n"
output=%exo%
}
Gui,2: ListView,lv1
;LV_Delete()
LV_Add("","================= " . lb1 . " =========================================")
Loop,parse,output,`n,`r
{
x:= a_loopfield
if (x="")
continue
LV_Add("",x)
}
LV_Add("","==========================================================")
;if (lb1="dir")
LV_Modify(LV_GetCount(), "Vis") ;-- scrolls to last line
output=
exo=
return
;------------------------------
;------- CASE-2 ---------------
exec2:
Gui,2: ListView,lv1
;LV_Delete()
while,!Exec.StdOut.AtEndOfStream
{
GuiControlGet,E1
;------------------------------
output:=Exec.StdOut.readline()
;------------------------------
Loop,parse,output,`n,`r
{
x:= a_loopfield
LV_Add("",x)
}
LV_Modify(LV_GetCount(), "Vis") ;-- scrolls to last line
}
output=
return
;======================================
;========== LISTVIEW ==================
mlv:
Gui,2:default
Gui,2: Submit, NoHide
Gui,2:ListView, LV1
Extx:= "ahk,ahl,log,bat,bas,ini,xml,htm,html" ;- maybe run with notepad / rightclick
if A_GuiEvent = Normal
{
LV_Gettext(C1,A_eventinfo,1)
SplitPath,C1,name, dir, ext, name_no_ext, drive
stringtrimleft,c1a,c1,36
cmdy=%ed2%\%c1a%
if c1 contains <DIR>
{
setworkingdir,%cmdy%
GuiControl,2:,Ed2,%cmdy%
gosub,commanddir
run,%cmdy%
return
}
if ext<>
{
stringlen,L1,ext
stringmid,sm,cmdy,2,2
if (sm=":\" and l1<5)
{
text1=Want you RUN this FILE (?) =
gosub,msgbox1
return
}
}
msgbox, 262208,LV_C1 ,Column1=`n%c1%
}
if A_GuiEvent = Rightclick
{
LV_Gettext(C1,A_eventinfo,1)
SplitPath,C1,name, dir, ext, name_no_ext, drive
stringtrimleft,c1a,c1,36
cmdy=%ed2%\%c1a%
if ext in %Extx%
{
msgbox, 262436,Notepad ,Want you OPEN this FILE with NOTEPAD ?`n%cmdy%
ifmsgbox,no
return
run,notepad "%cmdy%
return
}
}
return
;--------------------------------------
;=========== MENU ================================
MH0:
if A_thisMenuItem=DOS-Help
run,hh.exe ms-its:Help\ntcmds.chm::/ntcmds.htm
return
;--------------------------------------
;------------------------------------------------------------------
MH1:
if A_thisMenuItem=Volume
{
run,sndvol32
run,sndvol32 /rec
CN=RunDLL32.EXE shell32.dll,Control_RunDLL mmsys.cpl,,1
run,%CN%
}
if A_thisMenuItem=Charmap
run,charmap
return
;--------------------------------------
;--------------------------------------
mh3:
if (a_osversion="WIN_XP")
{
ifexist,%notespadx%
run, %notespadx% "%a_scriptfullpath%"
}
else
run, notepad "%a_scriptfullpath%"
return
;--------------------------------------
;=========== MSGBOX =====================================
msgbox1:
Gui,2:submit,nohide
Gui,3: +AlwaysOnTop
Gui,3: Color, Black
Gui,3: Margin, 0, 0
Gui,3: font,s12 norm,Lucida Console
Gui,3: Add, Text , x5 y5 cYellow ,%text1%
Gui,3: Add, Text , x5 y30 cGray ,%cmdy%
Gui,3: font,cBlack,Fixedsys
Gui,3:Add,Progress, x10 y55 w70 h22 Disabled BackgroundBlue
Gui,3:Add,Text, xp yp wp hp cYellow BackgroundTrans Center 0x200 gNo1,NO ;- color button
Gui,3:Add,Progress, x100 y55 w70 h22 Disabled BackgroundRed
Gui,3:Add,Text, xp yp wp hp cBlack BackgroundTrans Center 0x200 gOk1,RUN
if ext in %extx%
{ ;- ( ahk,log,bat,bas .... maybe can run with notepad )
Gui,3:Add,Progress, x200 y55 w200 h22 Disabled BackgroundGray
Gui,3:Add,Text, xp yp wp hp cBlack BackgroundTrans Center 0x200 gRunNotepad ,Run with NOTEPAD
}
Gui,3: Show,center h90,Msgbox
Return
RunNotepad:
Gui,3:submit,nohide
if (a_osversion="WIN_XP")
{
ifexist,%notespadx%
run, %notespadx% "%cmdy%"
}
else
run,notepad "%cmdy%"
goto,end
return
OK1:
Gui,3:submit,nohide
run,%cmdy%
goto,end
return
3Guiclose:
no1:
end:
Gui,3:destroy
Return
;===================== END MSGBOX ============
;---- MENU Directories ----------------
;----- Select-Folder ------------------
1B:
FileSelectFolder,dirc, , 3
If dirc =
return
setworkingdir,%dirc%
GuiControl,2:,Ed2,%dirc%
IniWrite,%dirc%,%rssini%,Dir1,Directory
gosub,commanddir
return
;--------------------------------------
;----- Select-Folder ------------------
2B:
FileSelectFolder,dirc, , 3
If dirc =
return
IniWrite,%dirc%,%rssini%,Dir2,Directory
return
;--------------------------------------
MH4:
GuiControl,2:,Ed2,%a_desktop%
gosub,commanddir
return
MH5:
IniRead , path1 , %rssini% ,Dir1 , Directory
GuiControl,2:,Ed2,%path1%
gosub,commanddir
return
MH6:
IniRead , path2 , %rssini% ,Dir2 , Directory
GuiControl,2:,Ed2,%path2%
gosub,commanddir
return
folder:
Gui,2:submit,nohide
run,%ed2%
return
;----------------------------------------
;================== create DOS commands ===============================
CREA:
;- telnet telehack.com / not works can't open a second cmd.exe
;- some commands / rest from %comspec% /c help >"%f1%" / cmd /?
e1x=
(ltrim join|
#Thunderbird ;%a_programfiles%\Mozilla Thunderbird\thunderbird.exe
cd
cd MyDocuments ;%a_mydocuments%
cd Desktop ;%A_desktop%
cd MyComputer-CLSID ;::{20d04fe0-3aea-1069-a2d8-08002b30309d}
cd MyNetworkPlaces-CLSID ;::{208d2c60-3aea-1069-a2d7-08002b30309d}
cd NetworkConnections-CLSID ;::{7007acc7-3202-11d1-aad2-00805fc1270e}
cd Printers-CLSID ;::{2227a280-3aea-1069-a2de-08002b30309d}
cd RecycleBin-CLSID ;::{645ff040-5081-101b-9f08-00aa002f954e}
cd AdminTools-CLSID ;Shell:::{d20ea4e1-3957-11d2-a40b-0c5020524153}
cd Appdata ;%a_appdata%
cd Appdatacommon ;%a_appdatacommon%
cd Programfiles ;%a_programfiles%
cd Programs ;%a_programs%
cd ProgramsCommon ;%a_programsCommon%
cd StartMenu ;%a_StartMenu%
cd StartMenuCommon ;%a_StartMenuCommon%
cd Startup ;%a_Startup%
cd StartupCommon ;%a_StartupCommon%
cd Windows ;%a_windir%
cd Temp ;%a_temp%
cd WorkingDir ;%a_workingdir%
cd ScriptDir ;%a_scriptdir%
cd\ goto C:\ ;cd\
cd /?
dir /OGN
dir /?
dir sort by extension ;echo sort by extension&dir /OGE&echo =========================================
dir sort by name ;echo sort by name&dir /OGN&echo =========================================
dir sort by size ;echo sort by size&dir /OGS&echo =========================================
dir sort by DateCreated ;echo sort by DateCreated&dir /OGD /TC&echo =========================================
dir sort by DateModified ;echo sort by DateModified&dir /OGD /TW&echo =========================================
dir sort by DateLastView ;echo sort by DateLastViewed&dir /OGD /TA&echo =========================================
cmd /?
vol
help
type edit this script ;type "%a_scriptfullpath%"&cd %a_scriptdir%
date /t
time /t
graftabl /status
ping /?
ping -n 4 -w 1000 www.google.com
netstat -an
netstat -e -s
ipconfig /?
ipconfig /all
shutdown /?
mem /?
mem
#charmap
#notepad
#calc
#winver
)
sort,e1x,D|
;- add to e1x from %comspec% /c help >"%f1%" add /?
i=0
fileread,a,%f1% ;- textfile is in variable A
loop,parse,a,`n,`r ;- parse each line
{
i++
if (i<3) ;- remove at least the first two lines from help
continue
y=%a_loopfield%
stringmid,kk,y,1,5
if (kk="Label") ;- maybe remove some dangerous commands
continue
stringmid,y2,y,1,3
if (y="" or y2=" ")
{
y=
y2=
continue
}
c1=
stringsplit,c,y,%s%
if (c1="dir" or c1="ver" or c1="path" or c1="chcp")
e1x .= c1 . "|"
e1x .= c1 . " /?|" ;- add '/?' to each command as help
}
a=
return
;========== end script DOS - COMMANDS HELP ===================================