Hi there, i get an exception while using C# and wmi to retrieve some data. So here is the code is wrote: public class Adapter { public static ManagementObjectCollection GetNicAdapters() { try { WqlObjectQuery WQO = new WqlObjectQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionStatus != null"); ManagementObjectSearcher MOS = new ManagementObjectSearcher(WQO); ManagementObjectCollection MOC = MOS.Get(); return MOC; } catch (Exception ex) { MessageBox.Show("Data couldn't be retrieved."); return null; } }
I use this function to populate a field in my Form1 Base form. On the form (visually) there is a combo box, which now is filled with the Description of the Object. All of this works so far but now i am getting problems: private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (Adapters != null) { try { ManagementObject[] MOArray = new ManagementObject[Adapters.Count]; Adapters.CopyTo(MOArray, 0); int select = comboBox1.SelectedIndex; int selectedIndex = int.Parse(MOArray[select]["Index"].ToString()); int status = int.Parse(MOArray[select]["NetConnectionStatus"].ToString()); string myQueryString = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index = " + selectedIndex.ToString(); WqlObjectQuery ConfigQuery = new WqlObjectQuery(myQueryString); ManagementObjectSearcher ConfigSearcher = new ManagementObjectSearcher(ConfigQuery); ManagementObjectCollection ManagementObjectConfigurations = ConfigSearcher.Get(); ManagementObject[] CurrentArray = new ManagementObject[ManagementObjectConfigurations.Count]; ManagementObjectConfigurations.CopyTo(CurrentArray, 0); ManagementObject CurrentConfig = CurrentArray[0]; #region Draw Status IconConverter IC = new IconConverter(); switch (status) { case 0: l_status.Text = "Gerät nicht angeschlossen";
junus
Posts
-
Dynamically retrieving WMI Data - A little help please! -
WMI not working. Did I forget something?Hi folks, today I was trying to do some stuff with WMI. I was trying to solve a problem many people seem to have who drag their laptop from some place to another (eg from home to university). Maybe at home you have one configuration for your networking needs and university makes you use completely different network settings. So basically what i was trying to do is a little application that allows you to save several profiles with configurations (such as IP Addresses, Subnet etc) and assign them when needed. the actual problem appeared when i was trying to utilize WMI to assign an address to a certain network adapter. the code looks pretty much like in this article: http://www.codeproject.com/cs/system/cstcpipwmi.asp The second part of the article contains the assignment of an IPAddress to the adapter. For me this thing isn't working. I dont get any Exceptions, everything just works fine, but nothing happens. I do the InvokeMethod thing (Win32_NetworkAdapterConfiguration.EnableStatic) and that is just it. I dont get a result, the Address stays as it is. the wmi works fine for other stuff such as simply retrieving the adapters to see which ones can be used or are enabled or to see the MAC or whatever. Did anyone of you have problems with wmi? Is maybe even my attempt to solve my original problem wrong (should I even use WMI to do this?) Did i forget to do some security clearance within the framework or something? I use Visual Studio 2005 Professional Edition (VS Version 8.0.50727.42) on a Windows Professional. .NET 2.0 installed etc. Thanx in advance
-
hi !lol thanks, i'll keep it in mind :laugh:
-
hi !why are you guys so uptight? :laugh: like you got a better comment to someone using precious database space for a post saying HI! ;)
-
hi !hi, hope your urine stays yellow!
-
Setting up a portfolio websitehm, then maybe you should pay someone to do it for you. you wount get too far without doing things yourself. you can use the joomla! CMS. http://www.joomla.org/ you just need some webspace with php and a mysql db running, install it, get a nice template (there's s*** loads of them on the net) and youre done. that is maybe the easiest thing to do, because distributing content over this particular CMD is fast and easy. PLUS you get a lot of functionality like polls and commenting and news systems by two clicks. just try it http://demo.joomla.org/ the template is a bit crappy but as i said you'll find one that fits.
-
Setting up a portfolio websiteSetting up a portfolio website is pretty easy - still depending on your web skills such as html and css. Its also not bad to know photoshop or something comparable. also you have to make the decision between what serversided language to use. you will need on if you want to go a little further than just setting up one single page. i recommend PHP - i hope i wont get stoned by you all ô_Ô it's easy to learn and to set up. if you already know c# by heart i recommend you to use asp, of course. Now you might be asking for further help such as with the basic design, slicing and content management, you will find it all on www.pixel2life.com from photoshop tutorials to how to implement basic usability guidelines.