XP DOS Commands Help

Post your working scripts, libraries and tools for AHK v1.1 and older
garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

XP DOS Commands Help

13 Feb 2015, 10:20

creates one text-file from DOS help and see command details when click in listbox

Code: Select all

MODIFIED=20150213
;---------------------------------------------
/*
- XP / AHK_L / 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 in EDIT
*/
;---------------------------------------------

autotrim,off
transform,s,chr,32
f1=%a_scriptdir%\doscommands.txt
ifnotexist,%f1%
   runwait,%comspec% /c help >"%f1%",,hide

;-- some commands
e1x =
(Ltrim Join|
help
ver
date /t
time /t
path
ping /?
ping -n 4 -w 1000 www.google.com
netstat
netstat -an
netstat -e -s
ipconfig /?
ipconfig
ipconfig /all

)

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,y2,y,1,3
   if (y="" or y2="   ")
     {
     y=
     y2=
     continue
     }

   c1=
   stringsplit,c,y,%s%
   e1x .= c1 . " /?|"
   }
a=

DetectHiddenWindows On
Run, %ComSpec% /k ,, Hide, pid

WinWait, ahk_pid %pid%
DllCall("AttachConsole", "UInt", pid)
Wsh := ComObjCreate("Wscript.Shell")

;-----------------------------------------
;GUI,2:+AlwaysOnTop
color1=D4D0C8           ;- for EDIT color like msgbox
color2=Black            ;- for TEXT

;Gui,2:Color,Black
Gui,2: Color, ControlColor, %color1%

   ;----------------------------
   Menu,S1,add,DOS-Help       ,MH0
   ;--
   Menu,S2,add,Volume         ,MH1
   Menu,S2,add,Charmap        ,MH1

   ;----------------------------
   menu,myMenuBar,Add,Help     ,:S1
   menu,myMenuBar,Add,Commands ,:S2
   ;----------------------------
   gui,2:menu,MyMenuBar
   ;----------------------------


Gui,2:font,,Fixedsys
Gui,2:add,Listbox,x5   y10   w200  h800 vLB1 c%color2% gExec1,%e1x%
;Gui,2:add,Button ,x5   y820  w100  h25 gTest1,TEST
Gui,2:Show       ,x10  y10   w1000 H850
Gui,2:font,s10,Terminal
;Gui,2:font,s10,Lucida Console
Gui,2:Add,Edit   ,x210 y10  W780  H800 c%color2% vE1,
e1x=
return
;-----------------------------------------------------

test1:
return

exec1:
Gui,2:submit,nohide
GuiControl,2:,E1,
cmdx=%comspec% /c
cmdx:=cmdx
exec  := Wsh.Exec(cmdx . " " . LB1 )
if lb1 contains ping
   goto,exec2

output:= exec.StdOut.ReadAll()
if (lb1="Path")
   loop,parse,output,`;
      {
      exo .= a_loopfield "`n"
      output=%exo%
      }
GuiControl,2:,E1,%output%
output=
exo=
return
;------------------------------

exec2:
while,!Exec.StdOut.AtEndOfStream
{
GuiControlGet,E1
output:=Exec.StdOut.readline()
GuiControl,2:,E1,%e1%`n%output%
}
output=
return
;------------------------------

esc::
2Guiclose:
DllCall("FreeConsole")
Process ,Exist, %pid%
if (ErrorLevel == pid)
    Process, Close, %pid%
exitapp
;------------------------------

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

;========== end script DOS - COMMANDS HELP ===================================
garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Send to DOS / DOS commands help

19 Feb 2018, 16:26

made a little complicated
select directory and send DOS commands

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 ===================================
garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

SEND to DOS

20 Feb 2018, 05:22

this script MoveTogether() is from user 'wolf_II'
https://autohotkey.com/boards/viewtopic ... 02#p199402
WIN-10

Code: Select all

;-modified = 20180220
;-created  = 20180211

;           https://autohotkey.com/boards/viewtopic.php?p=199402#p199402
;-------- https://autohotkey.com/boards/viewtopic.php?t=43192 -------------
;- script moveTogether()                               > from user= Wolf_II

;--------- LISTBOX send selected  commands to DOS --------------------------
;- example : Listbox with attached DOS Window > send commands to DOS
;            drag at Listbox to move both windows
;            close Listbox > also closes DOS/close DOS also thisscript close
;---------------------------------------------------------------------------

#warn
#NoEnv
setworkingdir,%a_scriptdir%
DetectHiddenWindows, ON
SetKeyDelay,2,4
sendmode,input
autotrim,off
transform,s,chr,32

f1=%a_scriptdir%\doscommands2.txt
ifnotexist,%f1%
   runwait,%comspec% /c help >"%f1%",,hide
telnetx=%a_windir%\system32

Handles := []
gosub,crea
k1:=""
k2:=""
;------------ ahk script Listbox --------------------
i=0
x1:=0
y1:=30
w1:=300
h1:=900
h2:=932

   ;- create ahk GUI = Listbox
   Gui,1: New, hwndhwin1, Window 1
   Gui,1:default
   Gui,1:Color,Black
   Gui,1:Color,ControlColor, Black
   Gui,1:Font,s12 cYellow ,Lucida Console

   Menu,S1,add,FolderSelect          ,MH1
   Menu,S2,add,OPEN_Directory        ,MH2

   menu,myMenuBar,Add,Change Directory   ,:S1
   menu,myMenuBar,Add,OPEN Directory     ,:S2
   Gui,1:menu,MyMenuBar

   Gui,1:add,Listbox,x%x1% y%y1% w%w1% h%h1% gLb1 vLbx cYellow,%e1x%
   ;Gui,1:add,Button ,x10 y910 w100 h26 gTest,Test
   Gui,1:Show,       x%x1% y1 w%w1% h%h2%,Drag & Close here

   Handles.Push(hwin1)

;----------- next-attached window > DOS ----------
x3:=(w1+5)
y3:=1
w3:=1220
h3:=(975)

;-- example-1 send to DOS  -----
e4x=
(Ltrim Join&
cd\
dir
telnet telehack.com
)
;Run, %COMSPEC% /k %e4x%,,,pid2       ;- start DOS and send different commands

;--- example-2 -------------------------
title2=AutoHotkey DOS
Run, %COMSPEC% /S /U /Q /E:ON /F:ON /T:0A /k "title %title2% & mode con lines=32048 cols=120&CD %a_desktop%&@echo off&ver&vol&chcp&@echo ======== Hello %a_username% ==================&CD",,,pid2   ; define title / lines / colons / color
;----------------------------
WinWaitActive, ahk_pid %pid2%
sleep,200
WinMove, ahk_pid %pid2%, , x3, y3, w3, h3                     ;- move DOS to the right position
sleep,200
;controlsend,,dir`n,ahk_pid %pid2%                             ;- send another command if needed

IfWinNotActive ,ahk_pid %pid2%,,WinActivate,ahk_pid %pid2%    ;- Activate DOS
  WinWaitActive,ahk_pid %pid2%
sleep,200
Handles.Push(WinExist("A"))                                   ;- DOS is lastactive
MoveTogether(Handles)

settimer,closethisscript,500                                  ;- close this script also if DOS was closed
Return
;-------------------------------------------------------------------------------------------------------------



MH1:
FileSelectFolder,k2, , 3
If k2 =
  return
;ControlSend,%title1%,cd "%k2%"`n,
controlsend,,cd "%k2%"&CD`n,ahk_pid %pid2%
IfWinNotActive ,ahk_pid %pid2%,,WinActivate,ahk_pid %pid2%
  WinWaitActive,ahk_pid %pid2%
return

MH2:
if k2=
{
SplitPath,a_scriptdir, name, dir, ext, name_no_ext, drive
msgbox,%dir%
}
else
run,%k2%
return
;-----------------------------------

;-----------------------------------
closethisscript:
process, exist, %PID2%
 status1 = %ErrorLevel%
if (status1 = 0)          ;- close this ahk-script if PID2 ( DOS ) not exist
  exitapp
return
;-----------------------------------

;-----------------------------------
Guiclose:                                                      ;- when close Listbox-GUI close also attached DOS
WinClose, ahk_pid %pid2%                                       ;- if close only DOS , ahk-script freeze but you can close it
WinWaitClose,ahk_pid %pid2%
exitapp
;------------------------------------

;-----------------------------------
Lb1:                                                           ;- send commands to DOS and let DOS active
Gui,1:submit,nohide
IfWinNotActive ,ahk_pid %pid2%,,WinActivate,ahk_pid %pid2%
  WinWaitActive,ahk_pid %pid2%
k1:=""
k2:=""

;-- case-1 programs -----
stringmid,v1,lbx,1,1
if (v1="#")
 {
 stringsplit,k,lbx,`;,
 if k2<>
    {
    try {
      run,"%k2%"
      } catch {
      msgbox, 262208,ERROR,Not found =%k2%
      }
    return
   }
  else
   {
    stringtrimleft,new,lbx,1
    try {
      run,%new%
      } catch {
      msgbox, 262208,ERROR,Not found =%new%
      }
    return
   }
  return
 }


;-- case-2 Telnet
if lbx contains telnet
 {
 ifexist,%telnetx%
   {
   controlsend,,`n%lbx%`n,ahk_pid %pid2%
   sleep,1500
   controlsend,,geoip`n,ahk_pid %pid2%
   sleep,1000
   controlsend,,cowsay /cow /joke Hello %a_username% `, You like AUTOHOTKEY`r,ahk_pid %pid2%
   return
   }
 else
   msgbox, 262208,ERROR,Not found =%telnetx%
 }

;---- case-3 change directories and open folder ----
if lbx contains % "cd  "
{
stringsplit,k,lbx,`;,
stringmid,str1,k2,1,2
stringmid,str2,k2,1,5
if (str1="::" or str2="Shell")
  {
    try {
      run,"%k2%"
      } catch {
      msgbox, 262208,ERROR,Not found ="%k2%"
      }
  return
  }
if k2<>
 {
 ;setworkingdir,%k2%
 ;controlsend,,`ndir /OGN`n,ahk_pid %pid2%
 controlsend,,`ncd "%k2%"&CD`n,ahk_pid %pid2%
    try {
      run,%k2%
      } catch {
      msgbox, 262208,ERROR,Not found =%k2%
      }
 return
 }
return
}

;--- case-4 k1=text  k2=dos command
stringsplit,k,lbx,`;,
if k2<>
  controlsend,,`n%k2%`n,ahk_pid %pid2%
else
  controlsend,,`n%lbx%`n,ahk_pid %pid2%
return
;==============================================================================

crea:
e1x=
(ltrim join|
telnet telehack.com
#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
cd_Show directory              ;cd
cd /?
dir
dir /?
dir sort by extension          ;dir /OGE
dir sort by name               ;dir /OGN
dir sort by size               ;dir /OGS
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%"
date /t
time /t
graftabl /status
ping /?
ping -n 4 -w 1000 www.google.com
netstat /?
netstat -an
netstat -e -s
ipconfig /?
ipconfig /all
logoff /?
shutdown /?
sfc /?
mem /?
#charmap
#notepad
#calc
#winver

)
sort,e1x,D|

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
   y1=%a_loopfield%
   stringmid,y2,y1,1,3
   if (y1="" or y2="   ")
     {
     y1=
     y2=
     continue
     }

   c1=
   stringsplit,c,y1,%s%
   if (c1="dir" or c1="ver" or c1="path" or c1="chcp")
     e1x .= c1 . "|"
   e1x .= c1 . " /?|"
   }
a=
return
;==============================================================================

;----------- ATTACH from user 'wolf_II' ----------------------------------------
MoveTogether(wParam, lParam = "", _ = "", hWnd = "") { ; using DeferWindowPos
;-------------------------------------------------------------------------------
    ; call MoveTogether(Handles) with an array of handles
    ; to set up a bundle of AHK Gui's that move together
    ;---------------------------------------------------------------------------
    ; https://autohotkey.com/boards/viewtopic.php?p=199402#p199402
    ; version 2018.02.08

    static init := OnMessage(0xA1, "MoveTogether") ; WM_NCLBUTTONDOWN
    static Handles

	If IsObject(wParam)             ; detect a set up call
		Return, Handles := wParam   ; store the array of handles

    If (wParam != 2) ; HTCAPTION
        Return

    ; changing AHK settings here will have no side effects
    CoordMode, Mouse, Screen    ; for MouseGetPos
    SetBatchLines, -1           ; for onMessage
    SetWinDelay, -1             ; for WinActivate, WinMove

    M_old_X := lParam & 0xFFFF, M_old_Y := lParam >> 16 & 0xFFFF
    WinActivate, ahk_id %hWnd%

    Win := {}
    For each, Handle in Handles {
        WinGetPos, X, Y, W, H, ahk_id %Handle%
        Win[Handle] := {X: X, Y: Y, W: W, H: H}
    }

    While GetKeyState("LButton", "P") {
        MouseGetPos, M_new_X, M_new_Y
        dX := M_new_X - M_old_X, M_old_X := M_new_X
      , dY := M_new_Y - M_old_Y, M_old_Y := M_new_Y

        If GetKeyState("Shift", "P")
            WinMove, ahk_id %hWnd%,, Win[hWnd].X += dX, Win[hWnd].Y += dY

        Else { ; DeferWindowPos cycle
            hDWP := DllCall("BeginDeferWindowPos", "Int", Handles.Length(), "Ptr")
            For each, Handle in Handles
                hDWP := DllCall("DeferWindowPos", "Ptr", hDWP
                    , "Ptr", Handle, "Ptr", 0
                    , "Int", Win[Handle].X += dX
                    , "Int", Win[Handle].Y += dY
                    , "Int", Win[Handle].W
                    , "Int", Win[Handle].H
                    , "UInt", 0x214, "Ptr")
            DllCall("EndDeferWindowPos", "Ptr", hDWP)
        }
    }
}
;=================================== END script ====================================
;- for XP 
;cd  ScheduledTasks-CLSID        ;::{d6277990-4c6a-11cf-8d87-00aa0060f5bf}

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 142 guests