473,805 Members | 2,059 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB.net WMI Win32_NtlogEven t problem, please help

First I wrote some _VBScript to get info from OS, and now I wrote some code
in VB.Net, and I have a problem now.

Look at this script in vbs

List1.vbs:

strComputer = "."

Set objWMIService = GetObject("winm gmts:\\" & strComputer & "\root\cimv 2")

strWQL="SELECT * FROM __InstanceCreat ionEvent WITHIN 5 WHERE
TargetInstance ISA ""Win32_NTLogEv ent"" "

Set objEventSource = objWMIService.E xecNotification Query(strWQL)

Do

Set objLatestEvent = colMonitoredEve nts.NextEvent

Wscript.Echo "OK"

Loop

I use it to register the Win32_ntlogEven t , so that i can get some info
where a new log written into the logfiles. List1 works very well on Windows
2003 Server, but when I try it on Windows 2000 Server, it echoed the
connection was refused .

So I edited it into List2,

strComputer = "."

Set objWMIService = GetObject("winm gmts:" & "{impersonation Level=
impersonate, (Security)}!\\" & strComputer & "\root\cimv 2")

Set colMonitoredEve nts = objWMIService.E xecNotification Query _

("Select * from __instancecreat ionevent WITHIN 5 where TargetInstance
isa 'Win32_NTLogEve nt' ")

Do

Set objLatestEvent = colMonitoredEve nts.NextEvent

Wscript.Echo "OK"

Loop

and list2 works well on Window2000. i noticed the security setting so when I
wrote the code(List3) in vb.net, I added

" watcher.Scope.O ptions.Imperson ation = ImpersonationLe vel.Impersonate

watcher.Scope.O ptions.Authenti cation = AuthenticationL evel.Default

" options in the vb.net code, but the bin still can not run on windows2000,
while it works well on Server2003.

i am puzzled! : ( ,

List3:
Imports System.manageme nt

Module Module1

Sub main()

Dim eventQuery As New EventQuery("SEL ECT * FROM
__InstanceCreat ionEvent WHERE TargetInstance ISA 'Win32_NTLogEve nt' ")

'Initialize an event watcher object with this query

Dim watcher As New ManagementEvent Watcher

watcher.Scope.P ath.Server = "."

watcher.Scope.P ath.Path = "\\.\root\CIMV2 "

watcher.Scope.P ath.NamespacePa th = "root\CIMV2 "

watcher.Scope.O ptions.Imperson ation = ImpersonationLe vel.Impersonate

watcher.Scope.O ptions.Authenti cation = AuthenticationL evel.Default

watcher.Scope.O ptions.EnablePr ivileges = False

watcher.Query = eventQuery

watcher.Start()

MsgBox("Listeni ng started!")

Dim handler As New EventHandler

AddHandler watcher.EventAr rived, AddressOf handler.HandleE vent

System.Threadin g.Thread.Sleep(-1)

End Sub

End Module

Public Class EventHandler

Public Sub HandleEvent(ByV al sender As Object, ByVal e As
EventArrivedEve ntArgs)

Console.Write(" OK")

End Sub

End Class

but after I changed the Query String to :

'Dim eventQuery As New EventQuery("SEL ECT * FROM __InstanceCreat ionEvent
WHERE TargetInstance ISA 'Win32_NTLogEve nt' and TargetInstance ='Application'
")

The bin could run well under windows2000 too, but if you change the
targetinstance to Security, you get the access denied message again.

So finally i have two questions:

Why can not i register to the Win32_NtlogEven t, bu t i can register to the
application part in Win32_ntlogeven t?

Is that a security problem?

Thank you for you time.

Jul 21 '05 #1
4 4242
Hello Jason,

I am not an expert on this but I have written some vb.net code to do
something similar. My understanding is the even if you run this with an
administravtive level account some security permissions are not enabled
unless you explicitly do so.

The line "watcher.Scope. Options.EnableP rivileges = True" allows me to do the
same type of thing.

I have bene running this code on Win XP SP1, Win XP SP2, Win2003, Win2000
Server under .Net 1.1 without any problems. I have upgraded a few test
machines for .Net 1.1 SP1 and I now have security related problems (access
denied on the watcher start command).

The access deinied is driven by trying to access the "security" logfile.
This may be the case for you. I have used the command

Dim q As New WqlEventQuery( _
"__InstanceCrea tionEvent", _
New TimeSpan(0, 0, 10), _
"TargetInst ance ISA ""Win32_NTLogEv ent"" " & _
"and (" & _
"TargetInstance .LogFile = ""Audit Success"" or " & _
"TargetInstance .LogFile = ""Audit Failure"" or " & _
"TargetInstance .LogFile = ""Applicati on"" or " & _
"TargetInstance .LogFile = ""System"" " & _
")")

which explicitly identifies the logfiles of interest (and does not require
EnabledPrivilag es to be set to true).

I hope this helps,
Mark

"Jason80" wrote:
First I wrote some _VBScript to get info from OS, and now I wrote some code
in VB.Net, and I have a problem now.

Look at this script in vbs

List1.vbs:

strComputer = "."

Set objWMIService = GetObject("winm gmts:\\" & strComputer & "\root\cimv 2")

strWQL="SELECT * FROM __InstanceCreat ionEvent WITHIN 5 WHERE
TargetInstance ISA ""Win32_NTLogEv ent"" "

Set objEventSource = objWMIService.E xecNotification Query(strWQL)

Do

Set objLatestEvent = colMonitoredEve nts.NextEvent

Wscript.Echo "OK"

Loop

I use it to register the Win32_ntlogEven t , so that i can get some info
where a new log written into the logfiles. List1 works very well on Windows
2003 Server, but when I try it on Windows 2000 Server, it echoed the
connection was refused .

So I edited it into List2,

strComputer = "."

Set objWMIService = GetObject("winm gmts:" & "{impersonation Level=
impersonate, (Security)}!\\" & strComputer & "\root\cimv 2")

Set colMonitoredEve nts = objWMIService.E xecNotification Query _

("Select * from __instancecreat ionevent WITHIN 5 where TargetInstance
isa 'Win32_NTLogEve nt' ")

Do

Set objLatestEvent = colMonitoredEve nts.NextEvent

Wscript.Echo "OK"

Loop

and list2 works well on Window2000. i noticed the security setting so when I
wrote the code(List3) in vb.net, I added

" watcher.Scope.O ptions.Imperson ation = ImpersonationLe vel.Impersonate

watcher.Scope.O ptions.Authenti cation = AuthenticationL evel.Default

" options in the vb.net code, but the bin still can not run on windows2000,
while it works well on Server2003.

i am puzzled! : ( ,

List3:
Imports System.manageme nt

Module Module1

Sub main()

Dim eventQuery As New EventQuery("SEL ECT * FROM
__InstanceCreat ionEvent WHERE TargetInstance ISA 'Win32_NTLogEve nt' ")

'Initialize an event watcher object with this query

Dim watcher As New ManagementEvent Watcher

watcher.Scope.P ath.Server = "."

watcher.Scope.P ath.Path = "\\.\root\CIMV2 "

watcher.Scope.P ath.NamespacePa th = "root\CIMV2 "

watcher.Scope.O ptions.Imperson ation = ImpersonationLe vel.Impersonate

watcher.Scope.O ptions.Authenti cation = AuthenticationL evel.Default

watcher.Scope.O ptions.EnablePr ivileges = False

watcher.Query = eventQuery

watcher.Start()

MsgBox("Listeni ng started!")

Dim handler As New EventHandler

AddHandler watcher.EventAr rived, AddressOf handler.HandleE vent

System.Threadin g.Thread.Sleep(-1)

End Sub

End Module

Public Class EventHandler

Public Sub HandleEvent(ByV al sender As Object, ByVal e As
EventArrivedEve ntArgs)

Console.Write(" OK")

End Sub

End Class

but after I changed the Query String to :

'Dim eventQuery As New EventQuery("SEL ECT * FROM __InstanceCreat ionEvent
WHERE TargetInstance ISA 'Win32_NTLogEve nt' and TargetInstance ='Application'
")

The bin could run well under windows2000 too, but if you change the
targetinstance to Security, you get the access denied message again.

So finally i have two questions:

Why can not i register to the Win32_NtlogEven t, bu t i can register to the
application part in Win32_ntlogeven t?

Is that a security problem?

Thank you for you time.

Jul 21 '05 #2
Thank you for your answer, and i have tried the
"watcher.Scope. Options.EnableP rivileges = True"
but i still can not access the whole "Win32_NtlogEve nt" class,
and i can access Application, System. So strange.

Thank you anyway, hope you can get your answer soon

"MarkD VIT@UK" wrote:
Hello Jason,

I am not an expert on this but I have written some vb.net code to do
something similar. My understanding is the even if you run this with an
administravtive level account some security permissions are not enabled
unless you explicitly do so.

The line "watcher.Scope. Options.EnableP rivileges = True" allows me to do the
same type of thing.

I have bene running this code on Win XP SP1, Win XP SP2, Win2003, Win2000
Server under .Net 1.1 without any problems. I have upgraded a few test
machines for .Net 1.1 SP1 and I now have security related problems (access
denied on the watcher start command).

The access deinied is driven by trying to access the "security" logfile.
This may be the case for you. I have used the command

Dim q As New WqlEventQuery( _
"__InstanceCrea tionEvent", _
New TimeSpan(0, 0, 10), _
"TargetInst ance ISA ""Win32_NTLogEv ent"" " & _
"and (" & _
"TargetInstance .LogFile = ""Audit Success"" or " & _
"TargetInstance .LogFile = ""Audit Failure"" or " & _
"TargetInstance .LogFile = ""Applicati on"" or " & _
"TargetInstance .LogFile = ""System"" " & _
")")

which explicitly identifies the logfiles of interest (and does not require
EnabledPrivilag es to be set to true).

I hope this helps,
Mark

Jul 21 '05 #3
Thank you for your answer, and i have tried the
"watcher.Scope. Options.EnableP rivileges = True"
but i still can not access the whole "Win32_NtlogEve nt" class,
and i can access Application, System. So strange.

Thank you anyway, hope you can get your answer soon

"MarkD VIT@UK" wrote:
Hello Jason,

I am not an expert on this but I have written some vb.net code to do
something similar. My understanding is the even if you run this with an
administravtive level account some security permissions are not enabled
unless you explicitly do so.

The line "watcher.Scope. Options.EnableP rivileges = True" allows me to do the
same type of thing.

I have bene running this code on Win XP SP1, Win XP SP2, Win2003, Win2000
Server under .Net 1.1 without any problems. I have upgraded a few test
machines for .Net 1.1 SP1 and I now have security related problems (access
denied on the watcher start command).

The access deinied is driven by trying to access the "security" logfile.
This may be the case for you. I have used the command

Dim q As New WqlEventQuery( _
"__InstanceCrea tionEvent", _
New TimeSpan(0, 0, 10), _
"TargetInst ance ISA ""Win32_NTLogEv ent"" " & _
"and (" & _
"TargetInstance .LogFile = ""Audit Success"" or " & _
"TargetInstance .LogFile = ""Audit Failure"" or " & _
"TargetInstance .LogFile = ""Applicati on"" or " & _
"TargetInstance .LogFile = ""System"" " & _
")")

which explicitly identifies the logfiles of interest (and does not require
EnabledPrivilag es to be set to true).

I hope this helps,
Mark

Jul 21 '05 #4
Hi Janson,

There was another discussion I had on this subject in the
microsoft.publi c.dotnet.framew ork group - the subject was

Subject: Problem with .NET 1.1 SP1 - Events

This may help give more details on the subject.

Thanks,
Mark

"Jason80" wrote:
Thank you for your answer, and i have tried the
"watcher.Scope. Options.EnableP rivileges = True"
but i still can not access the whole "Win32_NtlogEve nt" class,
and i can access Application, System. So strange.

Thank you anyway, hope you can get your answer soon

"MarkD VIT@UK" wrote:
Hello Jason,

I am not an expert on this but I have written some vb.net code to do
something similar. My understanding is the even if you run this with an
administravtive level account some security permissions are not enabled
unless you explicitly do so.

The line "watcher.Scope. Options.EnableP rivileges = True" allows me to do the
same type of thing.

I have bene running this code on Win XP SP1, Win XP SP2, Win2003, Win2000
Server under .Net 1.1 without any problems. I have upgraded a few test
machines for .Net 1.1 SP1 and I now have security related problems (access
denied on the watcher start command).

The access deinied is driven by trying to access the "security" logfile.
This may be the case for you. I have used the command

Dim q As New WqlEventQuery( _
"__InstanceCrea tionEvent", _
New TimeSpan(0, 0, 10), _
"TargetInst ance ISA ""Win32_NTLogEv ent"" " & _
"and (" & _
"TargetInstance .LogFile = ""Audit Success"" or " & _
"TargetInstance .LogFile = ""Audit Failure"" or " & _
"TargetInstance .LogFile = ""Applicati on"" or " & _
"TargetInstance .LogFile = ""System"" " & _
")")

which explicitly identifies the logfiles of interest (and does not require
EnabledPrivilag es to be set to true).

I hope this helps,
Mark

Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5651
by: newbie_mw | last post by:
Hi, I need urgent help with a novice problem. I would appreciate any advice, suggestions... Thanks a lot in advance! Here it is: I created a sign-up sheet (reg.html) where people fill in their first name, last name, email, etc. The data are then sent to a PHP script (reg.php). The data are then inserted into a table (reg) in MS SQL server. I have declared the variables like this: if (!(isset($_POST))) { $FirstName = "" ;
11
3767
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class (ClassB* b; b->func(); ) the base-class function is called instead of the new function in the derived class. All other similar functions (virtual in the base class and overwritten in the the derived class) work fine, it's just this one function. ...
3
3858
by: Spacy | last post by:
Am creating a HTML Report in asp.net. To save this report to excel on client-side, i write this code: Response.ContentType = "application/vnd.ms-excel" Response.AddHeader("content-disposition", "attachment; filename=Report.xls") But once the report is saved in excel, on click of hyperlink for second html report, i dont get the second report. the same old first html report is displayed. Please can anyone help me. Am frustrated with...
0
1705
by: Kurt Watson | last post by:
Im having a different kind of problem with Hotmail when I sign in it says, "Web Browser Software Limitations Your Current Software Will Limit Your Ability to Use Hotmail You are using a web browser that Hotmail does not support. If you continue to use your current browser software we cannot guarantee that Hotmail will work correctly for you". Please help, this is very annoying. I have been searching for help on
28
5228
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass(); .... and then call the virtual method, why is it that the base class's method is called instead of the overridden method? How do I fix this if I don't know at runtime what the child class is? I'm using Activator.CreateInstance() to load the...
9
2827
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am facing. Please please help me to solve this as soon as possible. So here we go ... I am not able to take the screen shot of the windows form based "Smart
11
1391
by: ASP newbie | last post by:
I cannot run my asp.net application in w2k server. But the program works fine under w2k professional. Can anyone tell me is there any difference in the settings? Many thanks.
4
1597
by: Jason80 | last post by:
First I wrote some _VBScript to get info from OS, and now I wrote some code in VB.Net, and I have a problem now. Look at this script in vbs List1.vbs: strComputer = "."
2
1623
by: cty0000 | last post by:
Please anybody help me... I have some serious problem.. I'm doing to keep equpiment list(string).. In my code, there are 3 page which are having 4 equpiment ID (user control.) like this window FORM ==================================================================
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10614
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.