I am trying to find a way to adjust the window that opens while you are running a batch file WITHOUT using 3rd party programs. I have adjusted the size and color of it, but would like to move the window to the top left corner of the screen. This also has to be self contained in the batch file it self(not right-clicking on title bar and changing the settings of window position that way).
So for example, I have a batch file that opens, you answer the questions it asks then it opens the required program to finish the tasks(such as logging you into putty). But then, I would like the batch window to move to top left(already adjusted size and color to make it more noticeable) so it's easier for the user to click on it to see the "codes" I added to it to use in putty.
This is going to be distributed to multiple users and we can't add 3rd party programs and I don't want to have to explain to everyone how to adjust how the window opens, I just want it to always open top left(no matter how the computers are set up).
Lastly, all PCs are running Windows 7 and thanks in advance for the help!
Run the batch file from Start-Run:
set title=COMMAND PROMPT
reg add "hkcu\console\%title%" /v WindowPosition /t REG_DWORD /d "0" /f
start "%title%" cmd "%~f0 %title%"
exit /b
Related
First off, I am not a "Programmer/Coder" Please do not flame me for asking a question that might be on here somewhere else that I could not find.
I found a registry modification to change the behavior of the calculator button my laptop. The original behavior was that each time I pressed that key a new instance of the calculator would appear. I wanted it to just bring focus to the same instance. I found the following registry key to add that sort of works. (Note: I have both the new and old style of calculator on my machine. Calc.exe is the new one, calc1.exe is the older Win2k/XP style one)
This is the exported Reg file:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\18]
"ShellExecute"="cmd.exe /c (tasklist /FI "IMAGENAME eq Calc1.exe" | find ".exe" >nul 2>nul &if not errorlevel 1 exit) &start "w" calc1.exe"
Now, when I press the calculator key, the calculator launches anew when pressed, and if it is already running the computer switches to it rather than launching another instance, which is what I want, BUT I need it to be on top of everything else on the desktop and other apps even if one of them is full screen. What additional commands are necessary to force it to be on top?
I also had found a batch file that does not seem to do anything, that is here:
#set #v=1 /* &echo off &title Calc single instance from media key
set "calckey=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\AppKey\18"
reg add "%calckey%" /v ShellExecute /d "wscript.exe /e:JScript "%~f0"" /f &exit */
calc=GetObject("winmgmts://./root/CIMv2").ExecQuery("Select * from Win32_Process WHERE Name LIKE 'Calculator.exe'")
shell=WSH.CreateObject("WScript.Shell"); if (calc.Count>0) shell.AppActivate("Calculator"); else shell.Run('calc',1,'False');
This is What I want to see
What I get is calulator opening but hidden from view, can get to it from full screened app with alt-tab but that defeats the purpose. I simply want the calc to be started up always on top with focus on it.
Here's the thing: There's an exe file to stamp on PDF through command line.
the file is from this website:
pdfmachine-command-line-tools
and this is the link to download the exe file:
pdfMachineStamp
PREVIOSULY:
I paste both the downlaoded 'pdfMachineStamp.exe' from the website, and also paste my 'prueba.pdf' (PDF file to stamp) here, manually:
C:\PDF
HOW THE EXE WORKS?:
Then I go to run MANUALLY on the System Symbol:
C:\PDF>pdfmachinestamp.exe /f prueba.pdf /t "This is the Stamp" /pos center /size 15 /rot 45 /color black /opacity 1
and it runs perfect!
My 'prueba.pdf' ends with a stamp in the center of the page rotated 45 degrees saying "This is the Stamnp".
THE PROBLEM:
NOW, I want to create a batch file to do that with a single click... but I'm new in this, and I'm stuck...
I dont' know if i have to edit the bat file with START,RUN, CD, or... ????
Then I tried
start /d "C:\PDF\pdfMachineStamp.exe" /f prueba.pdf /t "PRUEBA REAL" /pos center /SIZE 25 /rot 45 /color black /opacity 1
PAUSE
and it won't work.
Any ideas?
Thanks!
There is no need to use start or call for your purposes.
Instead you simply put the command you want there.
If you plan to keep the batch fine in the same folder as the prueba.pdf and pdfmachinestamp.exe than you can use this shorthand %~dp0 to specify the path to C:\PDF\, this is because %0 is the '0th' argument of the script,, and used to hold the full path and file name of the current script (and the current label within the script if within one.) and ~dp selects just the drive (d) and path (p); to the script from the %0 variable.
Therefore this should do the needful
#Echo off
"%~dppdfMachineStamp.exe" /f "%~dpprueba.pdf" /t "PRUEBA REAL" /pos center /SIZE 25 /rot 45 /color black /opacity 1
PAUSE
You can double click this cmd script or a shortcut to the script and it should run as expected.
However, make sure you have named it scriptname.cmd if you use notepad change the type to any instead of before saving and remove .txt from the end.
Also make sure "hide file extensions for known file types" is turned off in explorer (which is on my default) as windows will hide the ".Txt" at the end of the file if present, so you can be sure it is named correctly.
I honestly didn't have idea how to make it right, but after playing a little bit and some other research in this matter i found a solution that did exactly what i want easily.
This is the script:
start "" "C:\PDF\pdfMachineStamp.exe" /f "C:\PDF\prueba.pdf" /t ""PRUEBA_REAL"" /pos center /size 30 /rot 45 /color green /opacity 1
I decided to use start "" to begin the command line, and had to use the double quotes to highlight the names of both files (the exe and the pdf). Also, I used the full path for both. for the Stamp text, I had to use double-double quotes and avoid spaces (replaced by _). and that's it.
Thanks everybody!
I hope this is useful for somebody in the future.
I have a simple batch file in windows that I run on startup that presents the user with a menu to start certain applications. However by default, whenever I open one of these applications the focus goes to that window and off of the batch file. Is there a way to maintain, or re-divert focus onto the batch window?
Thanks
EDIT: Got it to do what I wanted. Used foxidrives suggestion to start them minimized but they were still taking focus. So I made a short VBScript to make the cmd window the active window after each call and the combination of the two worked. Thanks!
There is no command to steal the focus. As Bill_Stewart posted, that would be a dangerous feature that grants the program too much power over the user. You can however start the applications minimized (they will still be the active window), and then build and call a VBScript to make your batch window the active window:
start "" /MIN "application.exe"
cscript /nologo myVBScript.vbs
myVBScript.vbs
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate "myBatchFile"
WScript.Sleep 2000
WshShell.AppActiavte "myBatchFile"
I've read that several people have had trouble with AppActivate on Windows 7. It was not functioning for me, and instead of bringing my target window to the foreground it just blinked in the task bar. Calling it a second time however, for some reason, brought it to the foreground and made it the active window, which is what I wanted. Hope this helps anybody else with a similar issue.
you can't lock the focus to your command prompt window. But what you could do is to set the TopMost flag of the command prompt window. There is a Win32 function called SetWindowPos which does that. Maybe there are some ready to use command line tools around which are doing this for you. Or, if you have visual studio installed, try to compile this one here: How to set a console application window to be the top most window (C#)?
If you use the start command with the /min switch then the application will be minimised and the batch file should remain visible:
#echo off
pause
echo launching notepad
start "" /min notepad
echo notepad is active
pause
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.
I have a batch file, this batch file will not start automatically, it will only run when i double click on it.
Can I run the batch file in the background when I double click on it.
Well, you can start it minimized with start, if that is enough. Really hiding it is difficult (although I can think of an option right now).
Basically you need to determine whether the batch has been started by double-clicking it. You can do this by defining a special variable and look for it:
#echo off
if not defined FOO (
set FOO=1
start /min "" %~0
exit /b
)
rem here whatever you wanted to do originally in the batch
As long as the FOO variable isn't defined (which is probably the default almost everywhere), this batch will launch itself minimized again, but with the variable defined first. Environments are passed to subprocesses, which is why this works.
you would generally need something else to run the script in that manor
i.e.
Create a shortcut, and set the “Run” field for the shortcut to “Minimized’.
Once you click or tab away from the cmd.exe window that the batch file is running it, it's "in the background" -- I'm not really sure what you want but it sounds like you might be asking how to run the batch file without displaying the cmd.exe window.
If so I can think of two ways: first, you can create a shortcut to the batch file, right click it, and in the properties there set the shortcut to run minimized (should be a drop down option next to Run).
You can also wrap invocation of the batch file in a VBScript file using Windows Script Host's shell object (calling the Run method) to run the batch file invisibly. Passing 0 as the intWindowStyle parameter will suppress display of a window or anything.
#Ghyath Serhal
I have used cmdow to do this on another program, it is an external application that can be used to modify the command prompt. To use it, you will need to either enter this code (see below) into it's own batch file, or into the command prompt, where it will run 'BatchFile.bat' with a hidden terminal window. I haven't found a way to use this in a single batch file, but I only found out about this today.
cmdow /run /hid 'BatchFile.bat'
Hope this helps.