SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 7 of 7

Thread: GetComputerName

  1. #1
    Senior Member
    Join Date
    Jan 2002
    Location
    UK
    Posts
    108
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    GetComputerName

    I want to distribute a script to a range of PCs that uses their names as a variable.

    WinAPI32.GetComputerName doesn't work in DelphiScript since you can't pass parameters by reference.

    I don't want to use the example that depends on interrogating the log as I don't intend for the client PCs to maintain a log.

    Is there another way to get a PC's name at run-time?

  2. #2
    Member
    Join Date
    Oct 2002
    Location
    Kansas City
    Posts
    79
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: GetComputerName

    bughunta,

    You can convert this to run in DelphiScript as well:

    Sub Main()

    strComputer = "."
    strMsg = ""

    Set objWMIService = GetObject("winmgmts:\\" & strComputer)
    Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)

    For Each objItem In colItems

    strMsg = strMsg & "Manufacturer: " & objItem.Manufacturer & vbCrLf
    strMsg = strMsg & "Model: " & objItem.Model & vbCrLf
    strMsg = strMsg & "Name: " & objItem.Name

    Next

    MsgBox strMsg, vbInformation, "WMI"

    End Sub

    If you have time, look into the PrimalScript IDE 30 day trial. Even if you decide not to purchase it you will get much more information about using the WMI. I use the PrimalScript IDE with TC...it makes for quick development. I like the WMI Wizard, OLE Server panel, and the Snippet functionality. Maybe you will find other uses.

  3. #3
    Senior Member
    Join Date
    Jan 2002
    Location
    UK
    Posts
    108
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: GetComputerName

    Thanks. I actually meant the name of the PC in the network, which I found in the registry and am hoping is in the same place in all versions of Windows:
    </font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">function GetComputerName;
    begin
    result :=
    Storages.Registry('System\CurrentControlSet\Contro l\ComputerName\ComputerName',
    HKEY_LOCAL_MACHINE).GetOption('ComputerName', 'Error!');
    end;</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">

  4. #4
    Member
    Join Date
    Oct 2002
    Location
    Kansas City
    Posts
    79
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: GetComputerName

    bughunta,

    In my example above the objItem.Name does return the name of the computer just as the GetComputerName API function and as your GetComputerName function. I included the objItem.Manufacturer and objItem.Model to demonstrate how you can return other computer specific properties. This may not be of importance to you but I use many of the WMI functionality for gathering metrics as our scripts run.

    By the way I did find the computer name in the above mentioned Registry locations for all of our XP Pro machines and all of our 2000 Server machines. All of our 2003 Server machines had Control001 and Control002 nodes rather than the Control only node. However, this may only be specific to our OS configurations.

  5. #5
    Junior Member
    Join Date
    Sep 2001
    Posts
    21
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: GetComputerName

    Hi,

    You can also get the computer name using the ComputerName property of the WScript.Network OLE object:

    [code]
    [DelphiScript]

    procedure Test;
    var
    CompName;
    begin
    CompName := Sys.GetOleObject('WScript.Network').ComputerName;
    Log.Message(CompName);
    end;
    [\code]

    Atanas
    AutomatedQA

  6. #6
    Senior Member
    Join Date
    Jan 2002
    Location
    UK
    Posts
    108
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: GetComputerName

    All good stuff - opened up a whole new line of enquiry - thanks!

  7. #7
    Junior Member
    Join Date
    Mar 2003
    Location
    Sarov, N.Novgorod, Russia
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: GetComputerName

    Hi everybody,

    you can use foloowing:
    .....
    gl_szTestBox = tsEnviron( "COMPUTERNAME" );
    .....

    function tsEnviron( szVariable )
    {
    var WshShell = new ActiveXObject("WScript.Shell");
    var szExpanded = WshShell.ExpandEnvironmentStrings("%" + szVariable + "%");
    if( szExpanded == szVariable )
    return "";
    return szExpanded;
    }

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 10.00%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 07:59 AM.

Copyright BetaSoft Inc.