Starting and minimizing Quake Terminal at startup - windows

I'm trying to create a WSF that I can run using Task Scheduler at login. I want it to open the Terminal, switch to Quake mode, minimize that and then close the orignal Terminal window.
I've got as far as getting the Terminal to open, and activate Quake, but I'm not sure how to shift focus to the Quake Terminal in order to minimize it and then back to the original to exit out.
Best method for this - possibly not, but I'm playing around with things so I'd like to stick to this if I can.
This is what I have so far
<package>
<job id="vbs">
<script language="VBScript">
Set objShell = WScript.CreateObject("WScript.Shell")
Function SendKeysTo (process, keys, wait)
objShell.AppActivate(process.ProcessID)
objShell.SendKeys keys
WScript.Sleep wait
End Function
Set terminal= objShell.Exec("wt")
WScript.Sleep 500
SendKeysTo terminal, "^(`)", 1000 ' Works down to here
SendKeysTo terminal, "^(`)", 1000 ' I'm guessing this is still trying to input to the first terminal window which doesn't have focus anymore
SendKeysTo terminal, "exit{ENTER}", 1000
</script>
</job>
</package>
I have the Quake shortcut changed to Ctrl+` as it cannot simulate a WinKey press, I'm okay with this.

Note: This is the solution I use for your titled issue, but without the use of VBScript.
You need to add a task to the Task Library with a trigger At Log On.
The action it should perform goes as follow;
Program/Script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Add arguments: -Command wt -w _quake powershell -nologo -window minimized
This will launch Windows Terminal in/with Quake mode, then start a Powershell process that will minimize the window.
Source: I got this helpful tip from KKirschi from their comment.

Related

Running chrome in full screen using vb script

Hi I have problem with a vb script i created to run chrome in full screen.
The script simulates the F11 key press when chrome starts.
The script works when i run it but when I set it to run on startup on Windows XP chrome does not go full screen.
This is the script i have.
Option Explicit
Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.Run "chrome"
Wscript.Sleep 1000
objShell.SendKeys "{F11}"
WScript.Quit
Try launching Chrome with the command line switch "--full-screen".
It specifies if the browser should start in fullscreen mode, like if the user had pressed F11 right after startup. However, it seems it is ignored if the value of the "On Startup" setting is "Continue where you left off" (it works for the other two values).

cmd / powershell: minimize all windows on your desktop except for current command prompt (console) or except for some particular window

well, I know how to minimize all open windows on the desktop from a batch file by using powershell method - MinimizeAll():
powershell -command "& { $x = New-Object -ComObject Shell.Application; $x.minimizeall() }"
the problem is: this method minimizes everything including current cmd-console which should be in my case always visible to the user.
now, to workaround this problem I use external nircmd.exe tool and this part of my .bat-file looks like this:
:: change current command prompt window title
title my-cmd-console
:: minimize all open windows on the desktop with powershell command
powershell -command "& { $x = New-Object -ComObject Shell.Application; $x.minimizeall() }"
:: bring console back to the front with nircmd.exe command 'win activate [filter window by title]'
nircmd.exe win activate title "my-cmd-console"
what I don't like about this code is that there is much 'flashing' on the screen: at start, the console appears on the desktop, then it gets minimized with all other windows and then it's brought back on the desktop front again.
so, the question is: how to make console appear on the desktop front and 'lock it', so that it never gets out of sight until the command line EXIT is reached.
P.S.
not sure, but maybe there is an alternative solution to 'minimize all except for particular window' problem without need to use external nircmd.exe tool. any ideas?
minimize all but the active window (toggling command):
nircmd sendkeypress rwin+home

Executable running in background

I am trying to run a simple batch script via Jenkins (which in turn calls a VBscript). The script which i am executing in Jenkins is:
cd "C:\Product\workspace"
cscript Test.vbs
The test.vbs is simple code which calls an exe in console mode
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "cmd /K C:\Product\workspace\Product.exe -c -dir C:\ProductDir", 1
Set objShell = Nothing
The parameter 1 : Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position.
The problem which I am facing is I am not able to see the cmd.exe and the Product.exe installer. Though the process explorer shows cmd.exe and Product.exe running. I don't get why I its not running in foreground and only in background.
How can I get the exe to run in foreground?
When I tried running directly on VM, I can see it running in foreground. Cant understand this situation. Any light on this?
Thanks.
Are you running Jenkins slave agent as headless service on windows? I remember in this case the GUI would have problem. You should run the agent with jnlp when you add the slave VM. This works perfect with me.
Here's another way to skin the cat using VBScript.
I experienced the same issue trying schedule a task to launch Internet Explorer into the foreground. I was using WScript's Run method with the 3 window option to force it to be maximized. I just couldn't force it to come up in the foreground.
I FINALLY got that to work with WScript's AppActivate method. The trick was to monitor AppActivate's return value in a loop to ensure the application is fully launched with the correct TITLE before using AppActivate to bring it to the foreground.
AppActivate Method
Here's my example script:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "iexplore.exe https://www.google.com", 3, false
WScript.Sleep 2000
While WshShell.AppActivate("Internet Explorer") = FALSE
WScript.Sleep 1000
Wend
WshShell.AppActivate "Internet Explorer"
WScript.Quit
=========================
Note: AppActivate will choose the closest match for the application TITLE (or process ID, which is not as simple). You don't have to have the complete TITLE. I'm showing "Internet Explorer" here, but I was able to use the TITLE of the web site that I was redirecting to ("Google" would work OK in this example). So, if you don't want to pull up any random instance of an application you may already have open, be as specific as possible. A CMD.EXE TITLE wouldn't be your best bet.
AppActivate works especially well for CMD/COMMAND windows, as (mentioned previously) you can use the TITLE batch file command to specify a unique window title.
I think im late but I did this and it worked:
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "cmd /K C:\Product\workspace\Product.exe -c -dir C:\ProductDir", 0, False Rem 0: run in background, False: exit without waiting process to stop, True to wait for process
Set objShell = Nothing
You can use the .visible property in order to display the applications that are running and bring them to the foreground e.g. objShell.Visible = True
Example below of how I used it when launching an application:
Dim objQtpApp
Set objQtpApp = CreateObject("QuickTest.Application")
'make QTP visible
objQtpApp.Visible = True

Voodoo with DOS Batch files

I've created a simple batch file that kicks off my *.msi installer within our company, creating a log file of the process, then displays the log file after the installer has completed.
installAndLog.bat:
msiexec.exe /i "\\FileServer2\setup.msi" /l*v "C:\setupLog.txt"
"C:\setupLog.txt"
It works, but there are two (2) glitches that annoy me:
The black console box shows in the background the whole time the installer is running and the log file is being displayed. Q1: How do I hide that?
and
The console box will not close until the log file is no longer being viewed (i.e. notepad.exe is closed). Q2: Can I call the text file in a new process and simply exit?
I was a DOS lover back in the day, but that was too many years ago.
I don't think you can hide the console window when running a batch file. However you can use vbscript instead which will by default not create a console window.
Take the below and put it in a file with a .vbs extension:
Dim wshShell
Set wshShell = CreateObject("WScript.Shell")
wshShell.Run "msiexec.exe /i ""\\FileServer2\setup.msi"" /l*v ""C:\setupLog.txt""", 1, true
wshShell.Run "C:\setupLog.txt"
All the double double quotes are there because the entire command must be surrounded by "'s and doubling them escapes them. The the documentation for WshShell.Run for more info.
Q1 - AFAIK you can't really hide the console window.
Q2 - Use the start command. This will launch the specified program (notepad) outside of the shell. It will also prevent the shell from waiting until the application closes to continue processing the batch script.
You might be better off changing the batch script to launch the MSI installer using the start command and having the installer launch notepad to view the log file once installation is complete.
If you really want to get these batch windows away, you'll have to switch over to something else. One simple alternative could be one of the scripting languages supported by the windows scripting host.
Or you try HTA (HTML applications) see here and here.
Run the dos script as a different user by scheduled task or as a service.

how to hide cmd shell window?

on start up i have a bat file run routine things for me
however, the black console pops up and stays open until everything is finished....
anyway to hide it and run it in background ? so it shouldn't appear minimized or system tray.
You can use a VBS script to achieve this. Either write all your code as VBS, or call your batch file like this:
'launch.vbs
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "mybatch.bat", 0
WshShell = Null
Create a shortcut to the file. On the new shortcut: Right click -> Properties. Go to the Shortcut tab, and choose "Run: Minimized." (This is assuming you're on WinXP).
This link should help you as helped me. I used the second solution that uses a program named quiet.exe
To use, just call quiet.exe program params_if_has.
My use example: quiet.exe php script.php
You can't really do that but if you are using the scheduler to run the batch file you can select "don't interact with desktop" when creating the job.
I once had a little program which could hide windows based on their title. So my startup batch first set a unique title with title and then called the other program to hide the window with said title. Worked fine but involves a little programming.
If you don't want to go that way, then you should use the Task Scheduler as tr4656 noted.
Try renaming your file to .cmd instead of .bat.
Or, if you're executing a .exe try:
start "" "C:\Program Files\SomeProg\someprog.exe"
Note: When using "start" you have to be at a command prompt.

Resources