🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #5374

retrieval of machine name

#5374
From: Jeff Kish
Date: Thu, 08 Sep 2005 20:25
53 lines
2390 bytes
Hi.

I would like a reliable way of getting the machine name of the machine
my application is executing on.

Is this reliable? It "seems" to work on windows 2000 and xp pro.
For now it is designed to fail silently, and return a default machine
name which the application handles (it just uses it to fill in a
default value)

Of course I borrowed the code for the registry evaluation from the
examples in cbuilder 6.0...

Thanks for the advice,
Jeff

AnsiString TFormInstall::tryToGetThisMachineName()
{
AnsiString asMachineName = "MACHINENAME";
AnsiString retMachineName = asMachineName;
    const String RegKey =
"\\SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName";
    TRegistry *MyRegistry = new TRegistry();
    MyRegistry->RootKey = HKEY_LOCAL_MACHINE;
    try {
        if(MyRegistry->OpenKey(RegKey, false)) {
            asMachineName = MyRegistry->ReadString("ComputerName");
            if (!asMachineName.IsEmpty()) {
                retMachineName = asMachineName;
            }
            else
            {
                //do nothing, just return after closing things up, the
default MACHINENAME
            }
        MyRegistry->CloseKey();
        }
    }
/*
    catch(ERegistryException &E)
    {
    	//ShowMessage(E.Message);
        delete MyRegistry;
        return;
    }
*/
    catch(...)
    {
    }
    delete MyRegistry;
    return retMachineName;
}
Jeff Kish
Technical Details
Message-ID: <pa71i1lvoi5hg9o0tjnm4at1b4nb05iori@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!atl-c02.usenetserver.com!news.usenetserver.com!atl-c04.usenetserver.com!news.usenetserver.com!newsfeed.media.kyoto-u.ac.jp!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,85086ba69e4c31b4,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Jeff Kish <jeff.kish@mro.com>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: retrieval of machine name
Date: Thu, 08 Sep 2005 16:25:27 -0400
Message-ID: <pa71i1lvoi5hg9o0tjnm4at1b4nb05iori@4ax.com>
X-Newsreader: Forte Agent 3.0/32.763
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 12.106.157.130
X-Trace: newsgroups.borland.com 1126211086 12.106.157.130 (8 Sep 2005 13:24:46 -0700)
Lines: 53
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!atl-c02.usenetserver.com!news.usenetserver.com!atl-c04.usenetserver.com!news.usenetserver.com!newsfeed.media.kyoto-u.ac.jp!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail