Chinaunix首页 | 论坛 | 博客

=.=

  • 博客访问: 138055
  • 博文数量: 50
  • 博客积分: 3000
  • 博客等级: 中校
  • 技术积分: 550
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-25 17:22
文章分类

全部博文(50)

文章存档

2010年(7)

2009年(43)

我的朋友

分类: WINDOWS

2009-09-27 23:52:59

LSA_HANDLE GetPolicyHandle()
{
    LSA_OBJECT_ATTRIBUTES ObjectAttributes;
    WCHAR SystemName[] = TEXT("");
    USHORT SystemNameLength;
    LSA_UNICODE_STRING lusSystemName;
    NTSTATUS ntsResult;
    LSA_HANDLE lsahPolicyHandle;

    // Object attributes are reserved, so initialize to zeroes.

    ZeroMemory(&ObjectAttributes, sizeof(ObjectAttributes));


    // Get a handle to the Policy object.

    ntsResult = LsaOpenPolicy(
        NULL,
        &ObjectAttributes, //Object attributes.

        POLICY_ALL_ACCESS, //Desired access permissions.

        &lsahPolicyHandle //Receives the policy handle.

        );

    if (ntsResult != 0) // sth. wrong in here

    {
        // An error occurred. Display it as a win32 error code.

        wprintf(L"OpenPolicy returned %lu\n",
            LsaNtStatusToWinError(ntsResult));
        return NULL;
    }
    return lsahPolicyHandle;
}



int main( void )
{
    LSA_HANDLE hPolicyHandle = GetPolicyHandle();

    NTSTATUS status;
    PPOLICY_PRIMARY_DOMAIN_INFO ppdiDomainInfo;

    if ( hPolicyHandle )
    {
        status = LsaQueryInformationPolicy( hPolicyHandle,
            PolicyPrimaryDomainInformation,
            (PVOID *)&ppdiDomainInfo);

        if ( status )
        {
            printf("LsaQueryInformationPolicy error, %d\n", GetLastError() );
        }
        else
        {
            if ( ppdiDomainInfo->Sid )
            {
                DebugBox( TEXT("In Domain Controler!") );
            }
            else
            {
                DebugBox( TEXT("StandAlone Computer!") );
            }
        }

    }



    LsaFreeMemory((LPVOID)ppdiDomainInfo);
}


阅读(853) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~