473,396 Members | 2,013 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,396 software developers and data experts.

Setting ComputerName

Is there a method I can use in C# that will set the ComputerName? Any
Help would be appreciated.

Thanks
Todd
Nov 15 '05 #1
2 6566
This is what I am trying to use:

enum COMPUTER_NAME_FORMAT

{

ComputerNameNetBIOS,

ComputerNameDnsHostname,

ComputerNameDnsDomain,

ComputerNameDnsFullyQualified,

ComputerNamePhysicalNetBIOS,

ComputerNamePhysicalDnsHostname,

ComputerNamePhysicalDnsDomain,

ComputerNamePhysicalDnsFullyQualified,

ComputerNameMax

}

static extern bool SetComputerNameEx( [In] COMPUTER_NAME_FORMAT NameType,

string lpBuffer );

Now this is the part I am not sure of, setting the computer name on a button
click using the value of textbox1.text:

private void button1_Click(object sender, System.EventArgs e)

{

myCName = textBox1.Text;

ComputerName.Form1.SetComputerNameEx(ComputerNameN etBIOS, myCName);

}

Am I even close on this?

Todd

"Todd" <jj****@yahoo.com> wrote in message
news:f8**************************@posting.google.c om...
Is there a method I can use in C# that will set the ComputerName? Any
Help would be appreciated.

Thanks
Todd

Nov 15 '05 #2
Use the Management namespace classes (WMI wrappers) for all this kind of administrative tasks.
Following is a sample (not tested) that renames a local machine when run in the context of an administrator.

using System;
using System.Management;
// Rename a computer account using WMI
public class Wmis {

public static void Main() {

using (ManagementObject dir= new ManagementObject("Win32_ComputerSystem"))
{

ManagementBaseObject inputArgs = dir.GetMethodParameters("CopyEx");
inputArgs["Name"] = "NewComputerName";
// Other input args are UserName and Password.
// If not specified the current user security context is used to execute the command.
// See WMI sdk docs or MSDN for details.

ManagementBaseObject outParams = dir.InvokeMethod("Rename", inputArgs, null);
uint ret = (uint)(outParams.Properties["ReturnValue"].Value);
if(ret == 0)
Console.WriteLine("Success");
else Console.WriteLine("Failed with error code: {0}", ret);
}

}
}

Willy.

"Todd" <jj****@yahoo.com> wrote in message news:f8**************************@posting.google.c om...
Is there a method I can use in C# that will set the ComputerName? Any
Help would be appreciated.

Thanks
Todd

Nov 15 '05 #3

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

Similar topics

9
by: vishal | last post by:
i have created one page in asp login.php on my pc it is working as http://localhost/index.php but when i access this page from other computer in network it is not working pls help me ...
2
by: Ryd | last post by:
I'm looking for at asp script that grap the clients computername when they access a local http site. The client and server is in a local domaine.
2
by: dthmtlgod | last post by:
I am attempting to retrieve the computer name of a remote user accessing our websever. I have tried the following and both don't work. Any ideas? Returns the webserver computer name Set...
7
by: Mindy Geac | last post by:
Hello, i'm new with ASP! How can I display the hosting computername on the website, We have 2 servers and I want to know which server I'm getting the asp pages from. thnx, Mindy
1
by: Jason Shohet | last post by:
i'm using C#, would like to get the computerName of the machine on a windows2000 network. TY Jason Shohet
2
by: Joseph | last post by:
Has anyone had any experience gathering the local computername through a web application with no client side program. I've been researching different avenues and have been coming up blank so far. ...
0
by: amjad | last post by:
Dear All, I am using Visual Studio beta 2005 beta 2 with ASP.Net 2.0 and C#.I run the application and it work correctly with http://localhost:port/projectname/page but not with...
4
by: Mike Behrendt | last post by:
Hey @all! option explicit on Private Declare Function GetComputerName Lib "kernel32" Alias _ "GetComputerNameA" (ByVal lpBuffer As String) As Long Private Const MAX_COMPUTERNAME_LENGTH...
1
by: usman211 | last post by:
i m using the following code for IP and ComputerName, it run accurately with our LAN but when i run it from some remote/hosting servers(like godaddy where the site is hosted) it get the IP of my...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.