Solved

How to change the Computer Name programatically?

Posted on 2009-07-11
6
1,316 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
Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

 
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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows 10 Locking 68 98
HP Elitebook 8560w strange behaviour 7 34
URL to download SMB1 update for Server 2012 R2 3 26
winscp backup and restore 2 24
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Suggested Courses

752 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