13

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

PeterSVK
  • 173
  • 1
  • 1
  • 9
  • 3
    Is it the same issue when you try `cmd.exe /d`? – Stephan Dec 25 '19 at 18:13
  • Hi Stephan, nope - cmd.exe /d gives just Windows info and no error – PeterSVK Dec 25 '19 at 18:14
  • 4
    fine. `/d` deactivates autorun of some commands in the registry. Probably you have a problem there. `cmd /?` tells you the registry-keys to check. – Stephan Dec 25 '19 at 18:17
  • Thanks Stephan for the pointers ! I'm not entirely sure if this was the right thing to check or what to do with it, but it looks like i'm either missing Autorun folder or Autorun registry entry - I've updated my question with more info – PeterSVK Dec 25 '19 at 18:29
  • 3
    The string in your Autorun record is strange/wrong in so many ways - do you happen to know, where it comes from? I personally would just delete it (default is no entry) – Stephan Dec 25 '19 at 18:42
  • Yep i agree - Actually, last few weeks when i start my PC my explorer.exe does not come up so i have to run it manualy through Task Manager :D I think this might be the cause of that issue. I'll remove it, let you know and accept the answer. Thanks ! – PeterSVK Dec 25 '19 at 18:44
  • 4
    Don't bother - your question is off-topic for this site anyway (not code-related). Better delete it before downvoting starts. Glad I could help. Merry Christmas! – Stephan Dec 25 '19 at 18:56

1 Answers1

20

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.

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • 1
    Thanks a lot, you saved my day! I got this error because I had a "&" symbol in my autorun, due to a Conda install error. – Chan Kha Vu Aug 07 '23 at 23:58