C# VpnManagementAgent总是返回零个配置文件,而且我似乎无法创建新的配置文件 注意下面的第二个例子,其中一个是C++中的。

C# VpnManagementAgent总是返回零个配置文件,而且我似乎无法创建新的配置文件 注意下面的第二个例子,其中一个是C++中的。,c#,c++,c,uwp,windows-server-2019,C#,C++,C,Uwp,Windows Server 2019,注意,第三个例子是C 好的,经过一点挖掘,似乎问题可能在于某种权限问题,因为在调试二进制文件并跳过一些随机检查之后-它显示了我为我的帐户提供的单个配置文件。是的,有对GetCurrentPackageFamilyName的调用,肯定是在查询某种权限 没有背景信息不是我的错-只有公共文档是。我只是在尝试ping接口 C变量很复杂,因为我必须调用RoCreateInstance然后调用Inspectable_QueryInterface,还必须定义我自己的IID,因为原始IID是可检查的。此外,我还

注意,第三个例子是C

好的,经过一点挖掘,似乎问题可能在于某种权限问题,因为在调试二进制文件并跳过一些随机检查之后-它显示了我为我的帐户提供的单个配置文件。是的,有对GetCurrentPackageFamilyName的调用,肯定是在查询某种权限

没有背景信息不是我的错-只有公共文档是。我只是在尝试ping接口

C变量很复杂,因为我必须调用RoCreateInstance然后调用Inspectable_QueryInterface,还必须定义我自己的IID,因为原始IID是可检查的。此外,我还需要使用WindowsCreateStringReference和自定义COM处理程序创建自己的字符串。标题中包含的名称有数千个字符长,这没有帮助

基本上,我尝试从我查询和填充的VPNProfile接口和XML中添加一个概要文件,这些尝试都不起作用。最近,我能够从对象更新现有的配置文件

然而,我似乎也无法连接到一个和断开连接

使用上述接口,我能做的唯一有用的事情是UpdateProfileFromXmlAsync,它会使应用程序崩溃:

#define COBJMACROS
#include <roapi.h>
#include <windows.networking.vpn.h>
#include <stdbool.h>
#include <stdio.h>

//Had to manually define my IIDs
//because the definitions are missing from the library

const IID IID___x_ABI_CWindows_CNetworking_CVpn_CIVpnManagementAgent = {0x193696CD,0xA5C4,0x4ABE,0x85,0x2B,0x78,0x5B,0xE4,0xCB,0x3E,0x34};

const IID IID___FIAsyncOperationCompletedHandler_1___FIVectorView_1_Windows__CNetworking__CVpn__CIVpnProfile = {0xdac6dd72,0xa5d1,0x56d4,0xaf,0xc4,0x98,0x9f,0x84,0xdc,0xb2,0xb3};

const IID IID___x_ABI_CWindows_CNetworking_CVpn_CIVpnProfile = {0x7875B751,0xB0D7,0x43DB,0x8A,0x93,0xD3,0xFE,0x24,0x79,0xE5,0x6A};

const IID IID___x_ABI_CWindows_CNetworking_CVpn_CIVpnNativeProfile = {0xA4AEE29E,0x6417,0x4333,0x98,0x42,0xF0,0xA6,0x6D,0xB6,0x98,0x02};

const IID IID___x_ABI_CWindows_CNetworking_CVpn_CIVpnChannel = {0x4AC78D07,0xD1A8,0x4303,0xA0,0x91,0xC8,0xD2,0xE0,0x91,0x5B,0xC3};

const IID IID___FIAsyncOperationCompletedHandler_1_Windows__CNetworking__CVpn__CVpnManagementErrorStatus = {0x31229f8c,0x709d,0x5017,0x86,0x29,0x57,0xef,0x12,0x89,0xe6,0x16};

const WCHAR pVPNXmlCode[] = 

L"<SyncML xmlns=\"SYNCML:SYNCML1.2\" xmlns:A=\"syncml:metinf\">"
L"  <SyncBody>"
L"    <Atomic>"
L"      <CmdID>10000</CmdID>"
L""
L"      <!-- Configure VPN Server Name or Address (PhoneNumber=) [Comma Separated]-->"
L"      <Add>"
L"        <CmdID>10001</CmdID>"
L"        <Item>"
L"          <Target>"
L"            <LocURI>./Vendor/MSFT/VPNv2/VPN_Demo/ProfileXML</LocURI>"
L"          </Target>"
L"          <Data><VPNProfile>"
L"  <ProfileName>VPN_Demo</ProfileName>"
L"  <NativeProfile>"
L"    <Servers>VPNServer.contoso.com</Servers>"
L"    <NativeProtocolType>Automatic</NativeProtocolType>"
L"    <Authentication>"
L"      <UserMethod>Eap</UserMethod>"
L"      <Eap>"
L"        <Configuration>"
L"<EapHostConfig xmlns=\"http://www.microsoft.com/provisioning/EapHostConfig\"> <EapMethod> <Type xmlns=\"http://www.microsoft.com/provisioning/EapCommon\">25</Type> <VendorId xmlns=\"http://www.microsoft.com/provisioning/EapCommon\">0</VendorId> <VendorType xmlns=\"http://www.microsoft.com/provisioning/EapCommon\">0</VendorType> <AuthorId xmlns=\"http://www.microsoft.com/provisioning/EapCommon\">0</AuthorId> </EapMethod> <Config xmlns=\"http://www.microsoft.com/provisioning/EapHostConfig\"> <Eap xmlns=\"http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1\"> <Type>25</Type> <EapType xmlns=\"http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV1\"> <ServerValidation> <DisableUserPromptForServerValidation>false</DisableUserPromptForServerValidation> <ServerNames></ServerNames> </ServerValidation> <FastReconnect>true</FastReconnect> <InnerEapOptional>false</InnerEapOptional> <Eap xmlns=\"http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1\"> <Type>13</Type> <EapType xmlns=\"http://www.microsoft.com/provisioning/EapTlsConnectionPropertiesV1\"> <CredentialsSource> <CertificateStore> <SimpleCertSelection>false</SimpleCertSelection> </CertificateStore> </CredentialsSource> <ServerValidation> <DisableUserPromptForServerValidation>false</DisableUserPromptForServerValidation> <ServerNames></ServerNames> </ServerValidation> <DifferentUsername>false</DifferentUsername> <PerformServerValidation xmlns=\"http://www.microsoft.com/provisioning/EapTlsConnectionPropertiesV2\">false</PerformServerValidation> <AcceptServerName xmlns=\"http://www.microsoft.com/provisioning/EapTlsConnectionPropertiesV2\">false</AcceptServerName> <TLSExtensions xmlns=\"http://www.microsoft.com/provisioning/EapTlsConnectionPropertiesV2\"> <FilteringInfo xmlns=\"http://www.microsoft.com/provisioning/EapTlsConnectionPropertiesV3\"> <EKUMapping> <EKUMap> <EKUName>Unknown Key Usage</EKUName> <EKUOID>1.3.6.1.4.1.311.87</EKUOID> </EKUMap> </EKUMapping> <ClientAuthEKUList Enabled=\"true\"> <EKUMapInList> <EKUName>Unknown Key Usage</EKUName> </EKUMapInList> </ClientAuthEKUList> </FilteringInfo> </TLSExtensions> </EapType> </Eap> <EnableQuarantineChecks>false</EnableQuarantineChecks> <RequireCryptoBinding>false</RequireCryptoBinding> <PeapExtensions> <PerformServerValidation xmlns=\"http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV2\">false</PerformServerValidation> <AcceptServerName xmlns=\"http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV2\">false</AcceptServerName> </PeapExtensions> </EapType> </Eap> </Config> </EapHostConfig>"
L"    </Configuration>"
L"      </Eap>"
L"    </Authentication>"
L"    <RoutingPolicyType>SplitTunnel</RoutingPolicyType>"
L"  </NativeProfile>"
L"  <DomainNameInformationList>"
L"    <DomainName>.contoso.com</DomainName>"
L"    <DNSServers>10.5.5.5</DNSServers>"
L"  </DomainNameInformationList>"
L" <TrafficFilter>  "
L"    <App>%ProgramFiles%Internet Exploreriexplore.exe</App> "
L"  </TrafficFilter> "
L"  <TrafficFilter>  "
L"    <App>Microsoft.MicrosoftEdge_8wekyb3d8bbwe</App>  "
L"  </TrafficFilter>"
L"  <Route>"
L"    <Address>10.0.0.0</Address>"
L"    <PrefixSize>8</PrefixSize>"
L"  </Route>"
L"  <Route>"
L"    <Address>25.0.0.0</Address>"
L"    <PrefixSize>8</PrefixSize>"
L"  </Route>"
L"    <RememberCredentials>true</RememberCredentials>"
L"  </VPNProfile></Data>"
L"        </Item>"
L"      </Add>"
L""
L"    </Atomic>"
L"    <Final/>"
L"  </SyncBody>"
L"</SyncML>"

;


//Completion Handlers


HRESULT QueryInterface(This,riid,ppvObject)void * This;REFIID riid;void **ppvObject; {if(!ppvObject) return E_POINTER;
    return !memcmp(riid, &IID_IUnknown, sizeof *riid) || 
    !memcmp(riid, &IID___FIAsyncOperationCompletedHandler_1_Windows__CNetworking__CVpn__CVpnManagementErrorStatus, sizeof *riid) ||
    !memcmp(riid, &IID___FIAsyncOperationCompletedHandler_1___FIVectorView_1_Windows__CNetworking__CVpn__CIVpnProfile, sizeof *riid) ? *ppvObject=This, S_OK 
    : E_NOINTERFACE;}
HANDLE hReady;
(AddRef)(in) void*in; {;}
(Release)(in) void*in; {;}

__x_ABI_CWindows_CNetworking_CVpn_CIVpnProfile *pProfile;

        //Error Handler
HRESULT (InvokeError)(in,asyncInfo,status) void*in;
__FIAsyncOperation_1_Windows__CNetworking__CVpn__CVpnManagementErrorStatus *asyncInfo;AsyncStatus status;
{
    enum __x_ABI_CWindows_CNetworking_CVpn_CVpnManagementErrorStatus disconnectstatus;
    __FIAsyncOperation_1_Windows__CNetworking__CVpn__CVpnManagementErrorStatus_GetResults(asyncInfo,&disconnectstatus);
    printf("SET0:%d\n%x\n",disconnectstatus, GetLastError()),SetEvent(hReady);
    return S_OK;}

        //Profile Sets Handler
HRESULT (InvokeCollect)(in,asyncInfo,status) void*in;
__FIAsyncOperation_1___FIVectorView_1_Windows__CNetworking__CVpn__CIVpnProfile *asyncInfo;AsyncStatus status;
{__FIVectorView_1_Windows__CNetworking__CVpn__CIVpnProfile *pResults;
    unsigned int size;
    printf("SET1:%d\n",status),
    printf("%x\n",__FIAsyncOperation_1___FIVectorView_1_Windows__CNetworking__CVpn__CIVpnProfile_GetResults(asyncInfo, &pResults)),
    __FIAsyncOperation_1___FIVectorView_1_Windows__CNetworking__CVpn__CIVpnProfile_Release(asyncInfo),
    __FIVectorView_1_Windows__CNetworking__CVpn__CIVpnProfile_get_Size(pResults,&size),
    printf("Amount of profiles collected %d\n",size),
    __FIVectorView_1_Windows__CNetworking__CVpn__CIVpnProfile_Release(pResults),
    SetEvent(hReady);return S_OK;}


__FIAsyncOperationCompletedHandler_1___FIVectorView_1_Windows__CNetworking__CVpn__CIVpnProfile ProfilesRetrieverHandler = 
{(__FIAsyncOperationCompletedHandler_1___FIVectorView_1_Windows__CNetworking__CVpn__CIVpnProfileVtbl[1])
        {{QueryInterface,AddRef,Release,InvokeError}}};

(main)()

//Long complex,boring initialization
{__x_ABI_CWindows_CNetworking_CVpn_CIVpnManagementAgent *pVpnMan; HSTRING_HEADER header;
    ULONG idCount; IID*pIdds;
    hReady = CreateEvent(0,true,false,0); __x_ABI_CWindows_CNetworking_CVpn_CIVpnProfile *pProfile;
    __x_ABI_CWindows_CNetworking_CVpn_CIVpnNativeProfile *pNativeProfile;
    ULONG strSize; WCHAR *pRawString;__x_ABI_CWindows_CNetworking_CVpn_CIVpnChannel *pChannel;
    enum __x_ABI_CWindows_CNetworking_CVpn_CVpnManagementErrorStatus disconnectstatus;
    __FIAsyncOperation_1_Windows__CNetworking__CVpn__CVpnManagementErrorStatus *pVpnManErr;
    IInspectable *pVpnObjInspect; HSTRING string; RoInitialize(RO_INIT_MULTITHREADED),

    //Query for IVpnManagementAgent
    WindowsCreateStringReference(RuntimeClass_Windows_Networking_Vpn_VpnManagementAgent,
        sizeof RuntimeClass_Windows_Networking_Vpn_VpnManagementAgent/sizeof(WCHAR)-1,
        &header, &string), RoActivateInstance(string,&pVpnObjInspect), WindowsDeleteString(string), IInspectable_QueryInterface(pVpnObjInspect,
        &IID___x_ABI_CWindows_CNetworking_CVpn_CIVpnManagementAgent,&pVpnMan),IInspectable_Release(pVpnObjInspect), 


        //Query for IVpnProfile
        WindowsCreateStringReference(RuntimeClass_Windows_Networking_Vpn_VpnNativeProfile,
        sizeof RuntimeClass_Windows_Networking_Vpn_VpnNativeProfile/sizeof(WCHAR)-1,
        &header, &string), RoActivateInstance(string,&pVpnObjInspect),WindowsDeleteString(string),IInspectable_GetIids(pVpnObjInspect,&idCount,&pIdds),
        IInspectable_QueryInterface(pVpnObjInspect, &IID___x_ABI_CWindows_CNetworking_CVpn_CIVpnProfile,&pProfile),IInspectable_Release(pVpnObjInspect),

        //Set Profile name to currently active VPN Profile in my system
        WindowsCreateStringReference(pVPNXmlCode, sizeof pVPNXmlCode/sizeof(WCHAR)-1,&header, &string),WindowsCreateStringReference(L"VPN Connection",
            sizeof L"VPN Connection"/sizeof(WCHAR)-1,&header, &string),__x_ABI_CWindows_CNetworking_CVpn_CIVpnProfile_put_ProfileName(pProfile,string),
        WindowsDeleteString(string),

        //Query to IVpnNativeProfile and the back to IVpnProfile - because I can
        printf("%x\n",__x_ABI_CWindows_CNetworking_CVpn_CIVpnProfile_QueryInterface(pProfile,&IID___x_ABI_CWindows_CNetworking_CVpn_CIVpnNativeProfile,&pNativeProfile)),
        __x_ABI_CWindows_CNetworking_CVpn_CIVpnProfile_Release(pProfile),
        printf("%x\n",__x_ABI_CWindows_CNetworking_CVpn_CIVpnProfile_QueryInterface(pNativeProfile,&IID___x_ABI_CWindows_CNetworking_CVpn_CIVpnProfile,&pProfile)),
        __x_ABI_CWindows_CNetworking_CVpn_CIVpnNativeProfile_Release(pNativeProfile),


        //The interesting part


        //Try to add profile from XML

        WindowsCreateStringReference(pVPNXmlCode,sizeof pVPNXmlCode/
        sizeof(WCHAR)-1,&header, &string),__x_ABI_CWindows_CNetworking_CVpn_CIVpnManagementAgent_AddProfileFromXmlAsync(pVpnMan,string,&pVpnManErr),
        WindowsDeleteString(string),__FIAsyncOperation_1_Windows__CNetworking__CVpn__CVpnManagementErrorStatus_put_Completed(pVpnManErr,&ProfilesRetrieverHandler),
        WaitForSingleObject(hReady, INFINITE), ResetEvent(hReady),

        //Try to add profie from previously queried profile
        __x_ABI_CWindows_CNetworking_CVpn_CIVpnManagementAgent_AddProfileFromObjectAsync(pVpnMan,pProfile,&pVpnManErr),
        __FIAsyncOperation_1_Windows__CNetworking__CVpn__CVpnManagementErrorStatus_put_Completed(pVpnManErr,&ProfilesRetrieverHandler),
        WaitForSingleObject(hReady, INFINITE), ResetEvent(hReady),

        //See how many profiles we have
        ProfilesRetrieverHandler.lpVtbl->Invoke = InvokeCollect;
        __FIAsyncOperation_1___FIVectorView_1_Windows__CNetworking__CVpn__CIVpnProfile *pProfiles;
        __x_ABI_CWindows_CNetworking_CVpn_CIVpnManagementAgent_GetProfilesAsync(pVpnMan,&pProfiles),
        __FIAsyncOperation_1___FIVectorView_1_Windows__CNetworking__CVpn__CIVpnProfile_put_Completed(pProfiles,&ProfilesRetrieverHandler),
        __FIAsyncOperation_1___FIVectorView_1_Windows__CNetworking__CVpn__CIVpnProfile_Release(pProfiles),
        WaitForSingleObject(hReady, INFINITE),ResetEvent(hReady);

        //Try connectiong to our previously named profile
        ProfilesRetrieverHandler.lpVtbl->Invoke = InvokeError,
        __x_ABI_CWindows_CNetworking_CVpn_CIVpnManagementAgent_ConnectProfileAsync(pVpnMan,pProfile,&pVpnManErr),
        __FIAsyncOperation_1_Windows__CNetworking__CVpn__CVpnManagementErrorStatus_put_Completed(pVpnManErr,&ProfilesRetrieverHandler),
        __FIAsyncOperation_1_Windows__CNetworking__CVpn__CVpnManagementErrorStatus_Release(pVpnManErr),
        WaitForSingleObject(hReady, INFINITE),ResetEvent(hReady);

        //For fun crash the application
        ProfilesRetrieverHandler.lpVtbl->Invoke = InvokeError,
        WindowsCreateStringReference(pVPNXmlCode,sizeof pVPNXmlCode/
        sizeof(WCHAR)-1,&header, &string),__x_ABI_CWindows_CNetworking_CVpn_CIVpnManagementAgent_UpdateProfileFromXmlAsync(pVpnMan,string,&pVpnManErr),
        WindowsDeleteString(string),
        __FIAsyncOperation_1_Windows__CNetworking__CVpn__CVpnManagementErrorStatus_put_Completed(pVpnManErr,&ProfilesRetrieverHandler),
        __FIAsyncOperation_1_Windows__CNetworking__CVpn__CVpnManagementErrorStatus_Release(pVpnManErr),
        WaitForSingleObject(hReady, INFINITE),ResetEvent(hReady);

        printf("never reached\n");

}
以下是我如何编译上述内容:

cl so.cpp/std:c++最新版本/link RuntimeObject.lib Ole32.lib OleAut32.lib

下面是一个C变体:

using System;
using Windows;
using Windows.Networking.Vpn;
using System.Threading.Tasks;
using Windows.Networking;
using  System.Threading;

public class entry
{public static async Task Main()
{VpnManagementAgent mgr = new VpnManagementAgent();
    mgr.GetProfilesAsync().Completed = (asyncInfo, asyncStatus) => {Console.WriteLine($"{asyncInfo.GetResults().Count}\n");};
    Thread.Sleep(-1);}}
我在编译这篇文章时使用了:

csc same.cs /r:"C:\Program Files (x86)\Windows Kits\10\References\10.0.18362.0\Windows.Foundation.UniversalApiContract\8.0.0.0\Windows.Foundation.UniversalApiContract.winmd" /r:System.Runtime.dll /r:"C:\Program Files (x86)\Windows Kits\10\References\10.0.18362.0\Windows.Foundation.FoundationContract\3.0.0.0\Windows.Foundation.FoundationContract.winmd" /langversion:preview
我使用的是Visual Studio 2019构建工具,运行的是Windows Server 2019

我正在寻找MSFT的答案。如何利用所述接口的任何VPN功能

这是我的C程序的输出:

0
0
SET0:1
0
SET0:1
0
SET1:1
0
Amount of profiles collected 0
SET0:1
0
1表示VpnManagementErrorStatus_其他。下面是C++程序输出:

1
1
Found 0 profiles
1
以下是C变量输出:

0

这个问题源于我没有证明我的申请

我已经发现,在IDA中,有一个对GetCurrentPackageFamilyName的调用,然后在函数中进行其他调用,检查返回值是否有签名,即errorneous,如果是,则没有执行任何实际操作

以下是我修复了issueAppxManifest.xml的演示:


要不要解释一下反对票?工具。
0
<?xml version="1.0" encoding="utf-8"?>

<Package
  xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
  xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
  xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
  xmlns:r="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
  xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5"
  xmlns:desktop4="http://schemas.microsoft.com/appx/manifest/desktop/windows10/4" 
  xmlns:iot2="http://schemas.microsoft.com/appx/manifest/iot/windows10/2"
  IgnorableNamespaces="uap mp r uap5 desktop4 iot2">

  <Identity 
    Name="Sasho648.Internal.RmouseVPN.C" 
    Publisher="CN=Sasho648 Corporation, O=Sasho648 Corporation, L=Sofia, C=BG" 
    Version="1.0.0.0" />

  <mp:PhoneIdentity PhoneProductId="a771635b-3275-47f4-bfc9-72642a9b128b" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

  <Properties>
    <DisplayName>MobileBroadband</DisplayName>
    <PublisherDisplayName>Microsoft Corporation</PublisherDisplayName>
    <Logo>water-2748640_1920.png</Logo>
  </Properties>

  <Dependencies>
    <TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.10240.0" MaxVersionTested="10.0.18362.0" />
  </Dependencies>

  <Resources>
    <Resource Language="en-us"/>
  </Resources>

  <Applications>
    <Application Id="App"
      Executable="rmousevpn.exe"
      EntryPoint="RmouseVPN.App"
      desktop4:SupportsMultipleInstances="true"
      desktop4:Subsystem="console"
      iot2:Subsystem="console" 
      iot2:SupportsMultipleInstances="true">
<Extensions>  
    <uap5:Extension   
      Category="windows.appExecutionAlias">  
      <uap5:AppExecutionAlias desktop4:Subsystem="console">  
        <uap5:ExecutionAlias Alias="rmousevpn.exe" />  
      </uap5:AppExecutionAlias>  
    </uap5:Extension>  
</Extensions>  
      <uap:VisualElements
        DisplayName="vpnExecutioner"
        Square150x150Logo="water-2748640_1920.png"
        Square44x44Logo="water-2748640_1920.png"
        Description="Execute VPNs connections"

        BackgroundColor="#00b2f0">
      </uap:VisualElements>
    </Application>
  </Applications>

  <Capabilities>
      <r:Capability Name="networkingVpnProvider"/>
  </Capabilities>
</Package>
Add-AppxPackage -Path .\Appxmanifest.xml -Register