Is it possible to "reset" cmd? - windows

Is there a command to reset Windows cmd window? I would like it to have the same effect as opening a new cmd window, but well, by reloading the current one.
What I want to do is install Python from the command line and then "reload" the window so I can use Python in a current window. I don't want to close the cmd and then open it again.

Have a look at this list. I think cls is what you are looking for:
The cls command clears the screen of all previously entered commands and other text. The cls command is available in all versions of Windows, as well as in MS-DOS.

The following will create a brand new (reset) window with your current working directory set.
START "" "C:\Users\lit\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\cmd.exe.lnk" /K CD /D "%CD%" & EXIT

Related

BAT file with the option of using UP arrow to repeat command

I am troubleshooting a problem with a device keeping a Windows 10 PC awake using the powercfg -requests command. I have a BAT file containing the following so it can be run quickly via shortcut with run as admin properties:
cmd /k powercfg -requests
This works, but in addition to keeping the window open, I'd like to be able to keep sending powercfg -requests by hitting arrow up/enter when needed, as would normally happen if I opened a command prompt and typed it manually.
I've searched quite a bit here, and aside from making it repeat automatically,
I haven't found anything other than sending arrow keystrokes in a BAT file.
I did see something which implied it might be possible to print the command so it's entered at the prompt
after the command has executed, which would be fine too, but haven't had much luck.
Is this possible?
Sorry, there is not a simple way...
This works:
#if (#CodeSection == #Batch) #then
#echo off
start "" /B cmd /K
timeout /T 1
CScript //nologo //E:JScript "%~F0" "powercfg -requests{ENTER}"
goto :EOF
#end
WScript.CreateObject("WScript.Shell").SendKeys(WScript.Arguments(0));
For a further description on the method used, see this answer
Use PowerShell instead. You can right click on Desktop > New Shortcut and paste this then save
powershell -NoExit -Command "Add-Content -Path (Get-PSReadlineOption).HistorySavePath 'powercfg -requests'; Invoke-Expression 'powercfg -requests'"
It's better to create a new shortcut because you can set it to always run as admin although it's still possible to put it in a *.bat/*.ps1 file
You can also shorten it like this
powershell -NoE -C "$c = 'powercfg -requests'; ac (Get-PSReadlineOption).HistorySavePath $c; iex $c"
PowerShell is far more flexible and powerful than batch. It also has a persistent history so it's far more convenient to use PowerShell. You may not even need this and just press Ctrl+R to search through history for the powercfg command just like in bash/zsh

Command to start a process in the background and run silently

I'm trying to write a command in a bat file to run an installer exe file. The important part is to start and run the installer in silent mode. To clarify, I DO NOT want the user to see the installer and click through the wizard. They should just be able to double click the bat file and walk away. I have attempted this command in my bat file:
#echo off
REM Next command runs installer in silent mode
start /d "%USERPROFILE%\Desktop" MyInstaller_7.1.51.14.exe –s –v –qn
The –s –v –qn are supposed to enable the installer to run in the background, but they are not working.
Can anyone help me improve my command in my bat file so that MyInstaller_7.1.51.14.exe is indeed running in the background, silently, with no UI or wizard of any kind visible to the user??
Please help.
You can try one of these START command options to see if it gives you the effect you want:
/B = Start application without creating a new window
/MIN = Start window minimized
Edited:
Try putting the command with its switches inside quotes:
start /d "%USERPROFILE%\Desktop" "MyInstaller_7.1.51.14.exe –s –v –qn"
Another solution you can test :
Create a file RunHide.vbs and put this line in it :
CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False
and then run your batch file like this :
wscript.exe "RunHide.vbs" "Install.bat"
and your batch file will be run without any windows (and maybe your Installer to)
I finally figured it out.
Here is the correct code:
#echo off
REM Next command runs installer in silent mode
start "%USERPROFILE%\Desktop" MyInstaller_7.1.51.14.exe /s /v /qn
The change was between –s –v –qn and /s /v /qn where the former does not work, and the latter does.

How to run a command on command prompt startup in Windows

EDIT
If you want to perform any task at computer startup or based on an
event this is very helpful
http://answers.microsoft.com/en-us/windows/forum/windows_7-performance/how-to-schedule-computer-to-shut-down-at-a-certain/800ed207-f630-480d-8c92-dff2313c193b
Back to the question
I have two questions:
I want some specific commands to be executed when I start command prompt.
e.g. cls to clear my command prompt.
I want to execute some commands in a batch file and wait for the user to enter new commands (if any).
e.g. A batch file which will take the user to some specified folder and then wait for the user to rename/delete a file from the command prompt.
How can I do it?
If you want a defined set of commands to run every time you start a command prompt, the best way to achieve that would be to specify an init script in the AutoRun registry value. Create it like this (an expandable string value allows you to use environment variables like %USERPROFILE%):
reg add "HKCU\Software\Microsoft\Command Processor" /v AutoRun ^
/t REG_EXPAND_SZ /d "%"USERPROFILE"%\init.cmd" /f
Then create a file init.cmd in your profile folder:
#echo off
command_A
command_B
...
cls
To remove these changes, delete the registry key:
reg delete "HKCU\Software\Microsoft\Command Processor" /v AutoRun
Make a shortcut
Go to the properties
The bit where it says: C:\Users\<Your username>\Desktop\cmd.exe, you put: -cmd /K <your command here>
e.g.
C:\Users\Lewis\Desktop\cmd.exe -cmd /K color 1f
This is the way to launch 1 command without having to mess about with the registry.
Run multiple commands
You can also use & (and) operator to execute multiple commands.
Eg.
C:\Users\Lewis\Desktop\cmd.exe -cmd /K color 1f & H: & <your command>
Credits: user6589073
I found my answer: I should use the /K switch, using which I can enter a new command on the opened command prompt.
E.g. cmd /K cls will open a command prompt for me and clear it. (Answer for question 1)
and
cmd /K MyBatchFile.bat will start a command prompt, execute the batch file and stay on the command prompt and will not exit. (Answer for question 2).
First, you need to press Windows Key + R.
In the box that appears, type "regedit" (without the quotes).
The Windows Registry Editor should open.
Now, locate to HKEY_CURRENT_USER/Software/Microsoft/Command Processor.
Once you have clicked on Command Processor on the left side, click Edit on the top bar.
Then go to New > String Value in the Edit menu.
Rename the String Value that appears to Autorun.
Right click on Autorun and select Modify.
Under the "Value Data" area, type in the commands you want to run. You can run multiple by typing && between them.
Expanding a bit, here is an alternative for Windows 10 where multiple aliases can be defined and applied to the Command Prompt upon execution.
Create a file called init.cmd containing aliases on your %USERPROFILE% folder:
init.cmd
#echo off
doskey c=cls
doskey d=cd %USERPROFILE%\Desktop
doskey e=explorer $*
doskey g=git status
doskey l=dir /a $*
Register it to be applied whenever the Command Prompt is executed:
In the Command Prompt, run:
reg add "HKCU\Software\Microsoft\Command Processor" /v AutoRun /t REG_EXPAND_SZ /d "%"USERPROFILE"%\init.cmd" /f
Done
Now the contents of init.cmd will run for executions of cmd.exe namely from:
Taskbar shortcut
WIN+R cmd
By typing cmd in the File Explorer address bar
By running cmd.exe directly from C:\Windows\System32
After registering these settings just remember to close/open:
The Command Prompt so the settings are applied
The File Explorer, if you use to launch the cmd via File Explorer address bar
To unregister it, run:
reg delete "HKCU\Software\Microsoft\Command Processor" /v AutoRun
I have a command to run a python program. I do not want to run this command manually after login, I want this command should run automatically after I logged in to my ubuntu. I am using Ubuntu 16.04.
Here is the command.
sh demo_darknet_yolov3.sh , this shell is placed in this directory littro#littro-System-Product-Name:~/MobileNet-YOLO-master/MobileNet-YOLO-master
Depending on your script, you may want to use the cmd.exe /k <input script> method instead of the registry entry Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor\autorun
I have found with the latter, that other programs that launch cmd are affected by the registry entry. For example, I cannot get Visual Studio Native Tools prompt to work properly because my script gets in the way. In my case, the script is a menu with 5 options including to launch various programs manually (I like to minimize my auto-run programs) and set various environment variables (ie., printers, proxy settings, default versions of programs, etc).
If you are doing something static I think either method works fine.
I would have commented on the question or an applicable answer, but I do not have the reputation to comment.

Windows 7: cmd.exe: setting startup directory (in a link to cmd.exe)

I am running Windows 7 and when I run cmd.exe I want it to start up
in a directory named C:\foo\bar. I remember being able to create a
link to this executable on the desktop and right clicking somewhere
to set the startup menu of the cmd.exe command prompt by filling
out a field in a transient window, but I cannot find it. I have
found the following argument which however seems more complicated.
I want to set the startup directory for cmd.exe via a popup window.
Changing default startup directory for command prompt in Windows 7
Any ideas?
as mentioned by the other posters already:
the regular approach is to edit the shortcut's properties and fill the field labled "start in". simple as that.
however, for some reason this has no effect on UAC enabled systems if at the same time you also enable the "run as administrator" checkbox in the advanced properties of the shortcut.
a solution is to put everything in the "target" field of the shortcut:
%windir%\System32\cmd.exe /K cd /d "E:\My Folder" & sometest.bat
when running on 64bit and you want to explicitly start the 32bit flavour of the command prompt:
%windir%\SysWOW64\cmd.exe /K cd /d "E:\My Folder" & sometest.bat
for additional information on the command line parameters used above see:
cmd.exe /?
cd.exe /?
When you create a shortcut to cmd.exe, you can open the shortcut properties and find under Shortcut tab the Starts in option that will tell cmd.exe where to start, like here:
Open the properties of a shortcut to cmd and set the directory there:
Try this Shortcut Target:
C:\Windows\System32\cmd.exe cd /d %~dp0
Which will start cmd.exe in the shortcut's folder.

how to minimize the command prompt when running a batch script?

anybody know how to minimize the command prompt when running a batch script in Windows 3.11?
in Windows XP, there have a command
start /min start.bat
to minimize the cmd prompt, is it have similiar command in MSDos 6.22?
This little batch code should do what you need.
http://zoombody.com/articles/run-a-batch-script-minimized
The relevant code then needs to be placed at the top of your script:
if not "%minimized%"=="" goto :minimized
set minimized=true
start /min cmd /C "%~dpnx0"
goto :EOF
:minimized
rem Anything after here will run in a minimized window
Here is more information about "%~dpnx0".
There isn't a command that you can use from a DOS prompt, however you can create a PIF file that points to your batch file, in which you can set the default window position (including minimized).
...I think. It's been a couple of decades.
How to minimize the current command prompt:
Purpose:
Close a command prompt after execution.
Open a new command prompt using the same path.
First open command prompt :
Hold down the [Windows] + [R] keys.
Go to this location:
C:\>cd Users\Admin\Desktop
Next excute:
C:\Users\Admin\Desktop>start /min && exit
Results:
A new minimized command prompt should open with the same path.
Alternatively:
Create a script named minimize.bat and type start /min && exit into the script and place it in your system32 folder. In order to have the ability to access it via the command prompt.
Windows 10 makes it very easy to start minimized. Simply create a shortcut and click properties. On the shortcut tab half way down is the "Run:" option witch lets you select how you want the command line window to start up. Just select minimized and your command window will remain minimized from the onset.
Windows10 properties window of a shortcut
Use WinExec to start your batch file and pass SW_SHOWMINIMIZED for the second parameter.
See also, How do I run a batch file with WinExec?

Resources