Results 1 to 5 of 5

Thread: How to get the computer name from other computer where my program installed?

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2019
    Posts
    54

    How to get the computer name from other computer where my program installed?

    I have a shared program from other PC. I want to display into textbox the computer name from other PC where my shared program installed.
    Using "application.startup" the vb can detect where the program came from. Yes it displays the path (e.g. \\PC1\sampleprogram\) but I want to get or to display "PC1" into textbox. Any suggestion or modification regarding my code?

    What I have tried:

    First try but not working:

    Hide Copy Code
    txtServerName.Text = System.Net.Dns.GetHostName(Application.StartupPath)


    Second try:

    Hide Copy Code
    txtServerName.Text = System.Environment.GetEnvironmentVariable("ComputerName"(Application.StartupPath))


    All are not working. It shows error "Additional information: Conversion from string "C:\Users\r0n\Documents\Visual St" to type 'Integer' is not valid."

  2. #2
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,034

    Re: How to get the computer name from other computer where my program installed?

    try one of these...
    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim UserMachine As Microsoft.Win32.RegistryKey
            Label1.Text = Microsoft.Win32.Registry.CurrentUser.Name.ToString
            Label2.Text = Environment.UserName.ToString()
            Label3.Text = SystemInformation.UserName
            Label4.Text = System.Security.Principal.WindowsIdentity.GetCurrent().Name
    
            '... Windows Forms-'SystemInformation.UserName', 
            'or 'System.Security.Principal.WindowsIdentity.GetCurrent().Name'.
        End Sub
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,522

    Re: How to get the computer name from other computer where my program installed?

    Yes it displays the path (e.g. \\PC1\sampleprogram\) but I want to get or to display "PC1" into textbox. Any suggestion or modification regarding my code?
    If Application.Startup displays the server accurately, then it seems to me the simpest solution is to first remove the leading "\" and then split on the "" and take the first element in the resulting array.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,274

    Re: How to get the computer name from other computer where my program installed?

    Firstly, does Environment.MachineName not work? Secondly, if you already have "\\PC1\sampleprogram" then how hard can it be to get the "PC1" part out of that? The Path class may be able to do it, although I've never tried with a UNC path, but you could easily do it with IndexOf and Substring.

  5. #5
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,522

    Re: How to get the computer name from other computer where my program installed?

    Quote Originally Posted by jmcilhinney View Post
    Firstly, does Environment.MachineName not work?.
    Wouldn't that return the current computer name though? Not the name of the server where they are running the app from. Or am I mistaken on that?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width