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.
Related
i want to run a .wav-file. This is with
start "" SoundFile.wav
totally practical. But how can i run the window of the standard-windows-soundplayer minimized? So that nothing of my view changes?
start "" SoundFile.wav /MIN
start "" SoundFile.wav /min
start "" SoundFile.wav -MIN
start "" SoundFile.wav -min
didn't work sadly.
Can you help me?
Greets.
Sorry but i am not familiar with stackoverflow, so i can't make it that understandable, but i hope that this is enough.
In a simple way, you could just use a VBS like this:
s = createobject("WScript.Shell")
s.run "music.mp3", 2
Or create an automatic and CLI program to do this:
runmusic.bat
#echo off
set music=%1
set music=%music:"=%
if ":" neq "%music:~1,1%" set music=%cd%\%music%
if "%music:~-4%" neq ".mp3" set music=%music%.mp3
set katorn=%random%
echo >>"%temp%\%katorn%.vbs" set s = createobject("WScript.Shell")
echo >>"%temp%\%katorn%.vbs" s.run "%music%", 2
cscript "%temp%\%katorn%.vbs"
:: Uncomment the next line to autodelete the vbs file.
:: del /q /f "%temp%\%katorn%.vbs"
Usage:
runmusic (name or full path with quotation marks)
In a "professional way" you could do a shortcut file that starts the file minimized.
It could be useful if you needs the musics to have the "artist logo" or something like that, also if you don't want to use an CMD all the time...
Delete all comments to execute.
Set WshShell = CreateObject ("Wscript.Shell")
strDesktop = "X:\Shortcutlocation\yoo"
Set Shortcut = WshShell.CreateShortcut(strDesktop + "\MusicNameMaybe.lnk")
Shortcut.WindowStyle = "7"
Shortcut.IconLocation = "X:\IconPath\youricon.ico" // You can delete this and the file will be the same ever and forever.
Shortcut.TargetPath = "X:\yourpath\music.mp3"
Shortcut.Save
And you don't have to keep the shortcuts on the desktop if you don't want to, you don't even have to keep them fixed. Example:
runmusic.bat
#echo off
set music=%1
set music=%music:"=%
if ":" neq "%music:~1,1%" set music=%cd%\%music%
set music=%music%.mp3
set katorn=%random%
echo >>"%temp%\%katorn%.vbs" Set WshShell = CreateObject ("Wscript.Shell")
echo >>"%temp%\%katorn%.vbs" strDesktop = "%temp%"
echo >>"%temp%\%katorn%.vbs" Set Shortcut = WshShell.CreateShortcut(strDesktop + "\%katorn%.lnk")
echo >>"%temp%\%katorn%.vbs" Shortcut.WindowStyle = "7"
echo >>"%temp%\%katorn%.vbs" Shortcut.TargetPath = "%music%"
echo >>"%temp%\%katorn%.vbs" Shortcut.Save
cscript "%temp%\%katorn%.vbs"
:: Uncomment the next two lines to delete the temporary files.
:: del /q /f "%temp%\%katorn%.vbs"
:: del /q /f "%temp%\%katorn%.lnk"
echo Enjoy!
Usage:
runmusic (name or full path with quotation marks)
Now that you understand, you can even leave a folder with the songs and the other with just the customized shortcuts, which can come in handy.
Hope this helps,
K.
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.
i´m writing my first batch-file (4 Parameters as Input which are used for FTP) and got a problem now.
I´m using the FTP command and then it has to type in the PARAM3 then Enter and then PARAM4.
I don´t know why it isn´t working. I already tried STRG+M in my Editor, but it´s not typing the word in the command prompt.
#echo off
#REM Sample batch file
SET PARAM1=""
SET PARAM2=""
SET PARAM3=""
SET PARAM4=""
SET PATH1=" "
rem SET /P PARAM1=Enter Hostdatei: %=%
rem SET /P PARAM2=Enter Zielname: %=%
rem SET /P PARAM3=Enter BENZL : %=%
rem SET /P PARAM4=Enter Passwort : %=%
SET PATH1=c:\Users\%PARAM3%
echo %PARAM1%
echo %PARAM2%
echo %PARAM3%
echo %PATH1%
cd %PATH1%
ftp adt0
timeout 5
%PARAM3%
%PARAM4%
pause > nul
#REM Process the params
That's not how it works: in a batchfile you don't do:
command
parameter1
parameter2
simulate_pressing_enter
But you do:
command parameter1 parameter2
(Pressing ENTER is simulated automatically)
I have sql files in a folder structure like the following :
C:\Users\Peter\Desktop\SQL_FILES\data_structure\customer1\test.sql
C:\Users\Peter\Desktop\SQL_FILES\data_structure\customer2\test.sql
C:\Users\Peter\Desktop\SQL_FILES\data_structure\customer3\test.sql
C:\Users\Peter\Desktop\SQL_FILES\data_structure\customer4\test.sql
........
I want to make a script which reads the path (C:\Users\Peter\Desktop\SQL_FILES),
the name of the file(test.sql) and a text
and then concatenate the text in the end of each test.sql file.
Could you help me please ?
Thanks in advance
:: Hide Command and Set Scope
#echo off
setlocal EnableExtensions
mode 140,50
set /p AbsolutePath="Enter the path of root folder :"
echo.
set /p FileName="Enter the filename with it's extension (ie. test.sql):"
echo.
echo Enter your inserts
echo Press Enter twice when finished
echo (text may not contain ^<, ^>, ^|, ^&, or un-closed quotes)
ver > NUL
set new_line=""
:still_typing
set /p new_line=">"
if errorlevel 1 echo. >> temp.txt & set /p new_line=">"
if errorlevel 1 echo Sending message. . . & goto done_typing
echo %new_line% >> temp.txt
goto still_typing
:done_typing
echo done
:End
endlocal
pause >nul
=====================================
For example :
The file test.sql for example contains initially :
INSERT INTO TEST(COL1,COL2,COL3) VALUES(3,4,5);
And after the execution of batch supposing I add an empty line and two inserts in the text :
INSERT INTO TEST(COL1,COL2,COL3) VALUES(3,4,5);
INSERT INTO TEST(COL1,COL2,COL3) VALUES (1,2,3);
INSERT INTO TEST(COL1,COL2,COL3) VALUES (2,3,4);
The Batch file below use a different method to do the same, but in a simpler way. This code may be modified in any point you wish; for example, if you want not that the filename must include a wild-card.
#echo off
setlocal
set /p "AbsolutePath=Enter the path of root folder: "
echo/
set /p "FileName=Enter the filename with a wild-card (ie. test*.sql): "
echo/
echo Enter your inserts
echo Press Ctrl-Z and Enter when finished
copy CON temp.txt > NUL
echo/
echo Typing done
echo/
for /R "%AbsolutePath%" %%a in (%FileName%) do type temp.txt >> "%%a"
I running Windows 10 and I can't execute a script shell in .bat
So, my code is:
#echo off
echo .
echo MsgBox "TA MERE"
echo .
echo MsgBox "Salut ca va?"
> msgbox.vbs
cscript msgbox.vbs
loop
So, my script is running but the script do not create msgbox.vbs file on the desktop and the program close the Windows
This is a guess based upon what I think your script is supposed to do:
#echo off
( echo.
echo MsgBox "TA MERE"
echo.
echo MsgBox "Salut ca va?"
)> msgbox.vbs
cscript msgbox.vbs
I've missed out loop because I don't know where you want to loop to.
You can try something like that :
#echo off
REM We create our vbs file in temporary folder
REM If you want to create your vbs file on your desktop
REM Just Replace this line set "VBSFile=%Tmp%\%~n0.vbs" to
REM set "VBSFile=%userprofile%\desktop\%~n0.vbs"
set "VBSFile=%Tmp%\%~n0.vbs"
(
echo MsgBox "TA MERE TOI MEME LOL !",vbExclamation,"TA MERE TOI MEME LOL !"
echo MsgBox "Salut Comment ca va ?",VbQuestion,"TA MERE TOI MEME LOL !"
)> "%VBSFile%"
REM We execute our vbs file
cscript /nologo "%VBSFile%"
REM We Clean our vbs file
Del "%VBSFile%"