Declare Function GetComputerName Lib "kernel32" (ByVal lpBuffer As String, ByRef nMax As Integer) As Boolean
User-Defined Types:
None.
Notes:
The GetComputerName function retrieves the NetBIOS name of the local computer. This name is established at system startup, when the system reads it from the registry.
Tips & Tricks:
Make sure to go in to the build properties of your project and check "Allow Unsafe Code". Second version doesn't require this.
Sample Code:
using System.Management;
using System.Runtime.InteropServices;
Declare Unicode Function GetCompName2 Lib "Kernel32" Alias "GetComputerNameA" (ByVal Puffer As StringBuilder, ByRef Laenge As IntPtr) As Integer
Sub Main()
Dim CompName As New StringBuilder()
Dim Ret As Integer
'Ret = GetComputerNameAlt(CompName, 100)
Ret = GetCompName2(CompName, 100)
Dim CompNameBytes() As Byte = Encoding.Unicode.GetBytes(CompName.ToString)
Dim CompNameStr As String = Encoding.Default.GetString(CompNameBytes)
Console.WriteLine("Der Computer heißt: {0}", CompNameStr)
Console.ReadLine()
End Sub
The GetComputerName API
12/12/2010 4:15:59 AM - -68.150.190.236
The GetComputerName API
12/12/2010 4:15:59 AM - -68.150.190.236
The Netbios function interprets and executes the specified network control block (NCB). The Netbios function is provided primarily for applications that were written for the NetBIOS interface and need to be ported to Windows. Applications not requiring compatibility with NetBIOS should use other interfaces, such as mailslots, named pipes, RPC, or distributed COM to accomplish tasks similar to those supported by NetBIOS. These other interfaces are more flexible and portable.
4/8/2009 9:19:22 AM - -77.20.106.17
Click to read this page
4/6/2008 2:23:14 PM - hlidftvbgb-88.114.46.202
TODO - a short description
3/16/2007 1:31:57 PM - 66.194.55.242
The SetLastError API
4/11/2011 3:33:35 PM - -139.149.31.230
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 10:19:55 AM - josep1er@cmich.edu-141.209.229.179
Click to read this page
10/2/2011 9:35:57 AM - -87.165.40.65
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 10:19:55 AM - josep1er@cmich.edu-141.209.229.179
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).
Ignoring bugs won’t make them go away
Let users send you error reports in one click with SmartAssembly.