|
Hey thanks for the timely response!!
ah soz i forgot to paste that in!!(manscope.connect) sorry!
plz if u could try-> just request a whole lot of values from different tables.. and use threads (a lot).. and if u dont get an error maybe i can send u my program
2) Is there any windows setting(using XP) that can affect the WMI? I am unable to connect to some computers??
Thanks so much!
|
|
|
|
|
There are no settings that can affect WMI. I can't get the ManagementObjectSearcher class to work properly at all, either quering the local machine or a remote WMI namespace. The .Get() method works and returns, but the results are unreadable. I get a "COM object that has been separated from its underlying RCW can not be used." error in a Unhandled exception of type 'System.Management.ManagementException' occurred in system.windows.forms.dll when I try to get an enumerator for the returned object collection (ManagementObjectCollection.) But the entire WMI search code is wrapped in a Try/Catch block.
This error is getting back to the message pump unhandled for some reason. It looks like a bug in the .NET Framework, but I can't find any information on it. I also can't get a complete list of bug fixes in the upcomming Service Pack 1 for the .NET Framework 1.1 and SP3 for the .NET Framework 1.0. There are a LOT of bug fixes that don't have Knowledge Base articles for them yet...
Until the service pack comes out, I don't have a way around this problem.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Here's my code.. works for me..
Excuse the repertition, i just do this for complexities sake some RPC should occur if u use the threads...
using System;
using System.Threading;
using System.Management;
namespace SimpleTRY
{
public class Class1
{
private ManagementObjectSearcher m_MOSearcher;
private ManagementScope m_ManScope;
private ConnectionOptions m_ConnectOptions;
public Class1()
{
for (int i=0; i< 250; i++)
{
/*Thread a = new Thread(new ThreadStart(this.connect));
a.Start();*/
this.connect();
}
}
public void connect()
{
string ipAddress = "192.168.0.88";
m_ConnectOptions = new ConnectionOptions ();
m_ConnectOptions.Username = "Gorilla";
m_ConnectOptions.Password = "rock";
m_ConnectOptions.Authentication = AuthenticationLevel.Call;
m_ConnectOptions.Impersonation = ImpersonationLevel.Impersonate;
m_ConnectOptions.EnablePrivileges = true;
m_ConnectOptions.Locale = "MS_409";
m_ConnectOptions.Timeout = new TimeSpan (0,0,0,30);
string strConnection = "\\\\"+ ipAddress + "\\root\\cimv2";
m_ManScope = new ManagementScope(strConnection, m_ConnectOptions);
m_ManScope.Connect();
{
ObjectQuery Temp = new ObjectQuery("SELECT " + "Size" + " FROM Win32_" + "DiskDrive");
m_MOSearcher = new ManagementObjectSearcher (m_ManScope, Temp);
foreach(ManagementObject mo in m_MOSearcher.Get())
{
Console.WriteLine("Size: " +mo["Size"].ToString ());
}
Temp = new ObjectQuery("SELECT " + "Model" + " FROM Win32_" + "DiskDrive");
m_MOSearcher = new ManagementObjectSearcher (m_ManScope, Temp);
foreach(ManagementObject mo in m_MOSearcher.Get())
{
Console.WriteLine("Model: " +mo["Model"].ToString ());
}
Temp = new ObjectQuery("SELECT " + "SystemName" + " FROM Win32_" + "DiskDrive");
m_MOSearcher = new ManagementObjectSearcher (m_ManScope, Temp);
foreach(ManagementObject mo in m_MOSearcher.Get())
{
Console.WriteLine("SystemName: " +mo["SystemName"].ToString ());
}
Temp = new ObjectQuery("SELECT " + "AdapterRAM" + " FROM Win32_" + "VideoController");
m_MOSearcher = new ManagementObjectSearcher (m_ManScope, Temp);
foreach(ManagementObject mo in m_MOSearcher.Get())
{
Console.WriteLine("AdapterRAM: " +mo["AdapterRAM"].ToString ());
}
Temp = new ObjectQuery("SELECT " + "CurrentRefreshRate" + " FROM Win32_" + "VideoController");
m_MOSearcher = new ManagementObjectSearcher (m_ManScope, Temp);
foreach(ManagementObject mo in m_MOSearcher.Get())
{
Console.WriteLine("CurrentRefreshRate: " +mo["CurrentRefreshRate"].ToString ());
}
Temp = new ObjectQuery("SELECT " + "Name" + " FROM Win32_" + "VideoController");
m_MOSearcher = new ManagementObjectSearcher (m_ManScope, Temp);
foreach(ManagementObject mo in m_MOSearcher.Get())
{
Console.WriteLine("Name: " +mo["Name"].ToString ());
}
Console.WriteLine("--------------------------------------");
}
}
}
}
|
|
|
|
|
Now I get your problem. The issue is your swamping the target machine with requests. You have to pace your request by dropping in a Thread.Sleep() right after your Thread.Start(). What's happening is by launching 250 requests, at nearly the same time, the WMI service on the target machine can't keep up. Your pegging the target machines CPU Utilization at 100% the entire time your making these requests. In order to get it to work reliably, I had to pace the thread launches at every 150 milliseconds. This was by no means an extensive test, so for reliability, you'd probably have to increase that number to 250 milliseconds. THe only way to guarantee that it won't fail, is to launch them one at a time and wait for each request to complete before you launch the next one.
BTW: Why on earth would you want to do this? The only reason I can see is that your launching 250 requests at 250 seperate machines, not the same machine. This requirement would invalidate any testing your doing because you ar no longer stressing a single target machine.
A better way to do this would be to queue the work using the .NET Frameworks' built in ThreadPool.
public Class1()
{
for (int i=0; i< 250; i++)
{
Thread a = new Thread(new ThreadStart(this.connect));
a.Start();
Thread.Sleep(150);
}
}
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Why i am doing this incredibly daft task is to test the ManagementObjectSearcher Class.. because: i have another program that does retrieve info from many different comps.. the prob is while im scanning them, sometimes all of a sudden i get an RPC fail or COMException.. SO i want to make sure it's WMI setting or possibly a bug.
To Me, Something seems fishy with remotly retrieving the info.. Everything works fine locally. please try again with my code, using no threads (just "connect()") and see if u get the error? after it has gone thru the loop about 95 times the Exception pops up?
Thanks
|
|
|
|
|
Well, I ran the code like this:
public Class2()
{
for (int i=0; i< 25000; i++)
{
this.connect();
}
}
and didn't have a single problem...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Then I tried it like this:
public Class2()
{
for (int i=0; i< 2500; i++)
{
Thread a = new Thread(new ThreadStart(this.connect));
a.Start();
Thread.Sleep(500);
}
}
and couldn't get it to work reliably until I increased the Sleep delay to half a second. Took forever to run, but...
My suggestion still stands, queue up the work in the .NET Thread Pool.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
ja with the first 1: my problems are rare... most of the times it works.. but it's like the WMI on the remote computer gets clogged up from the previous attempts (when i ran the program before)
it's funny - i changed the password on the remote comp and now with threads i get an UnauthorizedAccessException sometimes..
NE Ways il let u know wat happens
|
|
|
|
|
hi - thread pool still gives me problems.. um i dont wanna worry about threads atm.. rather, plz could u just use the connect (no threads) and run the exe in the debug folder at the same time.. i would like to know if u also get and RPC error? if u dont get one at first, just keep running the program and exe thanks..
Another thing-do u know how to pass Credentials to be able to access the registry? Im using RegistryKey and OpenRemoteBaseKey...
thanks again
|
|
|
|
|
Okay. Now I’m making some progress. Thanks, beowulfagate, for suggesting the GetThumbnailImage method.
Can anybody tell me how to use the GetThumbnailImage method to fill a ListView?
Here is what I have:
lstPhotos.BeginUpdate()<br />
lstPhotos.Items.Clear()<br />
Dim strFiles() As String<br />
Dim x As Integer<br />
strFiles = Directory.GetFiles(formLibrary.componentPath)<br />
For x = 0 To strFiles.Length - 1<br />
Dim objListViewItem As New ListViewItem<br />
Dim imageThumb As Image<br />
With objListViewItem<br />
.Text = Path.GetFileName(strFiles(x))<br />
.SubItems.Add(Format(FileLen((strFiles(x))), "###,###,###,###"))<br />
.SubItems.Add(CStr(File.GetLastWriteTime(strFiles(x))))<br />
End With<br />
lstPhotos.Items.Add(objListViewItem)<br />
<br />
Next x<br />
lstPhotos.EndUpdate()
This lists the contents of the formLibrary.componentPath folder but I can't see how to use GetThumbnailImage to display the images as thumbnails in lstPhotos .
Thanks.
Brad
|
|
|
|
|
...I'm waayyy off aren't I?
The more I dig, the more I realize that I have no idea what I'm doing.
I wonder if I should try to use the StateImageList property?
Can anybody help?
Brad
|
|
|
|
|
try this:
<br />
dim imagethumb as image<br />
imagethumb.fromfile=path.getfilename(strFiles(x))<br />
dim index as integer=lstphotos.largeimagelist.images.add(imagethumb.getThumbNailImage)<br />
lstphotos.items.add(path.getfilename(strFiles(x),index)<br />
Note: the listview should be in the LargeIcons Style to use the LargeImageList. Use the SmallIcons to use the SmallImageList.
|
|
|
|
|
I can’t get imagethumb.fromfile to work. It says: Overload resolution failed because no accessible ‘FromFile’ accepts this number of arguments.
At first I thought that this might be because strFiles is and array but that didn’t seem to be causing the problem.
|
|
|
|
|
Uh Oh! Sorry. Try this.
<br />
Imagethumb.fromfile(path.getfilename(strFiles(x))<br />
|
|
|
|
|
That did the trick. Thanks!
Now the Index variable is giving me a fit.
Dim index As Integer = lstPhotos.LargeImageList.Images.Add(imagethumb.GetThumbnailImage )
Should index be declared as something other than an Integer since an image is being assigned to it? Is so, do you know what it would be?
Thanks
Brad
|
|
|
|
|
No, it is not an image being assigned to it. It is the index of the image we just added to the imagelist. We need this index to know what index goes with what item. The add method of the ImageCollection Class is declared as:
<br />
public sub overloads Add(icon)<br />
public sub overloads Add(Image) 'We are using this<br />
public function overloads Add(Image,Color) as integer 'When we should be using this<br />
Just add a color parameter to the Add method and it should work fine. Look it up in the MSDN Library.
|
|
|
|
|
Thanks.
I think I'm on track now.
Brad
|
|
|
|
|
Trying to find some basic programming help = adding icons to menus and changing the background color of menus. Have seen this done but can't find any examples.
Found one reference on this site "Adding Icons to Menus" by Willian.BR but apparantly it is a broken link.
Any suggestions or help appreciated!
billp@awalnet.net.sa
|
|
|
|
|
It can be done, but not within VB6 code. See the following articles and projects for helper .DLL's that will do what you want, especially the first one.
Yahoo Search Results[^]
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hi
i have tried to add a track bar control to my project, in vb.net, using the code provided by the msdn, however, it doesnt seem to work, it is not accepting the values nor is it saving them back to the xml file
any ideas?
|
|
|
|
|
if you are using the application.config.xml with the property, it wont write to the file. It will only read from the file when you load the application. You can manually change the XML file for it to change the value.
Hope it help.
anghp@yahoo.com
Feel free to email or yahoo messenger.
|
|
|
|
|
actually i am using the writeXml after each addition, and the problem is i want the user to make the changes.
this is not working with the add/delete buttons as well... as i can view the temporary changes however it is not changing the actual xml file
|
|
|
|
|
Okay, I was thinking about making a kind of media player in Visual Basic .NET that I could call my own...but the problem was I don't know how to insert a control that let a user control the sound! I would be able to in VB6 maybe, but .NET isn't the same. Could someone pleeeeeease help?
|
|
|
|
|
If you want to insert a control (activeX perhaps), right click at the toolbar, select add/remove items then select comp object.
Hope that is what you want.
anghp@yahoo.com
feel free to email or yahoo messenger.
|
|
|
|
|
This is the code, just paste it into a form with 1 command button.
Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim media As OpenFileDialog = New OpenFileDialog
media.RestoreDirectory = True
If media.ShowDialog = DialogResult.OK Then
Dim waveFile As String = media.FileName
Dim extension As String = System.IO.Path.GetExtension(waveFile)
If (extension.ToLower() = ".wav") Then
PlaySound(waveFile, 0, &H8)
End If
End If
End Sub
hope that help.
anghp@yahoo.com
Feel free to email or yahoo messenger.
|
|
|
|