vswhere icon indicating copy to clipboard operation
vswhere copied to clipboard

One of my office PC fails to find MSVC when not running in elevated terminal.

Open solarispika opened this issue 1 year ago • 6 comments

I have tried reinstall MSVC 2019/2022, but it doesn't work. I have to always run vscode/vs installer as administrator in order to use MSVC. My user account is already in administrators group. Could it be some components owned by some administrator and not readable by others?

solarispika avatar Mar 26 '24 18:03 solarispika

What command are you running? What channel did you install? Note that prereleases and incomplete installs are not shown by default. Running vswhere -help will give you more details.

heaths avatar Mar 26 '24 20:03 heaths

Hi @heaths I have tested with latest version of vswhere. image I'm not using prereleases or buildtools.

solarispika avatar Mar 27 '24 02:03 solarispika

If the same command works as administrator, it seems you have an atypical permissions issue on %ProgramData%. Install Process Monitor, run that to collect a trace, filter by the process name vswhere, export only the unfiltered results, zip, and attach them here.

Alternative, though it may not be as helpful, run the following in an elevated command prompt:

cmd

icacls "%ProgramData%\Microsoft\VisualStudio\Packages\_Instances"

or

powershell

icacls "${env:ProgramData}\Microsoft\VisualStudio\Packages\_Instances"

/cc @tydunkel

heaths avatar Mar 27 '24 15:03 heaths

I ran the powershell but problem still exists. Here's the problem trace: Logfile.zip

solarispika avatar Mar 28 '24 08:03 solarispika

Thanks. As I suspected, you're getting an ERROR_ACCESS_DENIED trying to read/list the directory above. icacls should've produced output if you run it elevated, which will help diagnose the problem and suggest a fix. Please paste it in a reply.

Normally, %ProgramData% has read/list (RX) permissions for Everyone, but it seems that's not the case for you or that it has an integrity level higher than normal - allowing only elevated access. icacls will show us that.

heaths avatar Mar 28 '24 18:03 heaths

Thank you for the information, I managed to recover the permission of the mentioned folder.

The original output of the command is

 pika1  icacls "${env:ProgramData}\Microsoft\VisualStudio\Packages\_Instances"
C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances BUILTIN\Administrators:(F)
                                                          BUILTIN\Administrators:(I)(OI)(IO)(F)
                                                          BUILTIN\Administrators:(I)(CI)(F)

And I replaced all child object permission entries of ${env:ProgramData}\Microsoft\VisualStudio image

And it became

 pika1  icacls "${env:ProgramData}\Microsoft\VisualStudio\Packages\_Instances"
C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances Everyone:(I)(OI)(CI)(M)
                                                          BUILTIN\Users:(I)(OI)(CI)(M)
                                                          NT AUTHORITY\SYSTEM:(I)(OI)(CI)(F)
                                                          BUILTIN\Administrators:(I)(OI)(CI)(F)

Successfully processed 1 files; Failed processing 0 files

And I can access MSVC without administrator privileges!

Here's a question: Is it possible to show some error messages about why it can't find usable MSVC? In this case, yelling permission error on the folder maybe helpful.

solarispika avatar Mar 29 '24 02:03 solarispika