-
Jun 2nd, 2020, 09:31 AM
#1
Thread Starter
Member
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."
-
Jun 2nd, 2020, 09:36 AM
#2
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.
-
Jun 2nd, 2020, 10:15 AM
#3
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
-
Jun 2nd, 2020, 07:55 PM
#4
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.
-
Jun 2nd, 2020, 09:53 PM
#5
Re: How to get the computer name from other computer where my program installed?
Originally Posted by jmcilhinney
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
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|