Run this script but minimized Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jerryrig
Posts: 40
Joined: 01 May 2021, 23:31

Run this script but minimized

03 Jun 2021, 10:06

Code: Select all


run cmd 
Sleep 200
Send date {Enter}
Sleep 100
send 02-02-2018 
Sleep 200
send {Enter}

this code will open cmd and change the date ...but i want to do the same stuff minimised any chance ?? :terms:
Ferro
Posts: 7
Joined: 13 Jun 2016, 09:45

Re: Run this script but minimized  Topic is solved

03 Jun 2021, 11:04

Code: Select all

run, %comspec% /c date 02-02-2018,,hide
This will set the date through cmd.exe without ever showing the command window so it doesn't get in your way.
teadrinker
Posts: 4411
Joined: 29 Mar 2015, 09:41
Contact:

Re: Run this script but minimized

03 Jun 2021, 11:12

You can use this code without opening the cmd window:

Code: Select all

RunAsAdmin(true)
RunCmd("cmd /c date 02-02-2018")

RunAsAdmin(exitIfNotAdmin := false)  {
   commandLine := DllCall("GetCommandLine", "str")
   isRestarted := !!RegExMatch(commandLine, " /restart(?!\S)")
   
   while !( A_IsAdmin || isRestarted ) {
      try Run, % "*RunAs " . (A_IsCompiled ? """" . A_ScriptFullPath . """ /restart"
                                           : """" . A_AhkPath . """ /restart """ . A_ScriptFullPath . """")
      catch
         break 
      ExitApp
   }
   if !A_IsAdmin  {
      MsgBox, Failed to run the script as admin!
      if exitIfNotAdmin
         ExitApp
   }
}

RunCmd(sCmd, callBackFuncObj := "", encoding := "")
{
   static HANDLE_FLAG_INHERIT := 0x00000001, flags := HANDLE_FLAG_INHERIT
        , STARTF_USESTDHANDLES := 0x100, CREATE_NO_WINDOW := 0x08000000
        
   (encoding = "" && encoding := "cp" . DllCall("GetOEMCP", "UInt"))
   DllCall("CreatePipe", "PtrP", hPipeRead, "PtrP", hPipeWrite, "Ptr", 0, "UInt", 0)
   DllCall("SetHandleInformation", "Ptr", hPipeWrite, "UInt", flags, "UInt", HANDLE_FLAG_INHERIT)
   
   VarSetCapacity(STARTUPINFO , siSize :=    A_PtrSize*4 + 4*8 + A_PtrSize*5, 0)
   NumPut(siSize              , STARTUPINFO)
   NumPut(STARTF_USESTDHANDLES, STARTUPINFO, A_PtrSize*4 + 4*7)
   NumPut(hPipeWrite          , STARTUPINFO, A_PtrSize*4 + 4*8 + A_PtrSize*3)
   NumPut(hPipeWrite          , STARTUPINFO, A_PtrSize*4 + 4*8 + A_PtrSize*4)
   
   VarSetCapacity(PROCESS_INFORMATION, A_PtrSize*2 + 4*2, 0)

   if !DllCall("CreateProcess", "Ptr", 0, "Str", sCmd, "Ptr", 0, "Ptr", 0, "UInt", true, "UInt", CREATE_NO_WINDOW
                              , "Ptr", 0, "Ptr", 0, "Ptr", &STARTUPINFO, "Ptr", &PROCESS_INFORMATION)
   {
      DllCall("CloseHandle", "Ptr", hPipeRead)
      DllCall("CloseHandle", "Ptr", hPipeWrite)
      throw "CreateProcess is failed"
   }
   DllCall("CloseHandle", "Ptr", hPipeWrite)
   VarSetCapacity(sTemp, 4096), nSize := 0
   while DllCall("ReadFile", "Ptr", hPipeRead, "Ptr", &sTemp, "UInt", 4096, "UIntP", nSize, "UInt", 0) {
      sOutput .= stdOut := StrGet(&sTemp, nSize, encoding)
      ( callBackFuncObj && callBackFuncObj.Call(stdOut) )
   }
   DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION))
   DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION, A_PtrSize))
   DllCall("CloseHandle", "Ptr", hPipeRead)
   Return sOutput
}
jerryrig
Posts: 40
Joined: 01 May 2021, 23:31

Re: Run this script but minimized

03 Jun 2021, 13:16

:thumbup:

but can i send a text to notepad and save it ..without opening notepad
...
by default all the events done by ahk happens in front if screen ... i wanna do it minimised ...
User avatar
boiler
Posts: 17384
Joined: 21 Dec 2014, 02:44

Re: Run this script but minimized

03 Jun 2021, 13:41

jerryrig wrote: but can i send a text to notepad and save it ..without opening notepad
It doesn’t make sense to send text to Notepad without opening Notepad. What you are really wanting to do is add text to a file without opening Notepad. You can do that with FileAppend, and it is independent of Notepad or any other text editor.

jerryrig wrote: by default all the events done by ahk happens in front if screen ... i wanna do it minimised ...
This is not true. There are many things AHK does that aren’t seen on the screen, such as the file operation described above.
jerryrig
Posts: 40
Joined: 01 May 2021, 23:31

Re: Run this script but minimized

03 Jun 2021, 14:45

may be i want to keep track of time in which user presses a key .....
it must be done behind ..anyways in convinced withcur answer thanks 🤩🤩🤩😍😍😍😍
User avatar
boiler
Posts: 17384
Joined: 21 Dec 2014, 02:44

Re: Run this script but minimized

03 Jun 2021, 14:55

jerryrig wrote:
03 Jun 2021, 14:45
may be i want to keep track of time in which user presses a key .....
I don’t understand what this has to do with Notepad.
jerryrig
Posts: 40
Joined: 01 May 2021, 23:31

Re: Run this script but minimized

03 Jun 2021, 20:25

lol..... i dont know everytools in ahk ...... 😄

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Chunjee, Google [Bot], JKJadan, Psych0p4th and 278 guests