Calling two scripts from batch file run asynchronously - batch-file

I have batch file which gets user input, tranfers the input to a vb script.
set /p "whichPort= Which port do you want to reset:"
start /b "" cscript.exe //NoLogo loginInXyplex.vbs /portname:"%whichPort%"
Then a telnet session is exceuted from within the batch file, followed by the exection of the same script file in order to issue commands in the telnet session.
telnet.exe 192.120.187.35 2000
REM run the script
cscript loginInXyplex.vbs
When in the telnet session it appears the two scripts are running at the same time as the conmmands are out of synch so cannot log on properly
This is my first vb script so I could be missing somethong obivious, so i have included all source code :
Batch File:
#echo off
cls
echo.
echo Welcome to Xyplex Server Port Reset
echo.
pause
echo.
set /p whichXplex= Which Xyplex server is your device connected too: 1 or 2 ?
echo.
set /p "whichPort= Which port do you want to reset:"
echo Sending port "%whichPort%" to script file
echo.
pause
rem send using strat /b so we open script file on same command line window
start /b "" cscript.exe //NoLogo loginInXyplex.vbs /portname:"%whichPort%"
echo.
echo Conencting to Xyplex "%whichXplex%"
pause
if "%whichXyplex%" == "1" (
REM COnnecting to xyplex one IP:Socket
echo.
echo Connecting to Xpyplex %whichXyplex%...
telnet.exe 192.120.187.35 2000
REM run the script
cscript loginInXyplex.vbs
) ELSE (
rem ^ missing spaces in )ELSE(
echo Conencting to xyplex %whichXyplex%....
telnet.exe 193.120.187.245 2000
REM run the script in same widow wuth start /b
cscript loginInXyplex.vbs
)
Script:
set OBJECT=WScript.CreateObject("WScript.Shell")
OBJECT.SendKeys"{ENTER}"
OBJECT.SendKeys "access{ENTER}"
WScript.sleep 50
OBJECT.SendKeys "access{ENTER}"
OBJECT.SendKeys "SET PRIV{ENTER}"
OBJECT.SendKeys "system{ENTER}"
OBJECT.SendKeys "sh po all{ENTER}"
OBJECT.SendKeys "{ENTER}"
' source heer: http://stackoverflow.com/questions/21013428/pass-variable-from-batch-to-vbs
port = WScript.Arguments.Named.Item("portname")
OBJECT.SendKeys port
OBJECT.SendKeys "Port number selected is: " & port
OBJECT.SendKeys "{ENTER}"
OBJECT.SendKeys "Port reset....logging off...{ENTER}"
OBJECT.SendKeys "SET NOPRIV {ENTER}"
Wscript.Sleep 1000
OBJECT.SendKeys "Quit"
Any help appreciated.

Related

vbscript opens mp4 in wmplayer, but only audio plays

I'm trying to simply open a video in full screen using a batch file, I realised this wasn't possible so I included code to make it write to vbscript instead and then later on execute the vbscript code.
I'm running windows 10, and I have another script running an mp3 file that works fine.
This is what my batch file is writing to the vbscript
set "file2=res\FORTNITESKINS.mp4"
( echo Set wmp = CreateObject("WMPlayer.OCX"^)
echo Video.URL = "%file2%"
echo Video.Controls.play
echo do while Video.currentmedia.duration = 0
echo wscript.sleep 100
echo loop
echo wscript.sleep (int(Video.currentmedia.duration^)+1^)*1000
echo set WshShell = WScript.CreateObject("WScript.Shell"^)
echo WScript.Sleep 1000
echo WshShell.SendKeys "%{ENTER}") >video.vbs
This is how I execute the vbscript
start video.vbs
The video does not open, only the audio plays, and wmplayer doesn't even open minimized, nor can I find it in task manager.
I have also tried this,
set "file2=res\FORTNITESKINS.mp4"
( echo Set Video = CreateObject("WMPlayer.OCX"^)
echo Video.openPlayer("%file2%"^)
echo set WshShell = WScript.CreateObject("WScript.Shell"^)
echo WScript.Sleep 1000
echo WshShell.SendKeys "%{ENTER}") >video.vbs
but it gives the error:
Line: 2
Char: 1
Error: 0xC00D1329
Code: C00D1329
Source: (null)
Why don't you use wmplayer directly with proper command-line-parameters ?
#Echo off
set "file2=res\FORTNITESKINS.mp4"
set wmplayer="%ProgramFiles(x86)%\Windows Media Player\wmplayer.exe" /prefetch:1
%wmplayer% "%file2%" /fullscreen
You can do it like this example :
#echo off
Mode 70,3 & color 0B
echo(
Set "Title=Playing videos with Windows Media Player"
Title %Title%
echo %Title%
Set "URL-FILE=http://1290922571.rsc.cdn77.org/movies/Superman-Unbound-2013-FRENCH.mp4/playlist.m3u8"
Start "%Title%" wmplayer /fullscreen "%URL-FILE%"
Timeout /T 2 /NoBreak>nul
EDIT :
#echo off
Mode 70,3 & color 0B
echo(
Set "Title=Playing videos with Windows Media Player"
Title %Title%
echo %Title%
Set vbs_video=%temp%\vbs_video.vbs
Set video=http://1290922571.rsc.cdn77.org/movies/Superman-Unbound-2013-FRENCH.mp4/playlist.m3u8
Call :Play %video%
Timeout /T 2 /NoBreak>nul & Exit
REM ***************************************
:Play <video>
(
echo Set Video = CreateObject("WMPlayer.OCX"^)
echo Video.openPlayer("%~1"^)
echo set WshShell = CreateObject("WScript.Shell"^)
echo WScript.Sleep 3000
echo WshShell.SendKeys "%%{ENTER}"
)>"%vbs_video%"
Start "video" "%vbs_video%"
exit /b
REM ***************************************
set "file2=F:\ull\path\to\res\FORTNITESKINS.mp4"
You must enter the full path to the file for the script to work. Including the drive letter and the path to the current folder.

Execute specific vbs file from batch file

Batch content:
echo Set wshShell =wscript.CreateObject("WScript.Shell")>"C:\Users\Riccardo\Desktop\prova.vbs"
<nul set /p =wshshell.sendkeys ^"^<nul set ^/p ^=>>"C:\Users\Riccardo\Desktop\prova.vbs"
Type "C:\Users\Riccardo\Desktop\prova.txt">>"C:\Users\Riccardo\Desktop\prova.vbs"
echo {bs}^>^"^"C:\Users\Riccardo\Desktop\prova.txt^"^"{enter}^">>"C:\Users\Riccardo\Desktop\prova.vbs"
wscript "C:\Users\Riccardo\Desktop\prova.vbs"
The vbs generated is:
Set wshShell =wscript.CreateObject("WScript.Shell")
wshshell.sendkeys "<nul set /p =La#{bs}>""C:\Users\Riccardo\Desktop\prova.txt""{enter}"
The prova.txt contains:
La#
After execute this line from new command prompt session:
wscript "C:\Users\Riccardo\Desktop\prova.vbs"
The prova.txt becomes
La
But if execute the same line as above from batch:
wscript "C:\Users\Riccardo\Desktop\prova.vbs"
nothing happens!
How can I fix the problem?
Try to call the script like so:
C:\Users\Riccardo\Desktop\prova.vbs
If that doesn't work, change directory to your desktop, and call the vbs:
cd C:\Users\Riccardo\Desktop\
prova.vbs
That should work in a batch file.
I am solved the my problem. The "Prova.bat" code is:
echo Set wshShell =wscript.CreateObject("WScript.Shell")>prova.vbs
echo wshShell.Run "cmd">>prova.vbs
echo WScript.Sleep 250>>prova.vbs
<nul set /p =wshShell.sendkeys ^"^<nul set ^/p ^=>>prova.vbs
Type prova.txt>>prova.vbs
<nul set /p ={bs}^>prova.txt{enter}exit{enter}^">>prova.vbs
wscript prova.vbs
DEL /q prova.vbs 2> NUL
The "Prova.vbs" generated and deleted is:
Set wshShell =wscript.CreateObject("WScript.Shell")
wshShell.Run "cmd"
WScript.Sleep 250
wshShell.sendkeys "<nul set /p =La#8{bs}>prova.txt{enter}exit{enter}"
The "Prova.txt" before:
La#8
The "Prova.txt" now:
La#
I am found the way of insert backspace character in a txt file using bat+vbs file! ;-) I hope that such a solution can be of help to someone else.

Running Tracert command 140 times in 1 command with different hosts

So i want to run the tracert command, but my problem is that the destination changes (tracert world1.runescape.com > tracert world140.runescape.com )
So my question is, how do i add the variable so it will change from 1 all the way to 140.
Try with this code :
#echo off
for /l %%# in (1,1,140) do (
echo TraceRoute for world%%#.runescape.com
echo.
Tracert world%%#.runescape.com
)
pause
And if you like to store the result into a text file :
#echo off
Color 0A & Mode con cols=80 lines=3
Set LogFile=Traceroute.txt
If Exist %LogFile% Del %LogFile%
for /l %%# in (1,1,140) do (
echo TraceRoute for world%%#.runescape.com
Cls
Title Tracert world%%#.runescape.com
echo(
echo Please Wait... TraceRoute to world%%#.runescape.com in progress...
Tracert world%%#.runescape.com >> %LogFile%
)
pause
So you are looking to keep doing tracert 140 times. This code might help but It keeps on going until you close the batch file. Good Luck!!!
tracert world140.runescape.com
call tracert.bat
When you did the code, save the batch file as tracert.bat and open it. It will keep on going untill you close the window. Enjoy and Please Like!!!

Using Batch file and VBS to change an IP

I have equipment that comes with a default ip address that I need to change via telnet.
The new ip will always be the same except for the last two octets.
I currently access the equipment with a batch file that call on a .vbs
#ECHO OFF
:: Get Hub IP
set /p input1="Enter Hub and press ENTER "
set /p input2="Enter Shelf and press ENTER "
#ECHO OFF
::Run script to Set IP Address
start telnet.exe 10.230.%input1%.%input2%
cscript SetIPAddress.vbs .
echo "DONE!"
pause
HERE IS THE VBS
set OBJECT=WScript.CreateObject("WScript.Shell")
WScript.sleep 1000
OBJECT.SendKeys "admin{ENTER}"
WScript.sleep 1000
OBJECT.SendKeys "admin{ENTER}"
WScript.sleep 1000
OBJECT.SendKeys "configure{ENTER}"
WScript.sleep 2000
This works fine
What I need is to add something like this
#ECHO OFF
SET /p paramA=Hub:
SET /p paramB=Shelf:
ECHO set interfaces eth0 10.230.%paramA%.254 mask 255.255.255.0 gateway 10.230.%paramA%.254
PAUSE
This also works fine but I’m not sure how to get it to send to the command prompt.
Can it be added to the .vbs or can the elements of the .vbs be added to the batch file?

How to create batch file which opens an website e.g. gmail.com and enters user name and password

i need to create a batch file which opens a website(gmail) and enters username and password.
so can anyone help me please..
Thank you.
here is the code i tried.. It opens gmail, now how can i enter username and password.
saved as Test.bat
#echo off
start /d "C:\Program Files\Internet Explorer" IEXPLORE.EXE https://gmail.com
Won't let me comment, but I agree the batch is the wrong way to do this. You could do this with PowerShell though.
add-type -AssemblyName microsoft.VisualBasic
add-type -AssemblyName System.Windows.Forms
#Loads Website
C:\Progra~1\Intern~1\iexplore.exe -k http://www.gmail.com
#Enter Credentials
[System.Windows.Forms.SendKeys]::SendWait("userid{TAB}password{enter}")
You cannot do this. You can open a specific url, but you cannot enter values in a form.
You can open an e-mail adress from the command prompt, but that will open the default e-mail client, and not some webmail page. So unfortunately, it's not possible.
I don't think there's a purely-batch way of achieving your goal.
You may try to write something up, using, for example, http://jsoup.org/ . But you'll need to change your code every time there's a new specification on the page.
This can be done with Selenium. You need to write a simple Selenium JUnit test in Java. Of course, this requires that Java be installed on the computer. It would be about 20-30 lines of code. Then, you can execute the JUnit test from a batch file like so:
#ECHO off
SET username=me
SET password=mypassword
java -cp MyGmailTest.class MyGmailTest %username% %password%
timeout 10
Use selenium's firefox WebDriver with java.
http://docs.seleniumhq.org/download/
Import all the necessary webDriver librarys, and it will very simple. Something like this:
public class checkEmail{
public static void main(String args[]){
WebDriver driver = new FirefoxDriver();
driver.get("www.gmail.com");
driver.findElement(By.id("Email")).sendKeys("your usernamne");
driver.findElement(By.id("Passwd")).sendKeys("your password");
driver.findElement(By.id("signIn")).click();
}
}
get the .class files, then make a simple batch file
#ECHO OFF
set CLASSPATH= (wherever your selenium jars are)
cd C:\where ever the class file is
java checkEmail
WITH FIREFOX:
#echo off
set command=C:\Users\%USERNAME%\Desktop\GMAIL.VBS
start https://gmail.com
echo Set objShell = WScript.CreateObject("WScript.Shell") > %command%
echo Set WshShell = WScript.CreateObject("WScript.Shell") >> %command%
echo Do Until Success = True >> %command%
echo Success = objShell.AppActivate("Mozilla Firefox") >> %command%
echo Loop >> %command%
echo WshShell.SendKeys "USERNAME HERE" >> %command%
echo WshShell.SendKeys "{TAB}" >> %command%
echo WshShell.SendKeys "[PASSWORD HERE] >> %command%
echo WshShell.SendKeys "{ENTER}" >> %command%
ping 192.0.2.2 -n 1 -w 5000 > nul
start %command%
ping 192.0.2.2 -n 1 -w 1000 > nul
del %command%
exit
chance [USERNAME HERE] AND [PASSWORD] { with the [ ] }
WITH GOOGLE CHROME
#echo off
set command=C:\Users\%USERNAME%\Desktop\GMAIL.VBS
start https://gmail.com
echo Set objShell = WScript.CreateObject("WScript.Shell") > %command%
echo Set WshShell = WScript.CreateObject("WScript.Shell") >> %command%
echo Do Until Success = True >> %command%
echo Success = objShell.AppActivate("Google Chrome") >> %command%
echo Loop >> %command%
echo WshShell.SendKeys "USERNAME HERE" >> %command%
echo WshShell.SendKeys "{TAB}" >> %command%
echo WshShell.SendKeys "[PASSWORD HERE] >> %command%
echo WshShell.SendKeys "{ENTER}" >> %command%
ping 192.0.2.2 -n 1 -w 5000 > nul
start %command%
ping 192.0.2.2 -n 1 -w 1000 > nul
del %command%
exit
chance [USERNAME HERE] AND [PASSWORD] { with the [ ] }
#if (#CodeSection == #Batch) #then
#echo off
rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"
%SendKeys% "{ENTER}"
goto :EOF
#end
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
While i myself am still experimenting and testing this batch file program on different applications, i am not sure as to the inner-workings of what this program actually does. All i know is it uses a java script installed on every windows computer to push keyboard commands to be executed. However in my experimentation i found that it could also serve as a means to fill in passwords and usernames.
#if (#CodeSection == #Batch) #then
#echo off
rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"
START FIREFOX "WWW.EXAMPLE.COM"
rem the script only works if the application in question is the active window. Set a timer to wait for it to load!
timeout /t 5
rem use the tab key to move the cursor to the login and password inputs. Most htmls interact nicely with the tab key being pressed to access quick links.
%SendKeys% "{TAB}"
rem now you can have it send the actual username/password to input box
%SendKeys% "username{TAB}"
%SendKeys% "password{ENTER}"
goto :EOF
#end
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
check this

Resources