Writing a string in console through VBScript - batch-file

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.

Related

calling bat file using asp classic

Can anyone help me with this problem, i need to call/execute bat file. below are my codes for bat file and asp classic.
test.bat
echo off
start C:\inetpub\wwwroot\Texting\Notification.lnk
That test.bat will run a shortcut and call the application, that will update received file.
sample.asp this code is for classic asp
<%
dim fs,tfile,loc,locadd,loctime1,nameFile,wshell
locadd = Month(Date)&Day(Date)&Year(Date)
loctime1 = stripNonNumeric(FormatDateTime(Now,3))
nameFile = "\\85new\Accts85new\Texting\Reply\Karing\"
loc = "\\85new\Accts85new\Texting\Reply\Karing\"&locadd&"_"&loctime1&".txt"
set fs= Server.CreateObject("Scripting.FileSystemObject")
set tfile=fs.CreateTextFile(loc)
For Each Item in Request.QueryString
tfile.Write Item &";"& Request.QueryString(Item)&"$&$"
next
tfile.close
set tfile=nothing
set fs=nothing
Function stripNonNumeric(inputString)
Set regEx = New RegExp
regEx.Global = True
regEx.Pattern = "\D"
stripNonNumeric = regEx.Replace(inputString,"")
End Function
set wshell = CreateObject("WScript.Shell")
wshell.Run "cmd.exe /c C:\inetpub\wwwroot\Texting\test1.bat"
set wshell = nothing
%>
that sample.asp will get the value of parameters from querystring.
The code is working, no error received when i hit ENTER on the browser.
Thank you in advance!
Typically this should be done in another way, but assuming you understand the security implications of calling bat file from a web application, you need to try to redirect output to a file to ensure it is executed and what is the output, i.e.
wshell.Run "test1.bat>debug.txt"
CreateObject("WScript.Shell") is executed in a separate process and you will not get any error in the browser, that's why your bat file needs to output its result somewhere.

How to generate key strokes from a batch file?

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.

while running batch file command prompt window blink

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

Redirecting shell application output to a file with HTA application

Can someone tell me why redirecting to a file does not work in my HTA program? It contains the following:
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "md5sums.exe", "tarball.tar > .\md5sum.log", , , NORMAL_WINDOW
When I run my HTA program with the two above lines without the redirect it works fine. But the second I add the "> .\md5sum.log", md5sums.exe spits out the following error:
Unable to read file/directory .\md5sum.log
, meaning it's ignoring the redirect symbol and trying to take the checksum of the non-existent md5sum.log file.
md5sums.exe is simply an external checksum program. When I run the following from a command line, it works fine:
md5sums.exe tarball.tar > .\md5sum.log
, piping the checksum for tarball.tar to the md5sum.log file as expected.
I've searched high and low throughout the Interwebs, without finding a solution. I'd greatly appreciate any help anyone can provide.
Finally figured it out! In case anyone runs into this:
shellCmd = "cmd /c md5sums.exe ""tarball.tar"" > ""md5sum.log"""
Set shell = CreateObject("WScript.Shell")
shell.Run shellCmd

Answer a question in a popup window

I have a batch file that I want to use to exicute a .exe file. The exe runs but it pops up a windows needing some information. How can I file in the popup with the correct information? The servername.domain is the server address that needs to be put in the popup. I thought that this was the syntax to populate the popup but its not working. Any help would be great.
SetupCodeGroup.exe servername.domain
i have found that you can not do what you want to do with a batch file. when i ran into a simaler problem i used vbscript sendkeys method. if you google that you should be able to do what you want.
and for your case i would have a batch file as a bass to run the vbscrit program you write to fill in the info in the .exe
somthing like this for the batch
(if you do copy and past this be sure to take out the comments (//) )
#echo off
set reapet=100 // just setting varibles to be used in the delay loop
set con=1
set time=0
start (your .exe) //starts your EXE
:begin
set /a time=%time%+%con%
if %time%==%reapet% goto:startvb // this makes a delay so that we can be sure your
goto:begin // computer fully started the .exe :)
:startvb
cls
start your (vbscript) // this starts your vbscript
cls
echo Done // tells you the batch file is done
pause
i hope this helps.

Resources