如何使用cmd打开最小化的chrome

时间:2013-12-13 20:11:39

标签: google-chrome cmd command minimize

我正在使用python编写脚本来帮助我管理打开的浏览器页面。 我正在使用os.system(“start ...”)打开chrome,我希望它作为最小化程序打开。

我注意到我不能使用flag / min(我试过“start / min chrome www.google.com”)而不是来自python脚本,也不是来自命令行本身或RUN。 / p>

有谁知道如何打开最小化的镀铬窗口? 或者也许是最小化现有镀铬窗口的命令(我打开它并将其最小化,希望它足够快让我注意到)?

我发现的只是如何最小化命令行本身。 当我从cmd使用“start / min notepad”时,flag / min工作得很好。 如果重要的话,我正在使用Windows XP操作系统。

2 个答案:

答案 0 :(得分:0)

http://code.google.com/p/pywinauto/

可能会有所帮助。

根据example,您可以使用“最小化()”来完成这项工作:

def do_test_1():

  "1st Watsup Test"

  app = Application().start_(r"c:\windows\Notepad")
  notepadWindow = app.Notepad

  notepadWindow.Edit1.SetEditText(u"Hello, 鋑ain!", 0, -1)
  sleep(0.8)
  notepadWindow.Edit.SetEditText("\r\nYou still there?")

  sleep(0.2)
  notepadWindow.Edit.SetEditText("\r\nGoing Bye Bye now!!")

  sleep(1)
  notepadWindow.Minimize()

  sleep(1)
  notepadWindow.Restore()

答案 1 :(得分:0)

我写了这个以获得所需的结果。

可能不是最好的代码,但是经过几个小时的尝试后,这实际上是有效的。

Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr

Private Const SW_SHOWMAXIMIZED As Integer = 3
Private Const SW_SHOWMINIMIZED As Integer = 2
Private Const SW_SHOWNORMAL As Integer = 1


            ' Start Chrome with a Blank document so we know what the Name will be.
            ' This is a bit of a work around but after trying for hour to get the handle 
            ' the the actual Chrome window that opens this is the only way.
            Process.Start("Chrome.exe", "--new-window --start-fullscreen _Blank")  ' C:\Program Files (x86)\Google\Chrome\Application\

            ' Need to wait until the window has been initalised, the name will not be set until
            ' the page has been loaded. Chrome will take a little while to start and then 
            ' realise that "_Blank" is not a valid URL.
            ' We will loop round for 30 seconds, after the the page will not be opened.
            Dim LongTimeEscapeCounter = 300
            While iHwndOrderStatusScreen = 0 And LongTimeEscapeCounter <> 0
                LongTimeEscapeCounter = LongTimeEscapeCounter - 1
                iHwndOrderStatusScreen = FindWindow(vbNullString, "http://_Blank/ is not available - Google Chrome")
                Sleep(100)
            End While
            Debug.Print("Chrome Handle: " & iHwndOrderStatusScreen.ToString)
            If iHwndOrderStatusScreen = 0 Then
                MsgBox("Failed to find the Google Chrome Handle, reboot the PC and try again.", vbOKOnly + vbExclamation, "Error")
                Exit Sub
            End If

            ' Open the actual page the user wants
            Process.Start("Chrome.exe", txtFileName2.Text)
            Sleep(5000)
            ShowWindow(iHwndOrderStatusScreen, SW_SHOWMINIMIZED)
            Beep()

千电子伏