Announcement

Collapse
No announcement yet.

Get Win login/ computer name from PB

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

  • Get Win login/ computer name from PB

    I need help again. I need the ability to get an NT login name
    (used to login into an NT server) and / or the computer name and
    computer description (from network neighborhood, properties,
    identification screen).
    Has anyone seen any code for this?
    Or any ideas how to do this?
    Thanks,
    Deon


    ------------------
    Deon Judkins
    Deon

  • #2
    Under Win2000 and NT4, you can get the computer name and user name from environment strings (See ENVIRON$).

    At the command-line on my 2k and NT systems, SET gives me (amongst lots of other info):
    Code:
    USERDOMAIN=TWOK
    USERNAME=Administrator
    Where USERDOMAIN is the computername, and USERNAME is... yes, the logged-on User's name.

    I'm not sure how to get that programmatically under DOS in NT/2K. My original DOS-level GetComputerName() code does not work on my 2K box.

    However, if you have PB/CC, you can ask Windows directly, and of course, you can synchronously SHELL to a PB/CC application from PB/DOS in Win32.
    The PB/CC code is pretty straight forward to get the Computer Name and User Name:
    Code:
    #INCLUDE "win32api.INC"
    FUNCTION PBMAIN
        DIM szName AS ASCIIZ * %MAX_PATH
        IF GetComputerName(szName, SIZEOF(szName)) THEN
            PRINT szName
        END IF
        IF GetUserName(szName, SIZEOF(szName)) THEN
            PRINT szName
        END IF
        WAITKEY$
    END FUNCTION
    I hope this helps!

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      COMPUTERNAME is the computer name. USERDOMAIN is the network domain.

      ------------------
      Tom Hanlin
      PowerBASIC Staff

      Comment


      • #4
        Good catch. On both of my networks here USERDOMAIN is the computer name. No domain controllers here.

        The COMPUTERNAME environment variable cant be much good, as it scrolls off the screen too fast when dumping all the environment vars with SET!

        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment

        Working...
        X