GetComputerObjectNameW Win API is failing
-
I was trying to use win API
GetComputerObjectNameW
as below but I am getting error. Can someone help me.
#include
#include
#include
typedef enum {
NameUnknown,
NameFullyQualifiedDN,
NameSamCompatible,
NameDisplay,
NameUniqueId,
NameCanonical,
NameUserPrincipal,
NameCanonicalEx,
NameServicePrincipal,
NameDnsDomain,
NameGivenName,
NameSurname
} EXTENDED_NAME_FORMAT, *PEXTENDED_NAME_FORMAT;int main()
{
EXTENDED_NAME_FORMAT enf = NameFullyQualifiedDN;
LPWSTR pwszComputerName;
DWORD dwLen;dwLen = 0; GetComputerObjectNameW(enf, NULL, &dwLen); pwszComputerName = new WCHAR\[dwLen + 1\]; if(NULL == pwszComputerName) { return 0; } if(!GetComputerObjectNameW(NameSamCompatible, pwszComputerName, &dwLen)) { delete pwszComputerName; return 0; } sbstrTrustee = pwszComputerName; wprintf(L"GetComputerObjectName: %s\\n", pwszComputerName); delete pwszComputerName;
}
Some of Error message is as below.
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(117): error C2146: syntax error: missing ';' before identifier 'GetUserNameExA'
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(121): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(126): error C2086: 'BOOLEAN SEC_ENTRY': redefinition
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(117): note: see declaration of 'SEC_ENTRY'
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(126): error C2146: syntax error: missing ';' before identifier 'GetUserNameExW'
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(130): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int -
I was trying to use win API
GetComputerObjectNameW
as below but I am getting error. Can someone help me.
#include
#include
#include
typedef enum {
NameUnknown,
NameFullyQualifiedDN,
NameSamCompatible,
NameDisplay,
NameUniqueId,
NameCanonical,
NameUserPrincipal,
NameCanonicalEx,
NameServicePrincipal,
NameDnsDomain,
NameGivenName,
NameSurname
} EXTENDED_NAME_FORMAT, *PEXTENDED_NAME_FORMAT;int main()
{
EXTENDED_NAME_FORMAT enf = NameFullyQualifiedDN;
LPWSTR pwszComputerName;
DWORD dwLen;dwLen = 0; GetComputerObjectNameW(enf, NULL, &dwLen); pwszComputerName = new WCHAR\[dwLen + 1\]; if(NULL == pwszComputerName) { return 0; } if(!GetComputerObjectNameW(NameSamCompatible, pwszComputerName, &dwLen)) { delete pwszComputerName; return 0; } sbstrTrustee = pwszComputerName; wprintf(L"GetComputerObjectName: %s\\n", pwszComputerName); delete pwszComputerName;
}
Some of Error message is as below.
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(117): error C2146: syntax error: missing ';' before identifier 'GetUserNameExA'
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(121): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(126): error C2086: 'BOOLEAN SEC_ENTRY': redefinition
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(117): note: see declaration of 'SEC_ENTRY'
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(126): error C2146: syntax error: missing ';' before identifier 'GetUserNameExW'
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(130): error C4430: missing type specifier - int assumed. Note: C++ does not support default-intWhy do you redefine the EXTENDED_NAME_FORMAT enumeration? :confused:
-
Why do you redefine the EXTENDED_NAME_FORMAT enumeration? :confused:
I first try without defining enum after that try with enum. In both case I am getting compilation error.
-
I was trying to use win API
GetComputerObjectNameW
as below but I am getting error. Can someone help me.
#include
#include
#include
typedef enum {
NameUnknown,
NameFullyQualifiedDN,
NameSamCompatible,
NameDisplay,
NameUniqueId,
NameCanonical,
NameUserPrincipal,
NameCanonicalEx,
NameServicePrincipal,
NameDnsDomain,
NameGivenName,
NameSurname
} EXTENDED_NAME_FORMAT, *PEXTENDED_NAME_FORMAT;int main()
{
EXTENDED_NAME_FORMAT enf = NameFullyQualifiedDN;
LPWSTR pwszComputerName;
DWORD dwLen;dwLen = 0; GetComputerObjectNameW(enf, NULL, &dwLen); pwszComputerName = new WCHAR\[dwLen + 1\]; if(NULL == pwszComputerName) { return 0; } if(!GetComputerObjectNameW(NameSamCompatible, pwszComputerName, &dwLen)) { delete pwszComputerName; return 0; } sbstrTrustee = pwszComputerName; wprintf(L"GetComputerObjectName: %s\\n", pwszComputerName); delete pwszComputerName;
}
Some of Error message is as below.
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(117): error C2146: syntax error: missing ';' before identifier 'GetUserNameExA'
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(121): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(126): error C2086: 'BOOLEAN SEC_ENTRY': redefinition
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(117): note: see declaration of 'SEC_ENTRY'
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(126): error C2146: syntax error: missing ';' before identifier 'GetUserNameExW'
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(130): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int -
I first try without defining enum after that try with enum. In both case I am getting compilation error.
Add these definition: #define _WIN32_WINNT 0x0500 #define SECURITY_WIN32 Remove the redefinition of enum. Define the sbstrTrustee variable. // edited: also don't forget to include the Secur32.lib library.
-
Add these definition: #define _WIN32_WINNT 0x0500 #define SECURITY_WIN32 Remove the redefinition of enum. Define the sbstrTrustee variable. // edited: also don't forget to include the Secur32.lib library.
Hi Victor, I have modified program according to your suggestion but I am not getting expected result. I want to use NameFullyQualifiedDN enum value and get the fully qualified distinguished name (for example, CN=Jeff Smith,OU=Users,DC=Engineering,DC=Microsoft,DC=Com). Regards, Rajnesh
-
Hi Victor, I have modified program according to your suggestion but I am not getting expected result. I want to use NameFullyQualifiedDN enum value and get the fully qualified distinguished name (for example, CN=Jeff Smith,OU=Users,DC=Engineering,DC=Microsoft,DC=Com). Regards, Rajnesh
Sorry, I don't know what is wrong/correct in your test. I've just tested your code and got the result in the form: [my_domain_name].[my_computer_name]$ wich is in my case 100% correct.
-
Sorry, I don't know what is wrong/correct in your test. I've just tested your code and got the result in the form: [my_domain_name].[my_computer_name]$ wich is in my case 100% correct.
Hi Victor, There was configuration issue with my windows laptop, so I was facing issue. Thanks for your feedback.