Welcome! Log In Create A New Profile

Advanced

Some translation help please

Posted by Ben 
Ben
Some translation help please
May 11, 2008 11:56AM
Up to now i have used either .NET libraries, or VBS to run WMI queries. But I wonder how feasible it is within WinDev itself.

For example, how can i translate the following VBS to Windev. eg. What must objEvents be defined as within Windev?
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set objEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceCreationEvent WITHIN 60 WHERE TargetInstance ISA 'Win32_USBControllerDevice'")

Wscript.Echo "Waiting for events ..."
Do While(True)
Set objReceivedEvent = objEvents.NextEvent

'report an event
Wscript.Echo "New USB device event has occurred."

Loop

The C# equivalent im using is currently in the lines of :-
using System;
using System.Management;
using System.Windows.Forms;

namespace WMISample
{
public class WMIReceiveEvent
{
public static void Main()
{
try
{
WqlEventQuery query = new WqlEventQuery(
"SELECT * FROM __InstanceCreationEvent WITHIN 60 WHERE TargetInstance ISA 'Win32_USBControllerDevice'");

ManagementEventWatcher watcher = new ManagementEventWatcher(query);
Console.WriteLine("Waiting for an event...");

ManagementBaseObject eventObj = watcher.WaitForNextEvent();

Console.WriteLine("{0} event occurred.", eventObj["__CLASS"]);

// Cancel the event subscription
watcher.Stop();
return;
}
catch(ManagementException err)
{
MessageBox.Show("An error occurred while trying to receive an event: " + err.Message);
}
}
}

Bob
Re: Some translation help please
May 11, 2008 03:39PM
Hi Ben,

Not sure if I understand what you need entirely...

If it is any help I have a Windev WMI project that uses .net class (although from what you say, you may already have done this?)

Any WQL query works fine in it.

You can find it here [www.file-upload.net]

I don't know how to handle WMI event sinks or other events though..

Cheers

Bob
Bob
Re: Some translation help please
May 11, 2008 03:57PM
replied to wrong thread... :eek:


Sorry, URL was wrong. Try this [www.span-networks.co.uk]
Ben
Re: Some translation help please
May 11, 2008 05:03PM
Hi Bob,

Yes, i have my own set of .NET classes doing it. I was just wondering if some of it could be translated into Windev, so i only need to maintain one piece of code set.

Cheers
Ben
Re: Some translation help please
May 21, 2008 12:03AM
So I have to assume the above cannot be translated or make to work in Windev?
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: