cmd.exe throws error “& was unexpected at this time.”

六眼飞鱼酱① 提交于 2021-02-19 04:13:06

问题


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

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

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 ?

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 )


回答1:


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.



来源:https://stackoverflow.com/questions/59480657/cmd-exe-throws-error-was-unexpected-at-this-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!