Doubt to hide window Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
snowmind
Posts: 124
Joined: 12 Nov 2015, 15:18

Doubt to hide window

07 Feb 2019, 10:14

Hi guys! :salute:
I'm developing a script to run the WMIC command. I am running with the following command line:

Code: Select all

ComObjCreate("WScript.Shell").Exec("wmic product get name, version, vendor").StdOut.ReadAll()
as soon as I run, a WMIC runtime window opens. I would like to hide this window. WinHide hides the window, but while running WMIC, the code does not pass to the WinHide line (WinHide, C:\windows\System32\Wbem\wmic.exe).

How to hide a window that will still appear? :think:
snowmind
Posts: 124
Joined: 12 Nov 2015, 15:18

Re: Doubt to hide window

07 Feb 2019, 10:47


It's a good solution, but using the COM object I can run the command and write directly to a variable, plus the ability to use credentials
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Doubt to hide window  Topic is solved

07 Feb 2019, 15:54

Use the ProcessID Property (see Exec - VBScript @ss64). You're still going to get a window blink, though:

Code: Select all

#NoEnv
#SingleInstance force
#Warn

SetWinDelay, -1
wshScriptExecObject := ComObjCreate("WScript.Shell").Exec("wmic product get name, version, vendor")
WinWait % "ahk_pid " . wshScriptExecObject.ProcessID
WinHide
MsgBox % wshScriptExecObject.StdOut.ReadAll()
Hope this helps.
my scripts
teadrinker
Posts: 4326
Joined: 29 Mar 2015, 09:41
Contact:

Re: Doubt to hide window

07 Feb 2019, 16:54

One more option:

Code: Select all

MsgBox, % Clipboard := CmdRet("wmic product get name, version, vendor")

CmdRet(sCmd, cp := "cp866")
{
   static STARTF_USESTDHANDLES := 0x100, CREATE_NO_WINDOW := 0x08000000
   
   DllCall("CreatePipe", PtrP, hPipeRead, PtrP, hPipeWrite, UInt, 0, UInt, 0)
   DllCall("SetHandleInformation", Ptr, hPipeWrite, UInt, 1, UInt, 1)
   
   VarSetCapacity(pi, A_PtrSize*2 + 4*2, 0)
   VarSetCapacity(si, sisize := A_PtrSize*4 + 4*8 + A_PtrSize*5, 0)
   NumPut(sisize, si)
   NumPut(STARTF_USESTDHANDLES, si, A_PtrSize*4 + 4*7)
   NumPut(hPipeWrite, si, A_PtrSize*4 + 4*8 + A_PtrSize*3)
   NumPut(hPipeWrite, si, A_PtrSize*4 + 4*8 + A_PtrSize*4)

   if !DllCall("CreateProcess", UInt, 0, Ptr, &sCmd, UInt, 0, UInt, 0, Int, true
                              , UInt, CREATE_NO_WINDOW, UInt, 0, UInt, 0, Ptr, &si, Ptr, &pi)  {
      DllCall("CloseHandle", Ptr, hPipeRead)
      DllCall("CloseHandle", Ptr, hPipeWrite)
      MsgBox, CreateProcess is failed
      Return
   }
   DllCall("CloseHandle", Ptr, hPipeWrite)
   VarSetCapacity(sTemp, 4096), nSize := 0
   while DllCall("ReadFile", Ptr, hPipeRead, Ptr, &sTemp, UInt, 4096, UIntP, nSize, UInt, 0)
      sOutput .= StrGet(&sTemp, nSize, cp)
   
   DllCall("CloseHandle", Ptr, NumGet(pi, 0))
   DllCall("CloseHandle", Ptr, NumGet(pi, A_PtrSize))
   DllCall("CloseHandle", Ptr, hPipeRead)
   Return sOutput
}
snowmind
Posts: 124
Joined: 12 Nov 2015, 15:18

Re: Doubt to hide window

11 Feb 2019, 10:41

A_AhkUser wrote:
07 Feb 2019, 15:54
Use the ProcessID Property (see Exec - VBScript @ss64). You're still going to get a window blink, though:

Code: Select all

#NoEnv
#SingleInstance force
#Warn

SetWinDelay, -1
wshScriptExecObject := ComObjCreate("WScript.Shell").Exec("wmic product get name, version, vendor")
WinWait % "ahk_pid " . wshScriptExecObject.ProcessID
WinHide
MsgBox % wshScriptExecObject.StdOut.ReadAll()
Hope this helps.
Great! Works fine :dance:
snowmind
Posts: 124
Joined: 12 Nov 2015, 15:18

Re: Doubt to hide window

11 Feb 2019, 10:42

teadrinker wrote:
07 Feb 2019, 16:54
One more option:

Code: Select all

MsgBox, % Clipboard := CmdRet("wmic product get name, version, vendor")

CmdRet(sCmd, cp := "cp866")
{
   static STARTF_USESTDHANDLES := 0x100, CREATE_NO_WINDOW := 0x08000000
   
   DllCall("CreatePipe", PtrP, hPipeRead, PtrP, hPipeWrite, UInt, 0, UInt, 0)
   DllCall("SetHandleInformation", Ptr, hPipeWrite, UInt, 1, UInt, 1)
   
   VarSetCapacity(pi, A_PtrSize*2 + 4*2, 0)
   VarSetCapacity(si, sisize := A_PtrSize*4 + 4*8 + A_PtrSize*5, 0)
   NumPut(sisize, si)
   NumPut(STARTF_USESTDHANDLES, si, A_PtrSize*4 + 4*7)
   NumPut(hPipeWrite, si, A_PtrSize*4 + 4*8 + A_PtrSize*3)
   NumPut(hPipeWrite, si, A_PtrSize*4 + 4*8 + A_PtrSize*4)

   if !DllCall("CreateProcess", UInt, 0, Ptr, &sCmd, UInt, 0, UInt, 0, Int, true
                              , UInt, CREATE_NO_WINDOW, UInt, 0, UInt, 0, Ptr, &si, Ptr, &pi)  {
      DllCall("CloseHandle", Ptr, hPipeRead)
      DllCall("CloseHandle", Ptr, hPipeWrite)
      MsgBox, CreateProcess is failed
      Return
   }
   DllCall("CloseHandle", Ptr, hPipeWrite)
   VarSetCapacity(sTemp, 4096), nSize := 0
   while DllCall("ReadFile", Ptr, hPipeRead, Ptr, &sTemp, UInt, 4096, UIntP, nSize, UInt, 0)
      sOutput .= StrGet(&sTemp, nSize, cp)
   
   DllCall("CloseHandle", Ptr, NumGet(pi, 0))
   DllCall("CloseHandle", Ptr, NumGet(pi, A_PtrSize))
   DllCall("CloseHandle", Ptr, hPipeRead)
   Return sOutput
}
Its good option! tks a lot for sharing this with me :monkeysay:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 316 guests