Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1467
  • Last Modified:

How to change the Computer Name programatically?

Hi,

I was wondering if it is possible to change the computer name.

I would prefer to do it with J2se, but if there is a solution in C++.. I can make it work.

I mean the computer name that is visible on the local network or trough bluetooth.

Thanks.
0
rnevet
Asked:
rnevet
  • 3
  • 2
2 Solutions
 
MILLENIONCommented:
Here's the full info to "Sets the NetBIOS and the Computer Name (the first label of the full DNS name)
Here's the full info to "Sets the NetBIOS and the Computer Name (the first label of the full DNS name) [MSDN]" within a C# program:
 
//P/Invoke signature
[DllImport( "Kernel32.dll", SetLastError=true, CharSet=CharSet.Auto )]
[ return: MarshalAs( UnmanagedType.Bool ) ]
private static extern bool SetComputerNameEx(COMPUTER_NAME_FORMAT nameType,[MarshalAs( UnmanagedType.LPTStr )] string lpBuffer);
private enum COMPUTER_NAME_FORMAT : int
{
ComputerNameNetBIOS, 
ComputerNameDnsHostname, 
ComputerNameDnsDomain, 
ComputerNameDnsFullyQualified, 
ComputerNamePhysicalNetBIOS, 
ComputerNamePhysicalDnsHostname, 
ComputerNamePhysicalDnsDomain, 
ComputerNamePhysicalDnsFullyQualified, 
ComputerNameMax
}
 
// Call SetComputerEx
string NewHostname = "my machine";
returnFlag = SetComputerNameEx(COMPUTER_NAME_FORMAT.ComputerNamePhysicalDnsHostname, NewHostname);

Open in new window

0
 
rnevetAuthor Commented:
Well this is a good tip, BTW that's for c# but it was easy enough to find the C++ solution from there.

Anyway to do it directly from Java ?
0
 
objectsCommented:
you would need to use JNI or Runtime.exec() to do it from java.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rnevetAuthor Commented:
Well I guess that's a no for the directly from Java?
JNI or Runtime.exec() will be the way to go if not.

BTW already tested SetComputerNameEx using C++ and it requires a computer restart to go into effect. anyway to make a shortcut on this restart ?
0
 
objectsCommented:
> Well I guess that's a no for the directly from Java?

no there isn't sorry
0
 
rnevetAuthor Commented:
Thnx.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now