Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmd.exe throws error "& was unexpected at this time."

so my problem is that when i just ran cmd.exe in terminal, i get "& was unexpected at this time." Error at the end - looks like this

enter image description here

So the problem is that i'm getting erros in Unity 3D when it wants to run the unity_csc.bat file and compile solution. These errors are exactly the same as the one when i just run cmd.exe - therefore i suspect its not an Unity3D based problem (if you want you can check the Unity3D specific thread here https://forum.unity.com/threads/2-empty-errors-in-console-was-unexpected-at-this-time.799110/ )

Does anyone know why this might be happening ? This also happens when i try to run a .bat file - which I suspect is why i cant compile Unity project

enter image description here

I'm running Windows 10 with all of the latest updates

EDIT:

Since cmd /d does not throw the error, might there be some problem with this registry record ? enter image description here

In User Folder i do have this Autorun record

@mode 20,5 & tasklist /FI "IMAGENAME eq SoundMixer.exe" 2>NUL | find /I /N "SoundMixer.exe">NUL && exit & if exist " ( start /MIN "" " & tasklist /FI "IMAGENAME eq explorer.exe" 2>NUL | find /I /N "explorer.exe">NUL && exit & explorer.exe & exit ) else ( tasklist /FI "IMAGENAME eq explorer.exe" 2>NUL | find /I /N "explorer.exe">NUL && exit & explorer.exe & exit )

enter image description here

like image 216
PeterSVK Avatar asked Dec 25 '19 17:12

PeterSVK


People also ask

How do I keep cmd from opening after error?

Type the "cmd /k" parameter before every command to keep the window from closing.

Why CMD EXE is not working?

This issue can be caused due to different reasons. You might be dealing with some corrupted system files because of which you can't open or use Command Prompt. It can also be caused due to a recent change on your PC. Some glitches or corruption with your current user profile can be another reason for the issue at hand.

Is CMD EXE deprecated?

The Windows Cmd / Command-Line shell is NOT being removed from Windows in the near or distant future! The Cmd shell remains an essential part of Windows, and is used daily by millions of businesses, developers, and IT Pro's around the world.


1 Answers

Stephan has provided the crucial pointer:

It sounds like you have a broken autorun command defined for cmd.exe; that is, your registry defines a command that is automatically executed whenever you call cmd.exe, and that command causes the syntax error you're seeing.

Note that such commands are executed irrespective of whether you open an interactive cmd session or invoke via a batch file or pass a command to cmd with /C.

Passing /D to cmd bypasses any autorun commands.

There are two locations in the registry where such a command can be defined, one at the local-machine level (which applies to all users),
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor, and another for the current user only,
HKEY_CURRENT_USER\Software\Microsoft\Command Processor, in a value named AutoRun.
If commands are defined in both locations, the HKEY_LOCAL_MACHINE's commands run first.

To list any defined autorun commands:

Get-ItemProperty -ea Ignore ('HKCU:', 'HKLM:' -replace '$', '\Software\Microsoft\Command Processor') AutoRun

You can use the following PowerShell snippet to remove autorun commands from both locations, but note that you'll have to run it with elevation (as administrator), if a local-machine value is present:

Get-ItemProperty -ea Ignore ('HKCU:', 'HKLM:' -replace '$', '\Software\Microsoft\Command Processor') AutoRun |
  Remove-ItemProperty -Name AutoRun -WhatIf

Note: The -WhatIf common parameter in the command above previews the operation. Remove -WhatIf, once you're sure the operation will do what you want.

like image 196
mklement0 Avatar answered Oct 06 '22 22:10

mklement0