Click here to Skip to main content
14,575,017 members
Rate this:
Please Sign up or sign in to vote.
See more: , +
I want to display 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:

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


Second try:

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."
Posted
Updated 2-Jun-20 4:28am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Use the Uri class[^].
Dim startupUri As New Uri(Application.StartupPath)
If startupUri.IsUnc Then
    txtServerName.Text = startupUri.Host
Else
    txtServerName.Text = Environment.MachineName
End If
   
Comments
kyrons 3-Jun-20 4:47am
   
Wow...Thank you so much Richard Deeming, my friend, it works perfectly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100