🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
9 messages
9 total messages Started by Mike Collins Tue, 11 Jul 2006 13:22
computer sid
#3290
Author: Mike Collins
Date: Tue, 11 Jul 2006 13:22
14 lines
1314 bytes
hi all,

Just a quicky - couldn't find anything solid on google.

I need to retrieve the computer SID for identification purposes, i can find 
any solid (or simple :-)  code to do this.

Does anyone have any code snippets or could point me in the right direction. 
Looking for something quick and slick but need the SID as a string and need 
to be able to run it on 2k and above.

Thanks in advance,

Mike C 
Re: computer sid
#3291
Author: Remy Lebeau (TeamB)
Date: Tue, 11 Jul 2006 16:51
18 lines
1436 bytes
"Mike Collins" <its@TheBottomOfThePost.com> wrote in message
news:44b3a626$1@newsgroups.borland.com...

> I need to retrieve the computer SID for identification purposes,
> i can find any solid (or simple :-)  code to do this.

There is no SID for the computer itself.  Only for individual users.  There
is no computer-wide ID available at all (expect for the CPU ID, but most
people disable that).

> Does anyone have any code snippets or could point me in the
> right direction.

What EXACTLY are you trying to accomplish?


Gambit
Re: computer sid
#3293
Author: Mike Collins
Date: Tue, 11 Jul 2006 19:03
52 lines
2876 bytes
Sorry Remy, i thought the was a SID defined for the computer when the 
windows installer is first run.

I'm basing this on the article that i read previously on sysinternals 
(http://www.sysinternals.com/utilities/newsid.html) and on chapter 8 of 
Inside Windows 2000 3rd Edition (by D.Solomon and M.Russinovich).  I run the 
tool, psgetsid.exe, from the sysinternals sight 
(http://www.sysinternals.com/utilities/psgetsid.html) and it returns a SID 
for my system.

Am i confusing my terminology here?  We have a basic registration system 
where i was intending to use a hash of (what i thought was the) computer SID 
to identify the installation on a specific windows version.  From reading 
the article above i understand that this can (if it does indead exists) be 
altered but we are just trying to track the installation and prevent it 
being installed on the same window box twice.  The reason for the is quite 
specific - there is method in the madness...

Obviously there are many different was to try and identify the system i.e. 
MAC address but the design modal that we have relates to a specific window 
installation as opposed to a specific machine.

Please advice me if I'm wrong here...

Many thanks in advance,

Mike C


"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
news:44b3d727$1@newsgroups.borland.com...
>
> "Mike Collins" <its@TheBottomOfThePost.com> wrote in message
> news:44b3a626$1@newsgroups.borland.com...
>
>> I need to retrieve the computer SID for identification purposes,
>> i can find any solid (or simple :-)  code to do this.
>
> There is no SID for the computer itself.  Only for individual users. 
> There
> is no computer-wide ID available at all (expect for the CPU ID, but most
> people disable that).
>
>> Does anyone have any code snippets or could point me in the
>> right direction.
>
> What EXACTLY are you trying to accomplish?
>
>
> Gambit
>
> 
Re: computer sid
#3294
Author: Mike Collins
Date: Tue, 11 Jul 2006 19:07
48 lines
3171 bytes
Just in following with the previous post, I've cut and pasted this from the 
books electronic version:

// 
*******************************************************************************

When you install Windows 2000, the Windows 2000 Setup program issues the 
computer a SID. Windows 2000 assigns SIDs to local accounts on the computer. 
Each local-account SID is based on the source computer's SID and has a RID 
at the end. RIDs for user accounts and groups start at 1000 and increase in 
increments of 1 for each new user or group. Similarly, Windows 2000 issues a 
SID to each newly created Windows 2000 domain. Windows 2000 issues to new 
domain accounts SIDS that are based on the domain SID and have an appended 
RID (again starting at 1000 and increasing in increments of 1 for each new 
user or group). A RID of 1028 indicates that the SID is the 29th SID the 
domain issued.

Windows 2000 issues SIDS that consist of a computer or domain SID with a 
predefined RID to many predefined accounts and groups. For example, the RID 
for the administrator account is 500, and the RID for the guest account is 
501. A computer's local administrator account, for example, has the computer 
SID as its base with the RID of 500 appended to it:


  S-1-5-21-13124455-12541255-61235125-500

Windows 2000 also defines a number of built-in local and domain SIDs to 
represent groups. For example, a SID that identifies any and every account 
is the Everyone, or World, SID: S-1-1-0. Another example of a group that a 
SID can represent is the network group, which is the group that represents 
users who can log on to a machine from the network. The network-group SID is 
S-1-5-2. Table 8-2, reproduced here from the Platform SDK documentation, 
shows some of the basic well-known SIDs, their numeric values, and their 
use.

Copyright � 2000 by David A. Solomon and Mark E. Russinovich <- for piece of 
mind :)
// 
*******************************************************************************



"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
news:44b3d727$1@newsgroups.borland.com...
>
> "Mike Collins" <its@TheBottomOfThePost.com> wrote in message
> news:44b3a626$1@newsgroups.borland.com...
>
Re: computer sid
#3295
Author: Remy Lebeau (TeamB)
Date: Tue, 11 Jul 2006 22:42
20 lines
1584 bytes
"Mike Collins" <its@TheBottomOfThePost.com> wrote in message
news:44b3f601$1@newsgroups.borland.com...

> Sorry Remy, i thought the was a SID defined for the
> computer when the windows installer is first run.

This is the first I have every heard of it.  Looking into it, I found the
following:

    "A computer account name always has a trailing dollar sign ($). You can
use any APIs that takes a user account by passing in the computer name with
a dollar appended to it. With COMPUTERNAME$, you can use LookupAccountName()
API to get the SID of the computer."

You can use GetComputerName() to get the name of the local computer, and
then append '$' to it.


Gambit
Re: computer sid
#3296
Author: Mike Collins
Date: Tue, 11 Jul 2006 23:27
13 lines
1519 bytes
Thanks remy, thought i was going mad there :)

I hadn't read the snippet that you posted before - this looks like a nice 
simple way of achieving what i want.  It's late here so i'll give it a spin 
tomorrow and post if there is anything unusual.

Thanks again,

"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
news:44b42978@newsgroups.borland.com...
>
> "Mike Collins" <its@TheBottomOfThePost.com> wrote in message
> news:44b3f601$1@newsgroups.borland.com...
Re: computer sid
#3298
Author: Mike Collins
Date: Wed, 12 Jul 2006 16:08
8 lines
1289 bytes
Yeh, works fine.  Got the computer name and appended a '$' to the end then 
passed it to LookupAccountName() which returns the computer SID.

Thanks

Mike C

"Mike Collins" <its@TheBottomOfThePost.com> wrote in message 
Re: computer sid
#3310
Author: TMBTC
Date: Tue, 18 Jul 2006 01:05
14 lines
1429 bytes
Could you paot the code segment for this please?
TMBTC

"Mike Collins" <its@TheBottomOfThePost.com> wrote in message 
news:44b51e96@newsgroups.borland.com...
> Yeh, works fine.  Got the computer name and appended a '$' to the end then 
> passed it to LookupAccountName() which returns the computer SID.
>
> Thanks
>
> Mike C
>
> "Mike Collins" <its@TheBottomOfThePost.com> wrote in message
> 
Re: computer sid
#3313
Author: Mike Collins
Date: Tue, 18 Jul 2006 23:12
75 lines
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
> 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads