Solved

How to change the Computer Name programatically?

Posted on 2009-07-11
6
1,274 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
  • 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
Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
How to record audio from input sources to your PC – connected devices, connected preamp to record vinyl discs, streaming media, that play through your audio card: Vista, Windows 7, Windows 8, Windows 8.1 and Windows 10 – both 32 bit & 64.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
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…

861 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