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



我正在使用python编写一个脚本,以帮助我管理打开的浏览器页面。我正在使用操作系统("启动…")来打开chrome,我希望它能作为一个最小化的程序打开。

我注意到,我不能使用flag/min(我尝试了"start/min-chromewww.google.com")来实现这一点,而不是从python脚本中,也不是从命令行本身或RUN中。

有人知道如何打开最小化的镀铬窗口吗?或者可能是最小化现有chrome窗口的命令(我会打开它,然后最小化它,希望它足够快让我注意到)?

我所发现的只是如何最小化命令行本身。当我使用cmd中的"start/min记事本"时,flag/min工作得非常好。不管怎样,我使用的是Windows XP操作系统。

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

可能会有所帮助。

根据它的例子,你可以使用"最小化()"来完成这项工作:

def do_test_1():
  "1st Watsup Test"
  app = Application().start_(r"c:windowsNotepad")
  notepadWindow = app.Notepad
  notepadWindow.Edit1.SetEditText(u"Hello, 鋑ain!", 0, -1)
  sleep(0.8)
  notepadWindow.Edit.SetEditText("rnYou still there?")
  sleep(0.2)
  notepadWindow.Edit.SetEditText("rnGoing Bye Bye now!!")
  sleep(1)
  notepadWindow.Minimize()
  sleep(1)
  notepadWindow.Restore()

我写这篇文章是为了得到所需的结果。

老实说,这可能不是有史以来最好的代码,但经过几个小时的尝试,它确实奏效了。

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)GoogleChromeApplication
            ' 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()

Kev

最新更新