473,320 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

getting network computer name

Hi,
I know that System.Windows.Forms.SystemInformation.ComputerNam e
retrieves the current computer's name, but is it possible to fetch the
computer's name from a file path?

ie. G:\file.txt exists on the computer named Tool, how I can get the
name Tool?

Thanks.
Tommy

--
http://www.treehugger.com

Jul 12 '06 #1
1 3273
I think you will need to use P/Invoke on WNetGetUniversalName. From
this you can get the UNC path like \\machinename\sharename. This code
worked for me:

[DllImport("mpr.dll")]
[return: MarshalAs(UnmanagedType.U4)]
static extern int WNetGetUniversalName(
string lpLocalPath,
[MarshalAs(UnmanagedType.U4)] int dwInfoLevel,
IntPtr lpBuffer,
[MarshalAs(UnmanagedType.U4)] ref int lpBufferSize);

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode),
Serializable()]
class MyUNC
{
[MarshalAs(UnmanagedType.LPStr)]
public string UniversalName;
[MarshalAs(UnmanagedType.LPStr)]
public string ConnectionName;
[MarshalAs(UnmanagedType.LPStr)]
public string RemainingPath;
}
[STAThread]
static void Main()
{
int bufferSize = 2000;
IntPtr buffer = Marshal.AllocHGlobal(bufferSize);
int ret = WNetGetUniversalName("P:", 2, buffer, ref bufferSize);
if (ret == 0)
{
MyUNC unc = new MyUNC();
Marshal.PtrToStructure(buffer, unc);
Console.WriteLine(unc.UniversalName);
}
Marshal.FreeHGlobal(buffer);
return;
}

John

wh*******@gmail.com wrote:
Hi,
I know that System.Windows.Forms.SystemInformation.ComputerNam e
retrieves the current computer's name, but is it possible to fetch the
computer's name from a file path?

ie. G:\file.txt exists on the computer named Tool, how I can get the
name Tool?

Thanks.
Tommy

--
http://www.treehugger.com
Jul 13 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
5
by: z. f. | last post by:
i need to get the computer name from an aspx page. i use System.Windows.Forms.SystemInformation.ComputerName() and it's working fine, but in second thought, it might not be recomended to use the...
4
by: Alex | last post by:
Hi All I'm writing scripts in VBS fore years. But now I've to write a tool in Visual Basic .Net which has to connet to a Windows domain. I know how to do this in VBS but I don't find a way in...
6
by: Al | last post by:
Hi I need to get the IP address of a computer on the network that uses dynamic IP addressing. Is there anyway I get the address but providing the name of the computer? Thanks in advance Al
0
by: NoWhereMan | last post by:
Hello, I'm trying to get the list of shared folders of a network computer and add them to a combo box. I'm using the bellow code in VB .NET. Code ==== Private Sub EnumShares(ByVal Machine As...
0
by: rony_16 | last post by:
Hi , I am writing a program that part of than program if to add a new network drive to the user. The adding part i know how to do (by win api "WNetAddConnection2A") but i want to check first if...
5
by: lmttag | last post by:
ASP.NET 2.0 (C#) application Intranet application (not on the Internet) Using Windows authentication and impersonation Windows Server 2003 (IIS6) Server is a member server on a domain Logged...
15
by: =?Utf-8?B?TVNU?= | last post by:
To demonstrate my problem, I have a very simple VB Windows application. It has a text box that is used to display a counter, a button to reset the counter, and a timer that increments the counter...
6
by: =?Utf-8?B?Tmljb2xhcw==?= | last post by:
Basically I got a LAN with several computer. From Computer A I'll got my appliation which should do the following: Check if any other computer lost connection to the network. (Computer B may has...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.