Solved

How to change the Computer Name programatically?

Posted on 2009-07-11
6
1,298 Views
Last Modified: 2012-05-07
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
Comment
Question by:rnevet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 1

Accepted Solution

by:
MILLENION earned 300 total points
ID: 24832682
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
 
LVL 2

Author Comment

by:rnevet
ID: 24832735
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
 
LVL 92

Expert Comment

by:objects
ID: 24832772
you would need to use JNI or Runtime.exec() to do it from java.
0
Independent Software Vendors: 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!

 
LVL 2

Author Comment

by:rnevet
ID: 24832822
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
 
LVL 92

Assisted Solution

by:objects
objects earned 200 total points
ID: 24832859
> Well I guess that's a no for the directly from Java?

no there isn't sorry
0
 
LVL 2

Author Comment

by:rnevet
ID: 24832882
Thnx.
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question