![]() * because batch subprocesses often open a second copy of CMD which will run this command again and again, from slowing everything down to other unforseen issues. Closing the window with the mouse won't work here. ![]() But remember, if you don't explicitly type exit, the history won't be saved. Now you've got all the macros you can eat, and you're saving your command line session each time. Rem copy the current directory to the clipboardĭOSKEY cc=cd^|clip ^& echo %%CD%% copied to clipboard For example: rem review previous command line entries:ĭOSKEY history=notepad %USERPROFILE%\commands.log This allows you to add as many macros as you want to your command session. Then, when any subsequent subprocesses open a command session, they will run into the second line and immediately exit the script! This is because subprocesses automatically inherit the environment variables from the parent process. How does this avoid those unexpected side effects?Īll we're doing is creating an environment variable called AUTOEXEC. Rem remap exit command to save a copy of the command line history to a log before exiting.ĭOSKEY exit=(echo/ ^& echo **** %date% %time% ****) $g$g %USERPROFILE%\commands.log ^& doskey /history $g$g %USERPROFILE%\commands.log ^& ECHO Command history saved, exiting ^& exit $* ![]() Here is what you put in the autoexec.bat file: off So yes, this batch file will run every time a CMD session is opened, but we'll do a trick to make sure it doesn't run in any subprocesses. Then change the value of HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor\AutoRun to this: IF EXIST "%USERPROFILE%\autoexec.bat" (CALL "%USERPROFILE%\autoexec.bat") While that will work, it will definitely create unexpected side effects when doing any kind of scripting*.Ĭreate a file called autoexec.bat and store it in your profile folder (e.g., C:\Users\yourname\autoexec.bat). Anything you put in this entry will be run when you start a CMD session. The short and dangerous answer is to just add it to the REGISTRY in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor\AutoRun. The tricky part is autoloading that doskey macro when you start a new command session. Unfortunately, you won't be able to easily go back to any of these entries by pressing the up arrow, but you can examine the file at any point to see what you did in the past. This creates a macro that remaps the EXIT command to copy the command line history into your user profile folder (e.g., C:\Users\yourname\commands.log). This simple macro will save the command line history when you exit a CMD session: doskey exit=(echo/ ^& echo **** %date% %time% ****) $g$g %USERPROFILE%\commands.log ^& doskey /history $g$g %USERPROFILE%\commands.log ^& ECHO Command history saved, exiting ^& exit $* I have actually got out of the hole by uninstalling USBPCap but I am still wanting to know how and whether booting directly to a command prompt is possible.If all you want to do is save your command line history at the end of every session, here's a simple way to do it:Īs other answers indicated, doskey allows you to list the command line history for the current session. I was able to gain control of the PC by TeamViewer and determine via the Device Manager that no USB drivers had loaded.Ī bit of web poking around found that this is a known problem with USBCap, but I wanted to back a couple of things up before attempting any fixes so I wanted to boot to a command prompt so I could access some files (a backup of the registry at the time of the last successful Windows startup) that were normally locked under windows. When I restarted, the machine (Dell 8700) started as per normal, but when it had finished starting windows the mouse (wireless - works via a USB dongle), and keyboard (wired, USB) were non-functional. It all started when I updated to WireShark 2.2.1 and decided at the same time to include the USBPCap drivers. I had a fault that wiped out all my USB devices so at the end of startup I had a functional machine but no keyboard or mouse. What do you do when your PC won't boot? Is there a way of getting from power - on to a command prompt as directly as possible? This assumes you have a functional PC that successfully boots so you can access said options. The discussions I have found detail how to boot to a command prompt, but they all have at their starting point the "Advanced Startup Options".
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |