Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

SetComputerName (kernel32)
 
.
Summary

C# Signature:

[DllImport("kernel32.dll")]
static extern bool SetComputerName(string lpComputerName);

User-Defined Types:

None.

VB.NET Signature:

<DllImport("kernel32.dll")> _
Private Function SetComputerName(ByVal lpComputerName As String) As Boolean
End Function

User-Defined Types:

None.

Notes:

You need to restart your computer for the new computer name to take effect.

Tips & Tricks:

Please add some!

C# Sample Code:

using System.Runtime.InteropServices;

    class Program
    {
    [DllImport("kernel32.dll")]
    static extern bool SetComputerName(string lpComputerName);

    static void Main(string[] args)
    {
        bool done = SetComputerName("New Comp Name");

        if (done)
        {
        Console.WriteLine("Done");
        }

        Console.ReadKey();
    }
    }

VB.NET Sample Code:

Imports System.Runtime.InteropServices

Class Program

    <DllImport("kernel32.dll")> _
    Private Function SetComputerName(ByVal lpComputerName As String) As Boolean
    End Function

    Private Shared Sub Main(args As String())

        Dim done As Boolean = SetComputerName("New Comp Name")

        If done Then
        Console.WriteLine("Done")
        End If

        Console.ReadKey()

    End Sub

End Class

Alternative Managed API:

Do you know one? Please contribute it!

Documentation

http://msdn2.microsoft.com/en-us/library/ms724930.aspx

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).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions