HMD SpatialLocator in Win32 app requires UAC using Windows 10 April 2018 Update 1803


I have successfully gotten HMD pose from Windows.Perception.Spatial.SpatialLocator class in a Win32 app. I did this by compiling the project with C++/Cx enabled and pointing my VS project property pages to the the right #using folders:

C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.17134.0;
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\vcpackages

When I build, I can sample HMD pose using the following code on 1703 (2018 Fall Creators Update Windows 10):


Windows::Globalization::Calendar^ c = ref new Windows::Globalization::Calendar;
SpatialLocator ^m_locator = SpatialLocator::GetDefault();
SpatialStationaryFrameOfReference^ m_referenceFrame = m_locator->CreateStationaryFrameOfReferenceAtCurrentLocation();

while (true)
    if (m_locator->Locatability == SpatialLocatability::PositionalTrackingActive)
        SpatialLocation^ head_pose = m_locator->TryLocateAtTimestamp(Windows::Perception::PerceptionTimestampHelper::FromHistoricalTargetTime(c->GetDateTime()), m_referenceFrame->CoordinateSystem);

        if (head_pose != nullptr)
            std::cout << "ROT: {" << head_pose->Orientation.w << ", " << head_pose->Orientation.x << ", " << head_pose->Orientation.y << ", " << head_pose->Orientation.z << "}" << std::endl;
            std::cout << "POS: {" << head_pose->Position.x << ", " << head_pose->Position.y << ", " << head_pose->Position.z << "}" << std::endl;



On version 1803, this code does not work as expected. I can see that the Locatability property changes, but every time it changes to "PositionActive" for example, it immediately changes Locatability back to "Unavailable" and TryLocateAtTimestamp() always returns null.

After trying a few things, I found out that if I launch my .exe using "Run as Administrator..." in the explorer, the code behaves as expected and I am able to get the pose of the HMD.

Is this a bug? Is there a way to grant permission to use the HMD in a win32 .exe without having to run the .exe as administrator?


  • Jimbohalo10Jimbohalo10 ✭✭✭
    edited August 20

    Hi @mrdev1929 Windows Mixed Reality software is now in the One-core of Windows 10 as of Win10 version 1803.

    Previously it was an application which sometimes did not load, because of networking problems with Windows Update violations.

    There is a big enough WMR user base to justify putting the code into core.
    When you access or install core or call your library call now reference core libraries.

    So try and see if this Stack Overflow article How-to-run-an-application-as-run-as-administrator-from-the-command-prompt

    Basically the command code line is

    runas.exe /savecred /user:administrator "%sysdrive%\testScripts\testscript1.ps1"

    testscript1.ps1 is the PowerShell script to run your exe
    How to set "Run as administrator" property to any exe thru code

  • Instead of using c++/CX have you tried C++/winRT

    Dwight Goins
    CAO & Founder| Independent Architect | Trainer and Consultant | Sr. Enterprise Architect
    MVP | MCT | MCSD | MCPD | SharePoint TS | MS Virtual TS |Windows 8 App Store Developer | Linux Gentoo Geek | Raspberry Pi Owner | Micro .Net Developer | Kinect For Windows Device Developer

Sign In or Register to comment.