Announcement

Collapse
No announcement yet.

How to get the name of the current computer ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get the name of the current computer ?

    Hi PBCC programmers !

    I want to get the network-name of the computer, on which
    my PBCC-exe is running.

    For example:
    The name of the computer is "notebook1".
    How to get this name into my Pbcc applikation ?

    Thank you and best regards.

    Karl

    ------------------
    Karl
    Karl

  • #2
    I did a search for "computer name" and the search returned (this web site)
    over 190 hits. You can use any Win Api call that would return
    the name. I am sure, I remember seeing how to do this being posted.

    ------------------
    Roy Cline

    [This message has been edited by Roy Cline (edited November 30, 2004).]
    Roy Cline

    Comment


    • #3
      Try this one.
      Code:
      ' --------------------------------------------------------------------------
      ' Retrieves the computer name of the current system.
      ' --------------------------------------------------------------------------
      FUNCTION DS_GetComputerName () AS STRING
         LOCAL lResult AS LONG
         LOCAL buff    AS ASCIIZ * %MAX_COMPUTERNAME_LENGTH '15 bytes
         LOCAL nlen    AS DWORD
         nlen = SIZEOF(buff)
         lResult = GetComputerName(buff, nlen)
         IF lResult <> 0 THEN FUNCTION = buff
      END FUNCTION

      ------------------
      Forum: http://www.jose.it-berater.org/smfforum/index.php

      Comment


      • #4
        To get José's example to work, you need to #INCLUDE "WIN32API.INC" somewhere in front of his example.

        Knuth

        ------------------
        http://www.softAware.de

        Comment


        • #5
          Hello Jose´!

          >>> FUNCTION DS_GetComputerName () AS STRING....

          Thank you for the example.

          It works fine on Win-XP but not on Win98.
          Do i have to change the code for using with Win 98?

          Best regards
          Karl




          ------------------
          Karl
          Karl

          Comment


          • #6
            Karl,
            try changing the following
            Code:
            LOCAL buff    AS ASCIIZ * %MAX_COMPUTERNAME_LENGTH '15 bytes
            to
            LOCAL buff    AS ASCIIZ * %MAX_COMPUTERNAME_LENGTH + 1 '15 bytes + 1
            Pierre

            Comment


            • #7
              Hello Piere !

              >>> LOCAL buff AS ASCIIZ * %MAX_COMPUTERNAME_LENGTH + 1 '15 bytes + 1

              Works !

              Thank you !

              Karl

              ------------------
              Karl
              Karl

              Comment


              • #8
                Hi,

                Here is a piece of code I wrote "Prolly found it someplace"

                writen in PB/CC 3.04

                #COMPILE CON
                #DIM ALL
                $INCLUDE "WIN32API.INC"

                FUNCTION PBMAIN () AS LONG

                LOCAL sServer AS ASCIIZ * 256
                LOCAL sUserID AS ASCIIZ * 256
                GetUserName sUserID, 256
                GetComputerName sServer, 256
                PRINT sUserID
                PRINT sServer

                END FUNCTION


                ------------------
                Leslie Potts

                Comment

                Working...
                X