I'm sure many shareholders had no idea this was happening. It's not like VW had a shareholder vote to decide whether to cheat on emissions or not.
My point is that this could happen with any company and is part of the risk of investing, but to imply that the shareholders should have just "demanded companies to uphold legal and moral obligations" is assigning more stupidity on the shareholders than deserved.
It usually goes without saying that shareholders expect the companies they're investing in to obey the law and not lie to them.
Like I said, this is part of the risk of investing. There's always a chance the company you are investing in is cooking their books, lying, etc..., but the risk exists with any company and there's not much you can really do to mitigate it.