Thank you for the detailed follow up and for confirming your findings. Based on your explanation, the issue Indeed appears to be caused by group policy restrictions that prevent the winsdk.bat file from executing the registry query (reg query ) command.
Since you do not have permission to modify registry access or run with elevated privileges, the recommended approach is to bypass registry dependency by using static or preconfigured SDK paths without requiring reg query.
Recommended workarounds
**1. **manually defines SDK paths in a custom script
central registry cannot be queried in your environment; you can define the required SDK variables manually in a separate batch file and run it before building your C++ project.
For example, create a file named SetWindowsSDKEnv.bat with the following contents:
@echo off
Rem ---- Manually configure Windows SDK paths ----
Set “WIndowsSdkDir-C:\Program Files (x86)\Windows Kits\10”
Set “WindowsSdkVersions=10.0.22621.0”
Set “WindowsSdkBinPath=%WindowsSdkDir%Bin\%WindowsSdkVersion%”
Set “WindowsSdkLibPath=%WindowsSdkDir%Lib\%WindowsSdkVersion%”
Set “WindowsSdkIncludePath=%WindowsSdkDir%Include\%WindowsSdkVersion%”
Echo Windows SDK environment configured successfully.
Update the WindowsSdkVersion to match the version install on your system. You can find this by checking the folder name inside C:\Program Files (x86)\ WindowsKits\10\Include.
Then run:
Call SetWIndowSDKEnv.bit
Before running your build commands.
This ensured your SDK variables are correctly initialized without needing registry access.
**2. **User pre initialized build environment
If we are organization uses build agents or CI/CD systems. You can predefine these environment variables at the system level:
- open system properties -> advanced-> environment variables
- under system variables, click new and add same 4 variables: o WindowsSdkDir o WindowsSdkVersion o WindowsSdkBinPath o WindowsSdkLibPath
- Save and restart your shell or build environment.
This method ensures all users/machines have consistent SDK paths without modifying registry access.
**3. **Avoid dependency on winsdk.bat
you can also invoke the compiler directly using the Visual Studio build tools vcvarsall.bat (which does not rely on reg query for SDK detection):
Example:
Call “C:\Program Files\Microsoft Visual Studio\2022\BuildTools\VS\Auxiliary\Build\vcvarsall.bat” x64
Then manually ensure SDK paths are defined as above.
https://learn.microsoft.com/en-us/cpp/build/building-on-command-line
Why this happens
The group policy setting prevent access to registry editing tools or restricted HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows registry access prevents scripts from reading SDK locations. Winsdk.bat internally relies on these registry keys to set the correct variables.
Since you confirmed the policy cannot be changed, the static variable configuration is the correct long-term workaround.
Please let us know if you require any further assistance we’re happy to help. If you found this information useful, kindly mark this as "Accept Answer".