I would like to know how to start a batch file minimized without creating a shortcut.
I also want the code on how to relaunch a batch file minimized without using a VBS
So if anyone knows how to start the batch file minimized from the first launch that would be great.
try with this and this:
#echo off
echo self minimizing
call getCmdPid.bat
call windowMode.bat -pid %errorlevel% -mode minimized
echo --other commands--
pause
By adding some powershell
#echo off
echo This batch will minimize and return to normal in 5 second intervals.
timeout /t 5 >nul
powershell -window minimized -command ""
timeout /t 5 >nul
powershell -window normal -command ""
echo and We're back..
if you want to use nothing other than batch, then the wrong way, as we do not really start batch files, would be:
start "" /min "batchfilename.cmd"
If you run this from another batch file, that batch file will remain open, unless you exit it. So in order to run it in your actual batch file, it would be something like:
echo Hello!
if not DEFINED IS_MINIMIZED set IS_MINIMIZED=1 && start "" /min "%~0" %* && exit
timeout /t 10
exit
The timeout here just gives you some time to see the window running minimized.
Related
I would like to start 3 commands in the same window.
For now I have this batch but there are 3 different windows at each command.
start /d "c:\Program Files\myfolder" cmd /k cscript A
timeout /t 6 >nul
start /d "c:\Program Files\myfolder" cmd /k cscript B
timeout /t 6 >nul
start /wait /d "c:\PProgram Files\myfolder" cmd /k cscript C
What should I modify to have only one window? thanks
I think you can run a .bat file by changing the directory like so, cd C:\PATH\TO\DIRECTORY\WITH\FILE, then use call (file name here). This should work assuming that all the files are in the same directory, if not you'll just have to change the directory for each call method. If my code doesn't seem very helpful, check this page out https://superuser.com/a/1062322
Example Code
#echo off
cd PATH\TO\FILE\DIRECTORY
call FILE NAME
echo The file (file name here) has run!
pause
this code will make a call to the file and pause the terminal to keep it opened. You can take this code and make as many calls/cd's as you like. I hope this helped, If it doesn't work, please tell me what doesn't work and I'll try to fix it. Have a nice day :)
I have created login script using batch file. But actually I need this batch runs invisible (but still showing on the task manager).
As far that I can go is that I only able to minimize the batch file using below code:
if not "%minimized%"=="" goto :minimized
set minimized=true
start /min cmd /C "%~dpnx0"
goto :EOF
:minimized
#echo off
echo *Logon Script*
rem :Time_Set
rem echo Setting the system time...
rem net time \\EX001LT /set /y
rem echo.
I have tried using cmd /c "batchfile" and didn't work.
You can use vbs to hide the batch completely. Add the path to the logon script to MyScript.Run line.
Hidden.vbs
Set MyScript = CreateObject("WScript.Shell")
MyScript.Run "C:\path to batch\logonscript.cmd", 0, False
Then simply call the Hidden.vbs file instead of the batch file
So I am working on a project where I need to start another batch file, Task Options.bat from this batch file, Task.bat in the same directory, but not close or pause the original file, so this is the script of Task.bat
#ECHO off
TITLE Task
START /D %~dp0 "Task Options.bat"
:loop
TASKLIST /FI "MEMUSAGE gt 20000"
timeout 10 >nul
cls
goto loop
Other lines are irrelevant but the third line of code: When I run the file, it just opens a blank cmd window that titled "Task Options.bat". There are codes in the Task Options.bat file so if it is being ran it would output something. So where I did wrong?
Try this:
#ECHO off
TITLE Task
START "Task Options" /D "%~dp0" %ComSpec% /k "Task Options.bat"
:loop
TASKLIST /FI "MEMUSAGE gt 20000"
timeout 10 >nul
cls
goto loop
Note that you may want to change the /k to /c if you want the Options window to go away after the options.bat script runs. Use /k until you've got all the bugs worked out.
Your version did not work because you had the command line arguments all mixed up. This sets the console window title to Options, the starting directory path to the same directory the script is in, uses the %COMSPEC% variable to find the correct cmd.exe file and hands it the Options.bat script file name to execute.
I have a handful of batch files running at users' login via GPOs and a couple of them that create text/batch files with various info are exhibiting odd behavior. Specifically, these batches run at login are echoing the same value(s) multiple times into the target files. As an example:
ECHO #echo off > \\server\share$\%username%.bat
ECHO set minimized=true >> \\server\share$\%username%.bat
ECHO start /min cmd /C "path-to-program" %computername% >> \\server\share$\%username%.bat
Seems pretty straightforward, right? Yet this batch is producing a file that contains:
#echo off
set minimized=true
start /min cmd /C "path-to-program" computer
start /min cmd /C "path-to-program" computer
This isn't my only .bat doing this, but it's all the same concept - echoing a bunch of info into a file and somewhere along the way it's as if parts of it are getting run multiple times.
Has anyone seen this before and/or have any suggestions as to what could be going on?
Try like this :
(ECHO #echo off
ECHO set minimized=true
ECHO start /min cmd /C "path-to-program" %computername%)>"\\server\share$\%username%.bat"
This is my .bat. All is working fine, except i see the black window on my screen while the countdown is taking place...
#echo off
timeout /nobreak /t 8 > nul
start /d "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Skype\" Skype.lnk
exit
Ps: /min doesn't work, skype doesn't start minimized even if i right click on the skype.lnk in the program files and set there start as minimized.
Thank you in advance!
I haven't tested this, but I think it should work. It's a batch + JScript + batch again hybrid script. Save this with a .bat extension and let me know whether it works for you. If not, I'll do some testing.
#if (#a==#b) #end /*
:: batch portion
#echo off
tasklist /fi "IMAGENAME eq cscript.exe" | find /i "cscript.exe" >NUL || (
start "" cscript /nologo /e:jscript "%~f0"
exit
)
:: ping -n seconds + 1 (because first ping result is instant)
ping -n 9 localhost > nul
start /d "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Skype\" Skype.lnk
exit
:: JScript portion */
var sh = new ActiveXObject("WScript.Shell");
sh.Run(WSH.ScriptFullName, 0);
WSH.Sleep(100);
I'll attempt to describe the workflow of the script.
cmd batch: User launches batch script either by double-clicking or entering batfile.bat at the cmd prompt.
Script checks to see whether cscript.exe is in the task list. It isn't.
Script re-launches itself using the JScript interpreter instead of the cmd batch interpreter. Current cmd interpretation exits.
JScript: The WScript.Shell object Run method re-launches the batch script with the cmd interpreter in a hidden, non-blocking process.
After a 100ms pause, JScript reaches the end of the file and exits. This should be the last of the visible windows.
invisible cmd batch: Script checks to see whether cscript.exe is in the task list. JScript is still pausing at this point, so cscript.exe does exist.
Go ping yourself... for 8 seconds.
Activate the Skype shortcut in a non-blocking process.
Batch script exit.