Click here to Skip to main content
15,897,315 members
Home / Discussions / C#
   

C#

 
AnswerRe: Kill a process Pin
V.4-May-06 3:28
professionalV.4-May-06 3:28 
GeneralRe: Kill a process Pin
krishna195-May-06 1:41
krishna195-May-06 1:41 
GeneralRe: Kill a process Pin
V.5-May-06 1:51
professionalV.5-May-06 1:51 
AnswerRe: Kill a process Pin
A.Gharighi4-May-06 8:28
A.Gharighi4-May-06 8:28 
GeneralRe: Kill a process Pin
krishna194-May-06 20:28
krishna194-May-06 20:28 
GeneralRe: Kill a process Pin
A.Gharighi6-May-06 3:00
A.Gharighi6-May-06 3:00 
GeneralRe: Kill a process Pin
krishna199-May-06 0:03
krishna199-May-06 0:03 
QuestionHow to change the DNS HostName using WMI Pin
Sharanray4-May-06 2:40
Sharanray4-May-06 2:40 
Hi,

Could anyone please let me know How to change the DNS HostName using WMI. I have
the snippet of the code below. The updation of the IPAddress and the SubNetMask
is happening correctly, but the updation of the HostName is not taking place.


using System;
using System.Management;
using System.Threading;
using Microsoft.Win32;

namespace WmiIpChanger {
class IpChanger {
[MTAThread]
static void Main(string[] args) {
SwitchToStatic();
}


static void SwitchToStatic() {
ManagementBaseObject inPar = null;
ManagementBaseObject objNewGate = null;
ManagementBaseObject outPar = null;
ManagementBaseObject hostPar = null;
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc) {
if (!(bool)mo["IPEnabled"])
continue;
try{

inPar = mo.GetMethodParameters("EnableStatic");
hostPar = mc.GetMethodParameters("EnableDNS");
objNewGate = mo.GetMethodParameters("SetGateways");

//Set IPAddress and Subnet Mask
inPar["IPAddress"] = new string[] { "192.168.1.141" };
inPar["SubnetMask"] = new string[] { "255.255.255.0" };

// Set the HostName
hostPar["DNSHostName"] = "user machine" ;
hostPar["DNSDomain"] = null;
hostPar["DNSServerSearchOrder"] = null;
hostPar["DNSDomainSuffixSearchOrder"] = null;


//Set DefaultGateway
objNewGate["DefaultIPGateway"] = new string[] { "192.168.1.100" };
objNewGate["GatewayCostMetric"] = new int[] { 1 };

outPar = mo.InvokeMethod("EnableStatic", inPar, null);
outPar = mo.InvokeMethod("SetGateways", objNewGate, null);
outPar = mc.InvokeMethod("EnableDNS", hostPar, new InvokeMethodOptions());
catch(Exception ex)
{
Console.WriteLine("Unable to Set IP : " + ex.Message);
}
}
}

}
}


Warm Regards
Sharan
QuestionHow to process web page that is on different we bserver Pin
rohan19814-May-06 2:36
rohan19814-May-06 2:36 
QuestionDifferent string conversions to integer Pin
Brendan Vogt4-May-06 2:28
Brendan Vogt4-May-06 2:28 
AnswerRe: Different string conversions to integer Pin
Guffa4-May-06 3:39
Guffa4-May-06 3:39 
AnswerRe: Different string conversions to integer Pin
J4amieC4-May-06 3:43
J4amieC4-May-06 3:43 
AnswerRe: Crystal report Pin
V.4-May-06 3:30
professionalV.4-May-06 3:30 
QuestionRemove cache programmatically Pin
AmitSumit4-May-06 1:45
AmitSumit4-May-06 1:45 
AnswerRe: Remove cache programmatically Pin
Guffa4-May-06 4:19
Guffa4-May-06 4:19 
QuestionXML Data Binding Pin
Kyawgyi4-May-06 1:17
Kyawgyi4-May-06 1:17 
AnswerRe: XML Data Binding Pin
sathish s4-May-06 1:24
sathish s4-May-06 1:24 
QuestionCasting string to Date Pin
Mark064-May-06 1:11
Mark064-May-06 1:11 
AnswerRe: Casting string to Date Pin
sathish s4-May-06 1:22
sathish s4-May-06 1:22 
GeneralRe: Casting string to Date Pin
Mark064-May-06 1:46
Mark064-May-06 1:46 
AnswerRe: Casting string to Date Pin
alexey N4-May-06 1:23
alexey N4-May-06 1:23 
QuestionDataGridColumnStyle in WinForms Pin
Sreeroop4-May-06 0:36
Sreeroop4-May-06 0:36 
AnswerRe: DataGridColumnStyle in WinForms Pin
MCSD-Gandalf4-May-06 2:26
MCSD-Gandalf4-May-06 2:26 
GeneralRe: DataGridColumnStyle in WinForms Pin
Sreeroop4-May-06 20:48
Sreeroop4-May-06 20:48 
QuestionHow to run application from Byte[] Pin
Dima Filipiuk4-May-06 0:27
Dima Filipiuk4-May-06 0:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.