Article View: borland.public.cppbuilder.nativeapi
Article #3313Re: computer sid
From: Mike Collins
Date: Tue, 18 Jul 2006 23:12
Date: Tue, 18 Jul 2006 23:12
75 lines
3753 bytes
3753 bytes
No problem, please note that this is taken directly from our installer dll
so there are some funny throw statements to break the execution - for
simplicity sake. I needed to pass back an exact reason code for any failure
so I just raised an EAbort exception and used the help id to reply the error
code back - it's a bit sloppy but worked in this case.
AnsiString szComputerName;
szComputerName.SetLength(MAX_COMPUTERNAME_LENGTH + 1);
DWORD dwSize = szComputerName.Length();
if (GetComputerName(szComputerName.c_str(), &dwSize))
{
szComputerName = szComputerName + "$";
PSID pSID = NULL;
DWORD dwSIDSize = 0;
TCHAR cDomain[1024] = {0};
DWORD dwDomainSize = 1024;
SID_NAME_USE AccountType;
LookupAccountName(NULL, szComputerName.c_str(), NULL, &dwSIDSize,
cDomain, &dwDomainSize, &AccountType);
if (dwSIDSize)
{
pSID = (PSID)GlobalAlloc(GPTR, dwSIDSize);
if (pSID)
{
if (LookupAccountName(NULL, szComputerName.c_str(), pSID,
&dwSIDSize, cDomain, &dwDomainSize, &AccountType))
{
char *cStringSID;
if (ConvertSidToStringSid(pSID, &cStringSID))
{
// Copy AnsiString to char buffer - potential for
buffer overflow with strncpy
strncpy(p_cCompHash, szSIDHash.c_str(),
szSIDHash.Length());
LocalFree(cStringSID);
cStringSID = NULL;
GlobalFree(pSID);
pSID = NULL;
iRtn = 0;
}
else
{
GlobalFree(pSID);
pSID = NULL;
throw EAbort("", -6); // - SID convertion
error....
}
}
else
{
GlobalFree(pSID);
pSID = NULL;
throw EAbort("", -5); // - SID Lookup error
}
}
else
throw EAbort("", -4); // - SID allocation error
}
else
throw EAbort("", -3); // - Initial look-up error
}
else
throw EAbort("", -2); // - Error geting the computers
name...
Works great for me.
"TMBTC" <jkofsky@bellsouth.net> wrote in message
news:44bc33bf$1@newsgroups.borland.com...
> Could you paot the code segment for this please?
> TMBTC
>
Technical Details
Message-ID:
<44bd6acc$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<44b3a626$1@newsgroups.borland.com> <44b3d727$1@newsgroups.borland.com> <44b3f601$1@newsgroups.borland.com> <44b42978@newsgroups.borland.com> <44b433fa$1@newsgroups.borland.com> <44b51e96@newsgroups.borland.com> <44bc33bf$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,752843d06b3a660f X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Mike Collins" <its@TheBottomOfThePost.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <44b3a626$1@newsgroups.borland.com> <44b3d727$1@newsgroups.borland.com> <44b3f601$1@newsgroups.borland.com> <44b42978@newsgroups.borland.com> <44b433fa$1@newsgroups.borland.com> <44b51e96@newsgroups.borland.com> <44bc33bf$1@newsgroups.borland.com> Subject: Re: computer sid Date: Wed, 19 Jul 2006 00:12:12 +0100 Lines: 76 Organization: SDA Ltd X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.2663 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.2663 NNTP-Posting-Host: 88.110.16.192 Message-ID: <44bd6acc$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1153264332 88.110.16.192 (18 Jul 2006 16:12:12 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail