|
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
|
|
|
|
|
Hi
I have created a web project in ASP.NET , I want to process one more ASP.NET page which resides in some other virtual dirctory.
Using Server.Execute is not working and giving error
Please help.
Thanks in advance.
N.A.
|
|
|
|
|
Hi,
Why are there so many string conversions to integer? Do they honestly all have different uses? I mainly use Int32.Parse() . There is Convert.ToInt32() as well, and the SqlDataReader has a .GetInt32() method as well.
Why so many, are there maybe more that I don't know of??
Regards,
ma se
|
|
|
|
|
Yes there are more. You have Int32.TryParse, then the integer types Int16 and Int64 each have their own set of parsers and converters.
The reason that there are several similar methods is that they all work a little differently.
:: The TryParse methods returns a status value instead of throwing an exception.
:: The Convert methods also take other data types than strings.
:: The Convert methods that take a string parameter handles a null value as zero, otherwise calls the Parse method.
---
b { font-weight: normal; }
|
|
|
|
|
Interesting question, and not really one answer, as you have asked about things which look similar but in some cases are not!
Ill try to address some of your queries.
Int32.Parse - most non-string datatypes in .NET provide an easy way to convert to that datatype from a string - mainly for convenience as programmers often use string representations. DateTime.Parse, Int16.Parse immediately come to mind.
Convert - this is a convenient helper class that knows how to do many conversions to and from every base type. However, it is just a wrapper around the actual casting & converting which can be done. For example, decompile the Convert.ToInt32(string) method and you get:
public static int ToInt32(string value)
{
if (value == null)
{
return 0;
}
return int.Parse(value);
}
so, in essence Convert.ToInt32(String) is just using int32.Parse under the hood.
SqlDataReader.GetInt32 - This is a type-safety convenience. Rather than have to convert each read column to its a desired type, the data reader provides a type-safe way of reading each value. Without this convenience, you would have alot of this in your code
int myIntValue = (int)myDataReader["MyIntColumn"];
You should also read up on the difference between casting from one type to another, and parsing a string to a different type - that will help you understand a little more.
Hope that helps.
Current blacklist
svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
|
|
|
|
|
|
I want to remove cache form client system programmatically even if the browser cache setting is set to “Automatically”. I have tried following options but it doesn’t work.
1) <%@ OutputCache Location="None" VaryByParam="None" %>
2) Response.Cache.SetExpires(DateTime.Today);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Please help me to sort out this problem.
Thanks is advance.
Amit
|
|
|
|
|
You can't remove anything from the client cache, you can only prevent new pages from being stored in the cache.
Either the OutputCache or SetCacheability should do that. The SetExpires should work as long as the clock of the client computer is correct, but there might be problems for other time zones.
Clear your browser cache and test if any of the methods will keep the page from being cached.
---
b { font-weight: normal; }
|
|
|
|
|
I want to call web service and i want to show with database structure in Clint Window Application by Using jboss-server.My friend make javaside web service and i make client side window application by using C#.Pls help me how can we show XMl Data Grid in C#.
Yan
|
|
|
|
|
Sure you can use Xml as datasource..
Dataset ds=new Dataset();
ds.ReadXml("xmlpath");
Datagrid1.Datasource=ds;
|
|
|
|
|
Hey everyone,
I have an sql database with a table field which is a nvarchar. But the field actually contains a date and time of an event, for each record.
Im trying to count up all the events that occurred today. Here's my code:
for (int i = 0; i < table.Rows.Count; i++)<br />
{<br />
if (table.Rows[i][0] != null)<br />
{<br />
thedate = (DateTime)table.Rows[i][0];<br />
<br />
if ((DateTime)table.Rows[i][0] == DateTime.Now)<br />
count += 1;<br />
}<br />
}<br />
2 problems. Firstly, the line thedate = ...., fails everytime. It will not cast and reports an exception about failing to assign infinity. How else can I convert the string field to a date object?
Also, the field contains a date and time. I need to compare todays date with that field, excluding the actual time. Is that possible?
Any help gratefully appreciated
Andy
|
|
|
|
|
1. You need to use DateTime.Parse(..) or DateTime.ParseExact(..)
2. In order to compare with todays date, you need to use
dt.ToShortDateString() or datetime.Today() because DateTime.Now will give you date along with time.
Note: Format of both needs to be the same
|
|
|
|
|
Thanks very much Sathish and alexey.
Did the job perfect.
Kind regards
Andy
|
|
|
|
|
Try using function:
DateTime.TryParse
To count difference between dates in days use code:
<br />
DateTime date1 = new DateTime(2000, 10, 10);<br />
DateTime date2 = DateTime.Now;<br />
TimeSpan span = new TimeSpan(date1.Ticks - date2.Ticks);<br />
int daysCount = span.Days;<br />
Best regards, Alexey.
|
|
|
|
|
Hi,
How do I map two different columnstyles to the same column in data table.
I have a table 'XYZ'.It has columns column1,column2,column3.My datagrid's datasource property
is set to default view of 'XYZ'.I hav defined the following objects:-
DataGridTableStyle-- ts1
DataGridColumnStyle-- cs1
DataGridColumnStyle-- cs2
DataGridColumnStyle-- cs3
Using MappingName property of above objects I have mapped ts1 to 'XYZ',cs1 to column1,cs2 to column2,cs3 to column3.
This works but Exception is thrown when I have to bind cs3 to column2 (or) any other column that has been already mapped
to a columnstyle object
Thanks,
Sreeroop
Developer.
|
|
|
|
|
I am a bit puzzled on WHY you would want to bind cs3 to column2, when it is already bound to column 3, however....
The only way I know to do this, is to have multiple TableStyles, and depending on conditions in your program (?), delete the first TableStyle and apply the second.
HTH
WhiteWizard (aka Gandalf)
|
|
|
|
|
Firstly,I would like to map cs3 to column2 instead of column3(even if column2 has been bound to cs2 )and yes, I had mentioned cs3 is bound to column3.
I did try using a second DataGridTableStyle object ts2, then ts2.GridColumnStyles.Add(cs3);
this allows me to map to column2 as it belongs to a different tablestyle ts2,
but Excepton was thrown when i had to bind ts2 to default view of 'XYZ'using MappingName property of ts2 . Finally,ColumnStyle cs3 should be displayed on the grid .
-- modified at 3:18 Friday 5th May, 2006
|
|
|
|
|
I have application in Byte[] array, how to run application from Byte[]?
|
|
|
|
|
Try static method:
Assembly.Load(byte[] data)
Best regards, Alexey.
|
|
|
|
|
Imagine a matrix,
S M L XL<br />
color1 10 20 30 0<br />
color2 4 5 45 50<br />
color3 1 0 4 5
You a sample matrix what i work on. columns are quantity of sizes (some of them may equals to 0 ) . Rows are colors. rows count and columns count are variable. How to save them to data base.
rows are in a table, size are saved on other table. But i couldnt solve how to save values on table. what do you offer to me ?
|
|
|
|
|
Store the sizes in one table, the model in one table, and the quantities in one table.
Size (SizeId int, SizeName varchar)
1, 'S'
2, 'M'
3, 'L'
4, 'XL'
Model (ModelId int, ModelName varchar)
1, 'color1'
2, 'color2'
3, 'color3'
ModelQuantity (ModelId int, SizeId int, Quantity int)
1, 1, 10
1, 2, 20
1, 3, 30
1, 4, 0
2, 1, 4
2, 2, 5
2, 3, 45
2, 4, 50
3, 1, 1
3, 2, 0
3, 3, 4
3, 4, 5
Alternatively, you can choose to not store any record for the quantities that are zero.
---
b { font-weight: normal; }
|
|
|
|
|
i already did so , but i think it is not effective way.
When reports i show these values as a table (using listview object).
But it is hard to populate values in to a listview.
First i read just columns for creating column header
Then i try to read values at ModelQuantity for rows. Care that all color1 values must be at the same row. So after for datareader.read process , i create a listviewitem object.
|
|
|
|
|
It's the best way if you consider possible changes in the future. You can for an example add the size "XXL" without having to change the data model.
If you give up that flexibility, you could store all sizes for a model in a single record, with each quantity in a field. This would make it simpler to get the data, but if you need to add a size it requires changes in the database and in the code.
---
b { font-weight: normal; }
|
|
|
|
|
that is why i ask for (XXL or XS or any other numeric sizes. )
i search for any easier other way but i think there is no possibility
,thank you for reply
|
|
|
|
|
Hi,
I'm making a windows form that dynamicly puts checkboxes in different FlowLayoutPanels. My problem is that when i dont turn on the AutoSize of a checkbox the text of CheckBox is wrapped. But when i turn on the AutoSize the loading of the form takes to long (about 5 seconds). Does someone knows if there is another way to auto size the text of a checkbox?
this is my code that puts the checkboxes on my form.
i have a array that contains the a string array that looks like this:
options[0] = Checbox nr
options[1] = Checkbox text
options[2] = the group index ther are 4 different groups
for(int i=0;i
|
|
|
|
|