473,395 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Rename my Computer

HI,

I need to install a service that changes Host Name, computer name, on all
our machines.
I have tried to ways:
First one:
static void RenameHostName()
{
ManagementClass mComputerSystem = new ManagementClass
("Win32_ComputerSystem");
ManagementBaseObject objNewComputerName =

CoomputerSystem.GetMethodParameters("Rename");
Console.WriteLine(objNewComputerName["Name"]);
objNewComputerName["Name"] = "NewHostName";
Console.WriteLine(objNewComputerName["Name"]);
mComputerSystem.InvokeMethod("Rename",objNewComput erName,null);
}

Second way
static void RenameHostName2()
{
using(ManagementObject cs = new
ManagementObject(@"Win32_Computersystem.Name='myHo stName'"))

{

cs.Get();

ManagementBaseObject inParams = cs.GetMethodParameters("Rename");

inParams["Name"] = "NewHostName";

ManagementBaseObject outParams = cs.InvokeMethod("Rename", inParams,
null);

// Check return value ...

uint ret = (uint)outParams.Properties["ReturnValue"].Value;

}
}

None of these has worked, my hostName is still the same..... Do I have to
restart my computer after changing hostName or will the the system change
without restarting my computer???

is there any other way to change host name??? All new Ideas are very
appreciated.
--
LZ
May 7 '06 #1
1 9296
I know that if you change the computer name manually, you have to
restart the computer.

Lamis wrote:
HI,

I need to install a service that changes Host Name, computer name, on all
our machines.
I have tried to ways:
First one:
static void RenameHostName()
{
ManagementClass mComputerSystem = new ManagementClass
("Win32_ComputerSystem");
ManagementBaseObject objNewComputerName =

CoomputerSystem.GetMethodParameters("Rename");
Console.WriteLine(objNewComputerName["Name"]);
objNewComputerName["Name"] = "NewHostName";
Console.WriteLine(objNewComputerName["Name"]);
mComputerSystem.InvokeMethod("Rename",objNewComput erName,null);
}

Second way
static void RenameHostName2()
{
using(ManagementObject cs = new
ManagementObject(@"Win32_Computersystem.Name='myHo stName'"))

{

cs.Get();

ManagementBaseObject inParams = cs.GetMethodParameters("Rename");

inParams["Name"] = "NewHostName";

ManagementBaseObject outParams = cs.InvokeMethod("Rename", inParams,
null);

// Check return value ...

uint ret = (uint)outParams.Properties["ReturnValue"].Value;

}
}

None of these has worked, my hostName is still the same..... Do I have to
restart my computer after changing hostName or will the the system change
without restarting my computer???

is there any other way to change host name??? All new Ideas are very
appreciated.

May 7 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: RudyL | last post by:
OK, I'm stumped. I'm trying to rename all the files displayed inside of a filelist box. VB help just doesn't help - I'm using VB6 Thanks
0
by: Querton Pierre-Benoit | last post by:
Hello, I develop a class to control IIS throw ADSI. But is seems that some method doesn't work with IIS. To be more clear ;) When I do the following code : DirectoryEntry w3svc = new...
4
by: Lloyd Sheen | last post by:
Seems to me there should be a simple method available in the framework to rename a file, but I cannot find such a thing. This has to be something that is done all the time so I am assuming I just...
5
by: Tony Meyer | last post by:
On Windows, if I do os.rename(old, new) where old is a file that is in-use (e.g. python itself, or a dll that is loaded), I would expect that an error would be raised (e.g. as when os.remove is...
3
by: Yannick Benoit | last post by:
Hi guys. I have like hundreds of pictures in a folder and then I use this function to rename them all to a following number. but very often I noticed that some pictures get lost and I dont know...
2
by: AA Arens | last post by:
During my database construction, I left the names of the buttons, comboboxes named by default like Combo77, Command43. I can rename them with Properties Other Name, but them I start getting...
3
by: rn5a | last post by:
An inquisitive question...... A ListBox lists all the directories & files residing in a directory on the server. Assume that the ListBox lists 2 directories & 4 files. Also assume that one of...
3
by: Luciano | last post by:
I have been programing in PHP recently. For this reason, I have lots of basic doubts. Let's see one of then. I'm developing in the localhost, so safety issues are not important. I have a script...
1
by: teo | last post by:
hallo I'm with vb net fx 2.0 vs2005 I'have difficulties to find some functions that allow me to delete and rename files and folders via FTP I'm good with My.Computer.Network.UploadFile
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.