2017-12-11 3 views
-2

아래 코드를 사용하여 파일을 설치합니다.AutoIt 스크립트에서 팝업 창을 숨기려면 어떻게합니까?

Run("file.exe", "", @SW_HIDE) 
WinWait("install", "") 
WinSetState("install", "", @SW_HIDE) 
Sleep(2000) 
ControlSend('install', '', '', 'E-mail') 
ControlSend('install', '', '', '{ENTER}') 
WinWait("install", "") 
WinSetState("install", "", @SW_HIDE) 

은 콘솔 창을 숨길 수 있지만, 몇 초 후에 ...

시스템 팝업은 설치 과정을 보여주는 비트에 대한 또 다른 설치 창을 표시하고 숨 깁니다.

이 창과 콘솔 창을 숨기는 방법을 알고 싶습니다.

답변

1

사용자가 볼 수있는 창이 없도록 Windows의 숨겨진 데스크톱에서 자동 실행 기능을 사용하여 응용 프로그램을 실행하는 방법이 있습니다. 내장 된 send()/click()/etc ... autoit 함수를 통해이 응용 프로그램과 해당 윈도우와 상호 작용할 수도 있습니다.

hiddenDesktopInteract.au3 :

#Region ;**** Directives created by AutoIt3Wrapper_GUI **** 
#AutoIt3Wrapper_UseUpx=y 
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** 
#include <WinAPI.au3> 
#include <WinAPIEx.au3> 
#include <GDIPlus.au3> 

;1st command line param that will launch seperate instance 
Const $hdiParam = 'hiddenDesktopInteract' 

;######DO NOT PUT ANY OTHER CODE ABOVE THIS THAT CALLS A 2ND INSTANCE OF THE SCRIPT OR ELSE YOU MAY END UP CALLING INFINITE INSTANCES AND CRASHING WINDOWS!!!!!! 
;seperate process for hidden desktop interaction 
;1st param should be 'hiddenDesktopInteract' and 2nd param is name of func to call for interaction code 
;ex: "autoit.exe script.au3 hiddenDesktopInteract interactionfunc" or "compiledscript.exe hiddenDesktopInteract interactionfunc" 
if $CmdLine[0] = 2 AND $CmdLine[1] = $hdiParam Then EXIT Call($CmdLine[2]) 

;credit to Decipher in thread https://www.autoitscript.com/forum/topic/152515-start-a-process-hidden/#comment-1095173 for code for running process on a hidden desktop 
Func _hiddenDesktopInteract_run($sProgram, $sInteractionFunc, $sCommand = '') 
    ;if the interaction function does not exist then don't do anything 
    If Not IsFunc(Execute($sInteractionFunc)) Then 
     ConsoleWrite('error: interaction function "' & $sInteractionFunc & '" for "' & $sProgram & '" does not exist' & @CRLF) 
     Return 
    EndIf 

    ;create structs 
    Local $tStartupInfo = DllStructCreate($tagStartupInfo) 
    DllStructSetData($tStartupInfo, "Size", DllStructGetSize($tStartupInfo)) 
    Local $tProcessInfo_targetApp = DllStructCreate($tagPROCESS_INFORMATION) 
    Local $tProcessInfo_interactionScript = DllStructCreate($tagPROCESS_INFORMATION) 

    ; Create Desktop 
    Local $hDesktop = _WinAPI_CreateDesktop('AutoItHidden', BitOR($DESKTOP_CREATEWINDOW, $DESKTOP_SWITCHDESKTOP)) 
    If Not $hDesktop Then 
     MsgBox(0, 'Error', 'Unable to create desktop.') 
     Exit 
    EndIf 

    ; Prep Process Info 
    Local $nSuccess = DllStructSetData($tStartupInfo, "Desktop", _WinAPI_CreateString("AutoItHidden")) 

    ;run target program on hidden desktop and get PID 
    _WinAPI_CreateProcess('', '"' & $sProgram & '"' & ($sCommand ? ' ' & $sCommand : ''), 0, 0, 0, 0x00000200, 0, 0, DllStructGetPtr($tStartupInfo), DllStructGetPtr($tProcessInfo_targetApp)) 
    Local $aPID_targetApp = DllStructGetData($tProcessInfo_targetApp, 'ProcessID') 
    ConsoleWrite('!>target app PID:' & $aPID_targetApp & @CRLF) 

    ;run instance of this script on hidden desktop to interact with target program 
    Local $sParams = '"' & @ScriptFullPath & '" ' & $hdiParam & ' ' & $sInteractionFunc 
    Switch @Compiled 
     case True 
      Local $sAppName = @ScriptFullPath 
      Local $sCommandLine = $sParams 
     case False 
      Local $sAppName = @AutoItExe 
      Local $sCommandLine = '"' & @AutoItExe & '" ' & $sParams 
    EndSwitch 
    _WinAPI_CreateProcess('', $sCommandLine, 0, 0, 0, 0x00000200, 0, 0, DllStructGetPtr($tStartupInfo), DllStructGetPtr($tProcessInfo_interactionScript)) 

    ;and get PID of interaction instance so we can wait until it is finished 
    Local $iPID_interactionScript = DllStructGetData($tProcessInfo_interactionScript, 'ProcessID') 
    ConsoleWrite('!>Interaction Script PID: ' & $iPID_interactionScript & @CRLF) 

    ;wait until interaction script instance is finished and get exit code (which is return value from interaction function) 
    ProcessWaitClose($iPID_interactionScript) 
    Local $exitcode_interactionScript = @extended 
    ConsoleWrite("!>Interaction Script Exit Code: " & $exitcode_interactionScript & @CRLF) 
    Local $sOutput = StdoutRead($iPID_interactionScript) 
    ConsoleWrite("!>Interaction Script Stdout: " & $sOutput & @CRLF) 

    ;close hidden desktop 
    Local $aRet = DllCall("User32.dll", "int", "CloseDesktop", "handle", $hDesktop) 
    ConsoleWrite("!>Close Desktop: " & $aRet[0] & @CRLF) ; Non-Zero is successfull! 

    Return $exitcode_interactionScript 
EndFunc 

Func _hiddenDesktopInteract_cap($title, $imgfile, $Left = 0, $Top = 0, $Right = -1, $Bottom = -1) 
    _GDIPlus_Startup() 
    $hWnd = WinGetHandle($title) 
    $iWidth = _WinAPI_GetWindowWidth($hWnd) 
    $iHeight = _WinAPI_GetWindowHeight($hWnd) 
    $hDDC = _WinAPI_GetDC($hWnd) 
    $hCDC = _WinAPI_CreateCompatibleDC($hDDC) 
    $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iWidth, $iHeight) 
    _WinAPI_SelectObject($hCDC, $hBMP) 
    DllCall("User32.dll", "int", "PrintWindow", "hwnd", $hWnd, "hwnd", $hCDC, "int", 0) 
    _WinAPI_ReleaseDC($hWnd, $hDDC) 
    _WinAPI_DeleteDC($hCDC) 
    $hBMPclone = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) 
    if $Right = -1 then 
     $iX = _GDIPlus_ImageGetWidth($hBMPclone) - $Left 
    Else 
     $iX = $Right - $Left 
    EndIf 
    if $Bottom = -1 then 
     $iY = _GDIPlus_ImageGetHeight($hBMPclone) - $Top 
    Else 
     $iY = $Bottom - $Top 
    EndIf 
    ;convert from 32bit bitmap to 24bit bitmap b/c 32bit bitmap cannot display correctly in autoit GUI for some reason 
    $hClone = _GDIPlus_BitmapCloneArea($hBMPclone, $Left, $Top, $iX, $iY, $GDIP_PXF24RGB) 
    _GDIPlus_ImageSaveToFile($hClone, $imgfile) 
    _WinAPI_DeleteObject($hBMP) 
    _WinAPI_DeleteObject($hBMPclone) 
    _WinAPI_DeleteObject($hClone) 
    _GDIPlus_Shutdown() 
EndFunc 

Here

은 AutoIt이 코드에 대한 링크가 AutoIt이 포럼 여기

에이 작업을 수행 할 수있는 링크가 죽었을 경우에 코드입니다 예제 스크립트는 메모장과 cmd.exe의 숨겨진 인스턴스를 실행하고 controlclick() 및 controlsend()를 통해 상호 작용 한 다음 닫히기 전에 창의 화면 캡쳐를 캡처하는 방법을 보여줍니다. 그거야.

hiddenDesktopInteract_EXAMPLES.au3 :

#include "hiddenDesktopInteract.au3" 

;test function for interacting with notepad app on hidden desktop 
func notepadtest() 
    opt('winwaitdelay', 0) ;to make it run a little bit faster 
    WinWait('[CLASS:Notepad]') 
    $hwin = WinGetHandle('[CLASS:Notepad]') 
    ControlSend($hwin, '', '[CLASS:Edit; INSTANCE:1]', 'hello{ENTER}') 
    WinMenuSelectItem($hwin, '', '&Edit', 'Time/&Date') 
    _hiddenDesktopInteract_cap($hwin, @DesktopDir & '\notepad_cap.jpg') 
    ControlSend($hwin, '', '[CLASS:Edit; INSTANCE:1]', '^a') 
    ControlSend($hwin, '', '[CLASS:Edit; INSTANCE:1]', '{DELETE}') 
    WinClose($hwin) 
EndFunc 

;test function for interacting with cmd.exe on hidden desktop 
func cmdtest() 
    opt('winwaitdelay', 0) ;to make it run a little bit faster 
    WinWait('[CLASS:ConsoleWindowClass]') 
    $hwin = WinGetHandle('[CLASS:ConsoleWindowClass]') 
    ControlSend($hwin, '', '', 'dir{ENTER}') 
    sleep(500) 
    _hiddenDesktopInteract_cap($hwin, @DesktopDir & '\cmd_cap.jpg') 
    ControlSend($hwin, '', '', 'exit{ENTER}') 
EndFunc 

_hiddenDesktopInteract_run("notepad.exe", 'notepadtest') 
_hiddenDesktopInteract_run("cmd.exe", 'cmdtest') 

이는 AutoIt이 포럼 포스트에서 거의 그냥 복사 - 붙여 넣기는하지만 해당 게시물의 저자이기 때문에 나는 그 문제가 일을 생각하지 않는다 .

0

WinSetState을 사용하여 창을 숨길 수는 있지만 더 이상이 창의 컨트롤과 더 이상 상호 작용할 수 없습니다.

; wait for the window to appear 
Local $hWnd = WinWait("[CLASS:TheAppToHide]") 

; hide the window using the handle returned from WinWait 
WinSetState($hWnd, "", @SW_HIDE) 
+1

당신은 잘하지만 난 ControlSend를 보낼 때 응용 프로그램 새 창을 열 ('{ENTER}' '', '', '설치') 그리고 난 그런 당신이 사용해야 그것을 –

+0

를 숨기려면 그 팝업 창에서 WinWait을하고 내가 쓴 것처럼 WinSetState로 숨 깁니다. 아니면 지속적으로 팝업 창이 생성된다는 의미입니까? – mrt

+0

나는 팝업 창에서 WinWait을 사용하지만 잠시 동안 열어 본 다음 숨긴다. –

관련 문제