Advertisement
Najeebsk

CMD1.ahk

Dec 25th, 2021
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #SingleInstance Force
  2. SetworkingDir, %A_workingdir%
  3. ;- modified = 20210405
  4. ;- created  = 20210324
  5. ;------------------------------------
  6. ;- cmdret user teadrinker / added a GUI with listbox and edit
  7. ;- https://www.autohotkey.com/boards/viewtopic.php?p=392095#p392095                                    / 20210405
  8. ;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=84266&sid=eff012cadb7a851b2c18f5f03b68408f   / 20201210
  9.  
  10. #warn
  11. FileEncoding , UTF-8
  12. ;- https://docs.microsoft.com/en-us/windows/win32/intl/code-page-identifiers
  13. ;- https://docs.microsoft.com/en-au/windows/win32/shell/knownfolderid
  14. ;- https://docs.microsoft.com/en-au/windows/win32/shell/csidl
  15. setworkingdir,%a_scriptdir%
  16. Gui,2:default
  17. ;Gui,2: -Caption +LastFound +AlwaysOnTop
  18. Gui,2: -DPIScale
  19. Gui,2:color,black,black
  20. Gui,2:Font,s12 cYellow,Lucida Console
  21. DetectHiddenWindows On
  22. autotrim,off
  23. transform,s,chr,32
  24. dlm:=";"
  25. e1x:=""
  26. wa:=A_screenwidth,ha:=A_screenHeight,xx:=100
  27. name1:="Najeeb CMD Commands"
  28. global name1
  29. ;- https://ss64.com/nt/chcp.html
  30. CPX:="cp" . DllCall("GetOEMCP", "UInt")                              ;- get CODEPAGE e.g. CP850
  31. fcdm=%a_scriptdir%\doscommands_small_02.txt
  32. ;---------------
  33. gosub,readLB
  34. ;---------------
  35. cmdx=ver
  36. x:=(wa*1)/xx ,y:=(ha*1)/xx,h:=(ha*3.0)/xx,w:=(wa*67)/xx
  37. Gui,2:Add,Edit,x%x%   y%y% w%w% h%h%  vED0 ,%cmdx%                   ;- command
  38. ;---------------------------------------------------------
  39. x:=(wa*68.5)/xx ,y:=(ha*1)/xx,h:=(ha*2.6)/xx,w:=(wa*5)/xx
  40. Gui,2:Add,Button,x%x%   y%y% w%w% h%h%  gA0 default,<RUN              ;- GO
  41. ;---------------------------------------------------------
  42. x:=(wa*74)/xx,y:=(ha*1)/xx,w:=(wa*5.5)/xx,h:=(ha*2.5)/xx
  43. Gui,2: add, Edit, x%x%  y%y% w%w%  h%h% center vED5,                 ;- display "Ended"
  44. ;----------------------- LISTBOX -------------------------
  45. x:=(wa*1)/xx ,y:=(ha*4)/xx,h:=(ha*90)/xx,w:=(wa*10)/xx
  46. Gui,2:Add,Listbox,x%x%   y%y% w%w% h%h%  vLB1 gLB1,%e1x%             ;- Listbox
  47. ;---------------------------------------------------------
  48. x:=(wa*12)/xx,y:=(ha*4)/xx,h:=(ha*90)/xx,w:=(wa*68)/xx      
  49. Gui,2:Add,Edit, x%x%   y%y%  h%h%  w%w% vED1 cYellow,                ;- show "result text"
  50. ;---------------------------------------------------------
  51. x:=(wa*12)/xx,y:=(ha*.1)/xx,h:=(ha*95)/xx,w:=(wa*80)/xx
  52. Gui,2:Show, x%x% y%y% w%w% h%h% ,%name1%
  53. GuiControl,2: Focus,ED0
  54. send,{end}
  55. return
  56. ;----------------------------------------------
  57. 2Guiescape:
  58. 2Guiclose:
  59. exitapp
  60. ;----------------------------------------------
  61. ;=========================================================
  62. AddOutputInGui(output) {
  63.    Control, EditPaste, %output%`r`n, Edit3,%name1%    ;- display output in EDIT ( show "result text" )
  64. }
  65. ;=========================================================
  66. lb1:
  67. gui,2:submit,nohide
  68. h1:=""
  69. h2:=""
  70. stringsplit,h,lb1,%dlm%
  71. if h2<>
  72.   {
  73.   ed0=%h2%
  74.   Guicontrol,2:,ED0,%ed0%
  75.   sleep,500
  76.   gosub,a0a
  77.   }
  78. return
  79. ;--------
  80. A0:
  81. Gui,2:submit,nohide
  82. A0a:
  83. ControlSend,Edit3,======= %ed0% ========`r`n,%name1%
  84. Guicontrol,2:,ED5
  85. ed2a:=comspec . " /c " . ed0
  86. CmdRet(ED2a, Func("AddOutputInGui"),CPX)
  87. gosub,clear
  88. return
  89. ;-------------------------
  90. CLEAR:
  91. Gui,2:submit,nohide
  92. Guicontrol,2:,ED0,
  93. Guicontrol,2:,ED5,ENDED
  94. GuiControl,2: Focus,ED0
  95. return
  96. ;----------------------------------------------
  97. readLB:
  98. Gui,2:submit,node
  99. ;- chcp 1252 West European Latin  DOS_Commands for german help UMLAUT
  100. ifnotexist,%fcdm%
  101.   runwait,%comspec% /c chcp 1252&help >"%fcdm%",,hide
  102. i=0
  103. e1x:=""
  104. ;- add some other commands to variable e1x , example for youtube-dl :
  105. ;- youtube-dl             ;C:\Users\GARRY\Desktop\PROJECT\YT_DL_TEST\youtube-dl.exe https://www.youtube.com/watch?v=G6_DldYj0uQ --verbose --youtube-skip-dash-manifest --write-auto-sub --sub-lang en -o C:\Users\GARRY\Desktop\M_VIDEO\`%(title)s$`%(uploader)s$`%(id)s.`%(ext)s
  106. e1x:="
  107. (Ltrim Join|
  108. version                ;ver
  109. systeminfo             ;systeminfo
  110. CMD-ALL                ;TYPE DATA\CMD.fm            
  111. CMD-COMMAND            ;TYPE DATA\CMD.ls
  112. CMD-ALL2               ;TYPE DATA\ALL.ls
  113. CMD-ATTRIB             ;TYPE DATA\ATTRIB.ls
  114. CMD-COPY               ;TYPE DATA\COPY.ls
  115. CMD-DEL                ;TYPE DATA\DEL.ls
  116. CMD-DIR                ;TYPE DATA\DIR.ls
  117. CMD-FIND               ;TYPE DATA\FIND.ls
  118. CMD-HELP               ;TYPE DATA\HELP.ls
  119. CMD-MD                 ;TYPE DATA\MD.ls
  120. CMD-NET                ;TYPE DATA\NET.ls
  121. CMD-NIR                ;TYPE DATA\NIR.ls
  122. CMD-REN                ;TYPE DATA\REN.ls
  123. CMD-start              ;TYPE DATA\START.ls
  124. youtube-dl update      ;youtube-dl -U      ; TEST youtube-dl must be in a_scriptdir otherwise use fullpath
  125. youtube-dl help        ;youtube-dl --help
  126. netstat -an            ;netstat -an
  127. netstat -e -s          ;netstat -e -s
  128. netstat /?             ;netstat /?
  129. ipconfig /?            ;ipconfig /?
  130. ipconfig               ;ipconfig
  131. ipconfig /all          ;ipconfig /all
  132. dir /P /Q /L /4 /TAWC  ;dir /P /Q /L /4 /TAWC
  133. help                   ;help
  134. date&time              ;date /t&time /t
  135. time /t                ;time /t
  136. RESTORE rstrui         ;rstrui
  137. ping autohotkey 3x     ;ping -n 3 -w 3000 autohotkey.com
  138. ping /?                ;ping /?
  139. =======================;date /t&time /t
  140. "
  141. )
  142. fileread,a,%fcdm%
  143.    loop,parse,a,`n,`r           ;- parse each line
  144.    {
  145.    i++
  146.    if (i<4)                     ;- remove at least the first 3 lines from help
  147.      continue
  148.    y1=%a_loopfield%
  149.    if y1=
  150.      break                      ;- at last line which is empty , then finish
  151.    stringmid,y2,y1,1,3
  152.    if (y1="" or y2="   ")
  153.      {
  154.      y1=
  155.      y2=
  156.      continue
  157.      }
  158.    c1=
  159.    stringsplit,c,y1,%s%
  160.    if (c1="dir" or c1="ver" or c1="path" or c1="chcp")
  161.      e1x .= c1 . "                  " . dlm . c1 . "|"
  162.    e1x .= c1 . " /?                 " . dlm . c1 . " /?|"
  163.    }
  164. a=
  165. return
  166.  
  167. ;========================= function teadrinker 20210405 ==========================================
  168. ;-https://www.autohotkey.com/boards/viewtopic.php?p=392095#p392095
  169. CmdRet(sCmd, callBackFunc := "", encoding := "")
  170. {
  171.    static flags := [HANDLE_FLAG_INHERIT := 0x1, CREATE_NO_WINDOW := 0x8000000], STARTF_USESTDHANDLES := 0x100
  172.  
  173.    (encoding = "" && encoding := "cp" . DllCall("GetOEMCP", "UInt"))
  174.  
  175.    hPipeRead:=""
  176.    hPipeWrite:=""
  177.    sOutput:=""
  178.    DllCall("CreatePipe", "PtrP", hPipeRead, "PtrP", hPipeWrite, "Ptr", 0, "UInt", 0)
  179.    DllCall("SetHandleInformation", "Ptr", hPipeWrite, "UInt", flags[1], "UInt", flags[1])
  180.    
  181.    VarSetCapacity(STARTUPINFO , siSize :=    A_PtrSize*9 + 4*8, 0)
  182.    NumPut(siSize              , STARTUPINFO)
  183.    NumPut(STARTF_USESTDHANDLES, STARTUPINFO, A_PtrSize*4 + 4*7)
  184.    NumPut(hPipeWrite          , STARTUPINFO, siSize - A_PtrSize*2)
  185.    NumPut(hPipeWrite          , STARTUPINFO, siSize - A_PtrSize)
  186.    
  187.    VarSetCapacity(PROCESS_INFORMATION, A_PtrSize*2 + 4*2, 0)
  188.    if !DllCall("CreateProcess", "Ptr", 0, "Str", sCmd, "Ptr", 0, "Ptr", 0, "UInt", true, "UInt", flags[2]
  189.                               , "Ptr", 0, "Ptr", 0, "Ptr", &STARTUPINFO, "Ptr", &PROCESS_INFORMATION)
  190.    {
  191.       DllCall("CloseHandle", "Ptr", hPipeRead)
  192.       DllCall("CloseHandle", "Ptr", hPipeWrite)
  193.       throw "CreateProcess is failed"
  194.    }
  195.    DllCall("CloseHandle", "Ptr", hPipeWrite)
  196.    VarSetCapacity(sTemp, 4096), nSize := 0
  197.    while DllCall("ReadFile", "Ptr", hPipeRead, "Ptr", &sTemp, "UInt", 4096, "UIntP", nSize, "UInt", 0) {
  198.       sOutput .= stdOut := StrGet(&sTemp, nSize, encoding)
  199.       ( callBackFunc && %callBackFunc%(stdOut) )
  200.    }
  201.    DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION))
  202.    DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION, A_PtrSize))
  203.    DllCall("CloseHandle", "Ptr", hPipeRead)
  204.    Return sOutput
  205. }
  206. #R::Reload
  207. #S::Suspend
  208. #P::Pause
  209. ESC::ExitApp
  210. ;================= END SCRIPT ================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement