1.

Solve : Creating a batch file with commands in programs?

Answer»

Im new to this forum, so this might have been posted already. I was wondering how to make a batch file perform tasks inside programs. Its for a project which involves creating a batch file that opens sndrec32.exe and then telling the program to start recording. If its at all possible i would like to be able to minimize it to the system tray. Thanks in advance!. you cannot do this in batch, atleast not using the standard commands if you want to create a batch file wrapper for a .vbs file then its possible, check out wsh.sendkeys google itYah ok i did that, but theres nothing very clear on it. Btw did i tell you im a noob, so i need like VERY clear instructions cuz im new at .bat and .vbs files. I know basic sort of.Ok

first ill explain wsh.sendkeys, to open a new instance of sndrec32.exe you would use the following


set oShell = CreateObject("WScript.Shell")
oShell.run"sndrec32.exe"
WScript.Sleep 500
oShell.SendKeys" "


If you paste the above into notepad.. go to save, save it as all files TYPE and something.vbs , double click something.vbs and it will open sndrec32.exe and send a space bar , oShell.SendKeys" " When i open'd sndrec32.exe a minute ago, spacebar was the first key i pressed and it started recording, so the above will work

the first line is set oShell = CreateObject("Wscript.shell") , oShell is the VARIABLE and can be anything , the second line oShell.Run"sndrec32.exe" will open sndrec32.exe , YourVariable.Run"sndrec32.exe" so if you set CreateObject("Wscript.shell") as YourVariable , You could instead type YourVariable.SendKeys" " , Ok the third line.. Wscript.Sleep 500 , this causes the script to sleep for 500 millaseconds before sending the spacebar to sndrec32.exe , You need to cause the script to sleep inbetween Sending another key, because the Script may operate to fast and malfunction .. (Im Guessing this is the reason) But it will malfunction without it.. so anyways the final line, oShell.SendKeys" " , this will send the spacebar charachter to sndrec32.exe , when you take a look at sendkeys and the list of what charachters are accepted you wont see a space, because its just a blank space...

so now you want to add this to a batch file, Here is an example:

@ECHO off
set a=%temp%\sendkeys.vbs
echo set oShell = CreateObject("WScript.Shell")>%a%
echo oShell.run"sndrec32.exe">>%a%
echo WScript.Sleep 500>>%a%
echo oShell.SendKeys" " >>%a%
%a% & del /q /f %a%

ok on the first line i set %temp%\sendkeys.vbs witch is the file name as a " %a%"
On the second line i added the first line into the file with the variable , using > this is called appending to a text file, using a single redirection charachter > will add a single line and re-write any other line, so if you want to add multiple lines.. then you use two of them >> as you will notice on the FOURTH line.. this causes the text to be echo'd into the file, without rewriting everything else.. ECHO echos text on the screen.. if you dont understand open a new instance of cmd.exe , and type Echo testing and it will OUTPUT "testing" , the rest is strait forward untill the last line , %a% & del /q /f %a% , %a% a is the variable of the .vbs file, so when you type %a% its the equivilent of %temp%\sendkeys.vbs , so it starts the script in otherwords.. right after it is an ampersand , then it uses del (DELETE) , so after the script is executed , it deletes the script file.. /q is for quiet mode , and /f is for force .. so in otherwords it wont ask you "are you sure you want to delete this file"



Discussion

No Comment Found