System name using C#
-
Hai, Can anyone tell me how to get the name of the computer (in which the code is running) using c#? thanks.
Thought this one should do
String s = System.Diagnostics.Process.GetCurrentProcess().MachineName;
// Fazlul
Get RadVC today! Play RAD in VC++ http://www.capitolsoft.com
-
Thought this one should do
String s = System.Diagnostics.Process.GetCurrentProcess().MachineName;
// Fazlul
Get RadVC today! Play RAD in VC++ http://www.capitolsoft.com
-
Its giving me only a '.', its not giving me the name of the machine. any other suggestions????:confused: omkamal
Ok. This is what I found out. I dont think there is a direct GetComputerName function in c# (as far as I know). Instead I read the following registry key HKLM\System\CurrentControlSet\Control\ComputerName\ComputerName. I hope this key is created in all machine because the System subkey stores sys related info. If anyone wants to know the computer name, this is next to a good solution. Use, Microsoft.Win32 namespace for Registry related classes in c#. One more thing "Naivete" and "omkamal" are one and the same. I just changed my username. Thanks for your help. omkamal
-
Its giving me only a '.', its not giving me the name of the machine. any other suggestions????:confused: omkamal
You're right, it doesn't work on my system either. According to .NET documentation, MachineName property should return the name of the system
Gets the name of the computer the associated process is running on.
// Fazlul
Get RadVC today! Play RAD in VC++ http://www.capitolsoft.com
-
Hai, Can anyone tell me how to get the name of the computer (in which the code is running) using c#? thanks.
Naivete wrote: Can anyone tell me how to get the name of the computer (in which the code is running) using c#? Try this:
string s = SystemInformation.ComputerName;
Kelly Herald Software Developer Micronpc, LLC -
You're right, it doesn't work on my system either. According to .NET documentation, MachineName property should return the name of the system
Gets the name of the computer the associated process is running on.
// Fazlul
Get RadVC today! Play RAD in VC++ http://www.capitolsoft.com
But if you read the document further it will also say that this property holds true only when you are trying to reach a remote computer... Remarks Specify a value for the MachineName property to view the processes running on another computer on the network. You can view statistical data and process information for processes running on remote computers but you .... omkamal
-
Naivete wrote: Can anyone tell me how to get the name of the computer (in which the code is running) using c#? Try this:
string s = SystemInformation.ComputerName;
Kelly Herald Software Developer Micronpc, LLCAwesome! Thanks Kelly. I appreciate your reply. I was so surprised how come c# doesnot provide such a functionality. But shame on me, that I felt so frustrating to check every single class for it. Nor did I try different search strings. Thanks again, Omkumar. omkamal
-
Naivete wrote: Can anyone tell me how to get the name of the computer (in which the code is running) using c#? Try this:
string s = SystemInformation.ComputerName;
Kelly Herald Software Developer Micronpc, LLC -
But if you read the document further it will also say that this property holds true only when you are trying to reach a remote computer... Remarks Specify a value for the MachineName property to view the processes running on another computer on the network. You can view statistical data and process information for processes running on remote computers but you .... omkamal
omkamal wrote: But if you read the document further it will also say that this property holds true only when you are trying to reach a remote computer... Sorry, I was obviously mistaken. I guess you can try SystemInformation::ComputerName, as suggested in another post. // Fazlul
Get RadVC today! Play RAD in VC++ http://www.capitolsoft.com
-