启动VS 2022开发者命令提示符时遭遇拒绝访问错误
VS 2022开发者命令提示符启动时出现“拒绝访问”问题
操作步骤与报错现象
- 从开始菜单找到「Developer command prompt for VS 2022」,选择「以管理员身份运行」
- 首先弹出Windows提示框:
此应用无法在你的电脑上运行
请查找适合你电脑的版本,咨询软件发布者 - 点击确定后,命令提示符窗口显示内容:
********************************************************************** ** Visual Studio 2022 Developer Command Prompt v17.11.5 ** Copyright (c) 2022 Microsoft Corporation ********************************************************************** Access is denied. C:\Program Files\Microsoft Visual Studio\2022\Enterprise>
问题定位
问题出在C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat内部调用的以下命令:
powershell.exe -NoProfile -Command "& {Import-Module '%~dp0\Microsoft.VisualStudio.DevShell.dll'; Send-VsDevShellTelemetry -NewInstanceType Cmd;}"
关联问题
启动某应用的cmd文件时也出现类似“拒绝访问”问题,该cmd文件内容如下:
echo set Falcon Specific Environment variables / Toggles rem Set environment variable SET_LOCALIP, which is used by many services. rem #Remarks: If more network adapters are available, choose the one which has the Internet or other sl artifacts can be accessed. for /f "delims=" %%a in ('powershell -command "(Get-NetIPAddress | Where InterfaceIndex -EQ ((Get-NetConnectionProfile | Where Name -like "*.sl.net").InterfaceIndex)).IPAddress"') do ( set SET_LOCALIP=%%a ) if not defined SET_LOCALIP ( for /f "delims=" %%a in ('powershell -command "(Get-NetIPAddress -PrefixOrigin Dhcp | Where-Object {$_.ValidLifetime -Lt ([TimeSpan]::MaxValue) -and $_.AddressState -Eq 'Preferred'}).IPAddress"') do ( set SET_LOCALIP=%%a ) )
关键测试结果
- 可独立执行其他PowerShell脚本
- 指定PowerShell.exe完整路径时,相关命令可正常执行;仅用
powershell.exe调用则报错“拒绝访问”,示例:
D:\OCT24A\bin\x64\Debug\devShell>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command "(Get-NetIPAddress | Where InterfaceIndex -EQ ((Get-NetConnectionProfile | Where Name -like "*.sl.net").InterfaceIndex)).IPAddress" D:\OCT24A\bin\x64\Debug\devShell>powershell.exe -command "(Get-NetIPAddress | Where InterfaceIndex -EQ ((Get-NetConnectionProfile | Where Name -like "*.sl.net").InterfaceIndex)).IPAddress" Access is denied.
内容的提问来源于stack exchange,提问作者Saikiran Kallatti
相关产品推荐
相关产品推荐

