I am running my batch file inside my code, it's working fine, I just want to know is there anyway I can stop the blinking of command prompt window.
Try using some VBScript like this.
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("C:\yourbatchfile.bat"), 0, True
Related
I'm working with a java program which is run in cmd. I have a batch file for starting the cmd and running the program. In it I also run a vbs script which is supposed to send keystrokes Alt+Enter, so the running cmd would go to fullscreen mode. However it doesn't seem to work; I tried sending in Alt+F4 and Alt+Tab and both work just fine, Alt+Enter is the only key combination not working for me.
Here's the batch file:
#echo off
title <title>
CMD /C "cscript fullscreen.vbs && cd <path to program> && java <program>"
exit
And here's the fullscreen.vbs script:
Set ws = WScript.CreateObject("WScript.Shell")
ws.SendKeys "%~"
Set ws = Nothing
I need the cmd to go to fullscreen before or after the program starts, but all it does is it hits Enter once the program is running and waiting for input. I also tried "%{ENTER}" instead of "%~" but no success there either. Also, I'm using windows 10, so Alt+Enter for fullscreen is supported and works fine if I do it on the keyboard.
Well I didn't figure out why Alt+Enter ("%~") doesn't work, however I found out that F11 does the trick so that's what I'm using now.
ws.SendKeys "{F11}"
CMD now goes fullscreen before the program starts.
I'm trying to open internet explorer invisibly frim command line. The page I will open log user data for our software. Thats why I want to make it invisible, there is nothing necessary for people on the page.
I tried this,
start iexplore http://www.example.com
it works. However, its visible. (I know there are some working scripts in vbs , shell. But I need to make it from command line) How to make it invisible ?
You can't with batch.
This is a vbs script. Just execute it.
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run """c:\program files\internet explorer\iexplore"" www.google.com", 0, false
I want to create a batch file to do the following:
Start selenium server(webdriver-manager start)
Run Protractor tests(protractor conf.js)
Stop Selenium server()
This needs 2 different command prompts since webdriver-manager start will keep running and simultaneously the tests need to be executed
I have achieved the following so far. I have created a .bat file with the following contents:
start runTests.cmd
webdriver-manager start
Ctrl-C(**DOES NOT WORK**)
However, I am not able to figure out a way to shutdown the Selenium server(which is achieved by pressing Ctrl+C on the same window on which the webdriver-manager start command is executed)
You can generate keystrokes using VB Script, which can be called from a batch file.
I followed this post: http://www.w7forums.com/threads/f5-key-via-batch-file.18046/, substituting {F5} with ^{C} for Ctrl+C. So my file looks like:
Set objShell = CreateObject("WScript.Shell")
objShell.SendKeys "^{C}"
You need to save this file with a ".vbs" extension.
I also found from this answer VBScript - switching focus to window using AppActivate how to set the focus to another window (which you know the title of). Doing this first, you can direct your keystroke to the appropriate window, so:
Set objShell = CreateObject("WScript.Shell")
objShell.AppActivate "Untitled - Notepad"
objShell.SendKeys "^{C}"
I experimented with an empty instance of Notepad, so you'll need to change the window title string appropriately. (Ctrl+C doesn't do anything in Notepad, but Alt+F4 closes it, so I used "%{F4}" to test it.)
Then you can simply call the VBS file from your batch file to run it.
I have a simple batch file in windows that I run on startup that presents the user with a menu to start certain applications. However by default, whenever I open one of these applications the focus goes to that window and off of the batch file. Is there a way to maintain, or re-divert focus onto the batch window?
Thanks
EDIT: Got it to do what I wanted. Used foxidrives suggestion to start them minimized but they were still taking focus. So I made a short VBScript to make the cmd window the active window after each call and the combination of the two worked. Thanks!
There is no command to steal the focus. As Bill_Stewart posted, that would be a dangerous feature that grants the program too much power over the user. You can however start the applications minimized (they will still be the active window), and then build and call a VBScript to make your batch window the active window:
start "" /MIN "application.exe"
cscript /nologo myVBScript.vbs
myVBScript.vbs
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate "myBatchFile"
WScript.Sleep 2000
WshShell.AppActiavte "myBatchFile"
I've read that several people have had trouble with AppActivate on Windows 7. It was not functioning for me, and instead of bringing my target window to the foreground it just blinked in the task bar. Calling it a second time however, for some reason, brought it to the foreground and made it the active window, which is what I wanted. Hope this helps anybody else with a similar issue.
you can't lock the focus to your command prompt window. But what you could do is to set the TopMost flag of the command prompt window. There is a Win32 function called SetWindowPos which does that. Maybe there are some ready to use command line tools around which are doing this for you. Or, if you have visual studio installed, try to compile this one here: How to set a console application window to be the top most window (C#)?
If you use the start command with the /min switch then the application will be minimised and the batch file should remain visible:
#echo off
pause
echo launching notepad
start "" /min notepad
echo notepad is active
pause
I am using the following code snippet
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec(".\lib\example.bat")
During this an empty console is getting opened till example.bat is completing it's process, is it possible to display some text in that console??
I have tried echo in example.bat file but no use.
please help me with it
Though displaying text in the console is not possible using exec, its possible to hide the console window using cscript and it worked.