Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.00 KB | None | 0 0
  1.  
  2.     Private Enum COMPUTER_NAME_FORMAT As Integer
  3.         ComputerNameNetBIOS = 0
  4.         ComputerNameDnsHostname = 1
  5.         ComputerNameDnsDomain = 2
  6.         ComputerNameDnsFullyQualified = 3
  7.         ComputerNamePhysicalNetBIOS = 4
  8.         ComputerNamePhysicalDnsHostname = 5
  9.         ComputerNamePhysicalDnsDomain = 6
  10.         ComputerNamePhysicalDnsFullyQualified = 7
  11.     End Enum
  12.  
  13.     Public Const MAX_COMPUTERNAME_LENGTH As Int32 = 31
  14.  
  15.     <DllImport("kernel32.dll", CharSet:=CharSet.Ansi, SetLastError:=True)> _
  16.     Private Shared Function SetComputerNameEx( _
  17.         ByVal NameType As COMPUTER_NAME_FORMAT, _
  18.         <MarshalAs(UnmanagedType.LPStr)> ByVal lpBuffer As String) As Integer
  19.     End Function
  20.  
  21.     Public Function SetNewName(ByVal Computername As String) As Boolean
  22.         If NetworkSet.SetComputerNameEx(COMPUTER_NAME_FORMAT.ComputerNamePhysicalDnsHostname, _
  23.             Computername & Convert.ToChar(0)) = 0 Then
  24.             Throw New Win32Exception
  25.         End If
  26.     End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement