Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scrcpy-noconsole.vbs #4357

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions app/data/scrcpy-noconsole.vbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
strCommand = "cmd /c scrcpy.exe"
strProcessName = "scrcpy.exe"
bFound = False

For Each Arg In WScript.Arguments
strCommand = strCommand & " """ & replace(Arg, """", """""""""") & """"
' Check if scrcpy.exe is already running
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process")

For Each objProcess in colProcesses
If InStr(1, objProcess.Name, strProcessName, vbTextCompare) > 0 Then
' scrcpy.exe is already running
bFound = True
Exit For
End If
Next

CreateObject("Wscript.Shell").Run strCommand, 0, false
If bFound Then
' Bring scrcpy window to the foreground, unless its minimized
Set objShell = CreateObject("WScript.Shell")

' Activate the window by title
objShell.AppActivate("2201116PG")

Else
' scrcpy.exe is not running, so start it
strCommand = "cmd /c scrcpy.exe"

For Each Arg In WScript.Arguments
strCommand = strCommand & " """ & Replace(Arg, """", """""") & """"
Next

CreateObject("WScript.Shell").Run strCommand, 0, False
End If