Solved

How to change the Computer Name programatically?

Posted on 2009-07-11
6
1,210 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Do email signature updates give you a headache?

Do you feel like you are constantly making changes to email signatures? Are the images not formatting how you want them to? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today.

Join & Write a Comment

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.
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…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
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 …

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now