Advertisement
Najeebsk

NAJEEB-CMD.ahk

Apr 15th, 2023
1,548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #SingleInstance Force
  2. SetworkingDir, %A_workingdir%
  3. ;#warn
  4. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  5. FileCreateDir, %A_ScriptDir%\DATA
  6. FileInstall , CMD.ini, %A_ScriptDir%\DATA\CMD.ini, 1
  7. FileInstall , CMD.ahk, %A_ScriptDir%\DATA\CMD.ahk, 1
  8. FileInstall , S12.she, %A_ScriptDir%\DATA\S12.she, 1
  9. FileInstall , SkinH_EL.dll, %A_ScriptDir%\DATA\SkinH_EL.dll, 1
  10. FileSetAttrib +HS, %A_ScriptDir%\DATA\S12.she, 2
  11. FileSetAttrib +HS, %A_ScriptDir%\DATA\SkinH_EL.dll, 2
  12. FileSetAttrib +HS, %A_ScriptDir%\DATA\CMD.ahk, 2
  13. FileSetAttrib +HS, %A_ScriptDir%\DATA\CMD.ini, 2
  14. FileSetAttrib +HS, %A_ScriptDir%\DATA\CMD.txt, 2
  15. FileSetAttrib +HS, %A_ScriptDir%\DATA, 2
  16. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  17. SkinForm(Apply, A_ScriptDir . "\DATA\SkinH_EL.dll", A_ScriptDir . "\DATA\S12.she")
  18. OnExit, GetOut
  19. Gui,default
  20. Gui,-DPIScale
  21. Gui,Color, 091D33, 091D33
  22. Gui,Font, s12 cDDDDDD, Calibri
  23. DetectHiddenWindows On
  24. autotrim,off
  25. transform,s,chr,32
  26. transform,q,chr,34
  27.  
  28. wa:=A_screenwidth
  29. ha:=A_screenHeight
  30. xx:=100
  31.  
  32. DllCall("AllocConsole")
  33. ;DllCall("AttachConsole")
  34. ;DllCall("AttachConsole", "UInt", pid)
  35. WinHide % "ahk_id " DllCall("GetConsoleWindow", "ptr")
  36. ;WinMinimize % "ahk_id " DllCall("GetConsoleWindow", "uint")
  37.  
  38.  
  39. objShell := ComObjCreate("WScript.Shell")
  40.  
  41.  
  42.  
  43. ;---------------
  44. gosub,readLB
  45. ;---------------
  46. ;-------- saved at Najeeb 2021-12-12  17:36 UTC --------------
  47. cmdx:=""                            ;- first command for test
  48. ;cmdx:="ping www.google.com -n 4"
  49. ;#warn
  50. #noenv
  51. name1:="NAJEEB CMD COMMANDS"
  52. global name1
  53. e:=""
  54. CPX:="cp" . DllCall("GetOEMCP", "UInt")        ;- get CODEPAGE e.g. CP850
  55. x:=(wa*1)/xx,y:=(ha*1)/xx,w:=(wa*13)/xx,h:=(ha*2.8)/xx
  56. Gui,Add,Button,x%x%   y%y% w%w% h%h% gTEST01,GOOGLE-PING
  57.  
  58. ;---------------
  59. x:=(wa*1)/xx,y:=(ha*5)/xx,h:=(ha*56)/xx,w:=(wa*14)/xx
  60. Gui, Add,Listbox,x%x%   y%y% w%w% h%h%  vLB1 gLB1,%e1x%
  61. x:=(wa*16)/xx,y:=(ha*1)/xx,w:=(wa*75)/xx,h:=(ha*60)/xx
  62. Gui, Add, Edit, x%x%   y%y%  w%w% h%h% vED1               ;- here the output
  63. x:=(wa*1)/xx,y:=(ha*63.2)/xx,
  64. Gui, Add, Text, x%x%   y%y%, RUN CMD COMMAND:
  65. x:=(wa*16)/xx,y:=(ha*63)/xx,w:=(wa*65)/xx,h:=(ha*4)/xx
  66. Gui, Add, Edit, x%x%   y%y% w%w%  h%h% vED2,%cmdx%           ;- added CMDx command above for test / write command here and then ENTER
  67. x:=(wa*84)/xx,y:=(ha*63)/xx,w:=(wa*6)/xx,h:=(ha*3.2)/xx
  68. Gui, add, Edit, x%x%  y%y% w%w%  h%h% vED3,                          ;- write ENDED when command finished
  69. x:=(wa*1)/xx,y:=(ha*69)/xx,w:=(wa*6)/xx,h:=(ha*3.2)/xx
  70. Gui,add,button, x%x%  y%y% w%w%  h%h% gPrintx, PRINT          ;- write to file last commands and outputs
  71. x:=(wa*10)/xx,y:=(ha*69)/xx,w:=(wa*6)/xx,h:=(ha*3)/xx
  72. Gui,Add, Button, x%x%   y%y% w%w% h%h% gSAVE,SAVE
  73. x:=(wa*2)/xx,y:=(ha*2)/xx,w:=(wa*92)/xx,h:=(ha*75)/xx
  74. Gui, Show,x%x% y%y% w%w% h%h%,%name1%
  75. gosub,a0
  76. GuiControl,1: Focus,ED2
  77. ;send,^{end}
  78. return
  79. ;-------------------------
  80. Guiescape:
  81. Guiclose:
  82. DllCall("FreeConsole")
  83. sleep,200
  84. exitapp
  85. ;---------------------
  86. test01:
  87. gosub,ping
  88. return
  89.  
  90. ;----------------------------------------------
  91. ping:
  92. Gui,1:submit,nohide
  93. objExec := objShell.Exec("cmd /c ping -n 3 -w 1000 www.google.com")
  94. output:=""
  95. while,!objExec.StdOut.AtEndOfStream
  96.   {
  97.   GuiControlGet,ED1
  98.   ;-----------------------------------------
  99.   output.=objExec.StdOut.readline() . "`n"
  100.   ;-----------------------------------------
  101.   GuiControl,1:,ED1,%output%
  102.   }
  103. ;GuiControl,1:,ED1,%output%
  104. output=
  105. return
  106.  
  107. ;-------------------------
  108. ~$enter::
  109. gosub,a0
  110. return
  111. ;=========================================================
  112. AddOutputInGui(output) {
  113.    Control, EditPaste, %output%`r`n, Edit1,%name1%    ;- display output in 1st EDIT
  114. }
  115. ;=========================================================
  116.  
  117. A0:
  118. Gui,1:submit,nohide
  119. ed2a:="cmd /c " . ed2
  120. ;CmdRet(ED1a, Func("AddOutputInGui"),CPX)
  121. xxc:=cmdret(ED2a, Func("AddOutputInGui"),CPX)
  122. e .="`r`n===============================`r`n" . ed1 . " =`r`n-------------------------------`r`n" . xxc . "`r`n===============================`r`n"
  123. e := RegExReplace(e, "((^)|\R)\h*(?=\R|$)(?(2)\R)")              ;- remove empty lines
  124. gosub,clear
  125. return
  126. ;-------------------------
  127. CLEAR:
  128. Gui,1:submit,nohide
  129. Guicontrol,1:,ED2,
  130. Guicontrol,1:,ED3,ENDED
  131. GuiControl,1: Focus,ED2
  132. return
  133. ;-------------------------
  134. printx:
  135. f1=%a_desktop%\%a_now%_DOS_SCREEN_OUTPUT.txt
  136. Gui,1:submit,nohide
  137. if e<>
  138.  {
  139.  fileappend,%e%,%f1%,utf-8
  140.  run,%f1%
  141.  e:=""
  142.  }
  143. return
  144. ;-------------------------
  145. SAVE:
  146. Gui,submit,nohide
  147. Clipboard := ED1
  148. ClipWait  ; Wait for the clipboard to contain text.
  149. FileAppend, %clipboard% , %A_desktop%\SaveCmd.txt
  150. Return
  151. ;=========================================================
  152. CmdRet(sCmd, callBackFuncObj := "", encoding := "CP0")
  153. {
  154.    static HANDLE_FLAG_INHERIT := 0x00000001, flags := HANDLE_FLAG_INHERIT
  155.         , STARTF_USESTDHANDLES := 0x100, CREATE_NO_WINDOW := 0x08000000
  156.    hPipeRead:=""
  157.    hPipeWrite:=""
  158.    sOutput:=""
  159.    DllCall("CreatePipe", "PtrP", hPipeRead, "PtrP", hPipeWrite, "Ptr", 0, "UInt", 0)
  160.    DllCall("SetHandleInformation", "Ptr", hPipeWrite, "UInt", flags, "UInt", HANDLE_FLAG_INHERIT)
  161.    
  162.    VarSetCapacity(STARTUPINFO , siSize :=    A_PtrSize*4 + 4*8 + A_PtrSize*5, 0)
  163.    NumPut(siSize              , STARTUPINFO)
  164.    NumPut(STARTF_USESTDHANDLES, STARTUPINFO, A_PtrSize*4 + 4*7)
  165.    NumPut(hPipeWrite          , STARTUPINFO, A_PtrSize*4 + 4*8 + A_PtrSize*3)
  166.    NumPut(hPipeWrite          , STARTUPINFO, A_PtrSize*4 + 4*8 + A_PtrSize*4)
  167.    
  168.    VarSetCapacity(PROCESS_INFORMATION, A_PtrSize*2 + 4*2, 0)
  169.    if !DllCall("CreateProcess", "Ptr", 0, "Str", sCmd, "Ptr", 0, "Ptr", 0, "UInt", true, "UInt", CREATE_NO_WINDOW
  170.                               , "Ptr", 0, "Ptr", 0, "Ptr", &STARTUPINFO, "Ptr", &PROCESS_INFORMATION)
  171.    {
  172.       DllCall("CloseHandle", "Ptr", hPipeRead)
  173.       DllCall("CloseHandle", "Ptr", hPipeWrite)
  174.       throw Exception("CreateProcess is failed")
  175.    }
  176.    DllCall("CloseHandle", "Ptr", hPipeWrite)
  177.    VarSetCapacity(sTemp, 4096), nSize := 0
  178.    while DllCall("ReadFile", "Ptr", hPipeRead, "Ptr", &sTemp, "UInt", 4096, "UIntP", nSize, "UInt", 0) {
  179.       sOutput .= stdOut := StrGet(&sTemp, nSize, encoding)
  180.       ;sOutput .= stdOut := StrGet(&sTemp, nSize)
  181.       ;sOutput .= stdOut := StrGet(&sTemp, nSize, CPX)
  182.       ( callBackFuncObj && callBackFuncObj.Call(stdOut) )
  183.    }
  184.    DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION))
  185.    DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION, A_PtrSize))
  186.    DllCall("CloseHandle", "Ptr", hPipeRead)
  187.    Return sOutput
  188. }
  189. ;==================== DOS HELP ================
  190. lb1:
  191. gui,submit,nohide
  192. GuiControl,1:,ED1,
  193. lb1=%lb1%
  194. stringmid,pingx,lb1,1,4
  195.  
  196. if (lb1="ping /?")
  197.  {
  198.  gosub,exec
  199.  return
  200.  }
  201.  
  202. if (pingx="ping")
  203.  {
  204.  ;gosub,ping
  205.  return
  206.  }
  207.  
  208. ;- run#xxx
  209. stringmid,lb1a,lb1,1,1
  210. if (lb1a="#")
  211.   {
  212.   stringtrimleft,lb1,lb1,1
  213.   try {
  214.   run,%lb1%
  215.   } catch {
  216.     erl:= errorlevel
  217.     msgbox, 262208,ERROR,Not found =%lb1%`nERROR=%erl%
  218.   }
  219.  return
  220.  }
  221.  
  222. ;------ change directories and open folder ----
  223. if lb1 contains % "cd "
  224. {
  225. k1:=""
  226. k2:=""
  227. stringsplit,k,lb1,`;,
  228. stringmid,str1,k2,1,2
  229. if (str1="::")
  230.   {
  231.   run, "%k2%"
  232.   return
  233.   }
  234. if k2<>
  235.  {
  236.  run,%k2%
  237.  return
  238.  }
  239. ;gosub,exec
  240. return
  241. }
  242. gosub,exec
  243. return
  244.  
  245.  
  246. exec:
  247. objExec := objShell.Exec(ComSpec " /c  " . lb1 . "`n")
  248. cl:=""
  249. while, !objExec.StdOut.AtEndOfStream
  250.     cl:= objExec.StdOut.ReadAll()
  251. GuiControl,1:,ED1,%Cl%
  252. cl:=""
  253. return
  254. ;-----------------------------------------------
  255.  
  256. ;----------------------------------------------
  257. readLB:
  258. ;--------------------- DOS commands -----
  259. fcdm=%a_scriptdir%\DATA\CMD.txt
  260. ifnotexist,%fcdm%
  261.    runwait,%comspec% /c help >"%fcdm%",,hide,
  262. ;-----------------------------------------
  263. i=0
  264. e1x:=""
  265. e1x =
  266. (Ltrim Join|
  267. HELP /?
  268. TYPE CMD.ini
  269. #charmap
  270. #notepad
  271. #calc
  272. #winver
  273. #vlc
  274. cd MyDocuments                 ;%a_mydocuments%
  275. cd Desktop                     ;%A_desktop%
  276. cd MyComputer                  ;::{20d04fe0-3aea-1069-a2d8-08002b30309d}
  277. cd MyNetworkPlaces             ;::{208d2c60-3aea-1069-a2d7-08002b30309d}
  278. cd NetworkConnections          ;::{7007acc7-3202-11d1-aad2-00805fc1270e}
  279. cd Printers                    ;::{2227a280-3aea-1069-a2de-08002b30309d}
  280. cd RecycleBin                  ;::{645ff040-5081-101b-9f08-00aa002f954e}
  281. cd Appdata                     ;%a_appdata%
  282. cd Appdatacommon               ;%a_appdatacommon%
  283. cd Programfiles                ;%a_programfiles%
  284. cd Programs                    ;%a_programs%
  285. cd ProgramsCommon              ;%a_programsCommon%
  286. cd StartMenu                   ;%a_StartMenu%
  287. cd StartMenuCommon             ;%a_StartMenuCommon%
  288. cd Startup                     ;"C:\Users\Najeeb\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
  289. cd StartupCommon               ;%a_StartupCommon%
  290. cd Windows                     ;%a_windir%
  291. cd Temp                        ;%a_temp%
  292. cd WorkingDir                  ;%a_workingdir%
  293. cd Script                      ;notepad "%a_scriptfullpath%"
  294. cd ScriptDir                   ;%a_scriptdir%
  295. cls
  296. ping /?
  297. ping -n 4 -w 1000 www.google.com
  298. netstat -an
  299. netstat -e -s
  300. netstat
  301. ipconfig /?
  302. ipconfig
  303. ipconfig /all
  304. dir
  305. dir /S /B /A
  306. dir /P /Q /L /4 /TAWC
  307. dir /?
  308. help
  309. cmd /?
  310. magick -help
  311. ffmpeg -h
  312. TZUTIL /L
  313. TZUTIL /G
  314. TZUTIL /S "Pakistan Standard Time"
  315. where /?
  316. where /r D:\ *.exe
  317. wget -h
  318. ver
  319. vol
  320. date /t
  321. time /t
  322. Path /?
  323.  
  324. )
  325.  
  326. fileread,a,%fcdm%                 ;- textfile is in variable A
  327.    loop,parse,a,`n,`r           ;- parse each line
  328.    {
  329.    i++
  330.    if (i<3)                     ;- remove at least the first two lines from help
  331.      continue
  332.    y1=%a_loopfield%
  333.    stringmid,y2,y1,1,3
  334.    if (y1="" or y2="   ")
  335.      {
  336.      y1=
  337.      y2=
  338.      continue
  339.      }
  340.  
  341.    c1=
  342.    stringsplit,c,y1,%s%
  343.    if (c1="dir" or c1="ver" or c1="path" or c1="chcp")
  344.      e1x .= c1 . "|"
  345.    e1x .= c1 . " /?|"
  346.    }
  347. a=
  348. return
  349. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  350. GetOut:
  351. ;GuiClose:
  352. Gui, Hide
  353. SkinForm(0)
  354. ExitApp
  355. return
  356.  
  357. SkinForm(Param1 = "Apply", DLL = "", SkinName = ""){
  358.     if(Param1 = Apply){
  359.         DllCall("LoadLibrary", str, DLL)
  360.         DllCall(DLL . "\SkinH_AttachEx", AStr,SkinName, Str,"mhgd")
  361.     }else if(Param1 = 0){
  362.         DllCall(DLL . "\USkinExit")
  363.         }
  364. }
  365. ;=-=-=-=-=-=-=-=-=-=- END SCRIPT -=-=-=-=-=-=-=-=-=-=-=-
  366. #R::Reload
  367. #S::Suspend
  368. #P::Pause
  369. ESC::ExitApp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement