473,398 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

VB.net WMI Win32_NtlogEvent 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("winmgmts:\\" & strComputer & "\root\cimv2")

strWQL="SELECT * FROM __InstanceCreationEvent WITHIN 5 WHERE
TargetInstance ISA ""Win32_NTLogEvent"" "

Set objEventSource = objWMIService.ExecNotificationQuery(strWQL)

Do

Set objLatestEvent = colMonitoredEvents.NextEvent

Wscript.Echo "OK"

Loop

I use it to register the Win32_ntlogEvent , 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("winmgmts:" & "{impersonationLevel=
impersonate, (Security)}!\\" & strComputer & "\root\cimv2")

Set colMonitoredEvents = objWMIService.ExecNotificationQuery _

("Select * from __instancecreationevent WITHIN 5 where TargetInstance
isa 'Win32_NTLogEvent' ")

Do

Set objLatestEvent = colMonitoredEvents.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.Options.Impersonation = ImpersonationLevel.Impersonate

watcher.Scope.Options.Authentication = AuthenticationLevel.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.management

Module Module1

Sub main()

Dim eventQuery As New EventQuery("SELECT * FROM
__InstanceCreationEvent WHERE TargetInstance ISA 'Win32_NTLogEvent' ")

'Initialize an event watcher object with this query

Dim watcher As New ManagementEventWatcher

watcher.Scope.Path.Server = "."

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

watcher.Scope.Path.NamespacePath = "root\CIMV2"

watcher.Scope.Options.Impersonation = ImpersonationLevel.Impersonate

watcher.Scope.Options.Authentication = AuthenticationLevel.Default

watcher.Scope.Options.EnablePrivileges = False

watcher.Query = eventQuery

watcher.Start()

MsgBox("Listening started!")

Dim handler As New EventHandler

AddHandler watcher.EventArrived, AddressOf handler.HandleEvent

System.Threading.Thread.Sleep(-1)

End Sub

End Module

Public Class EventHandler

Public Sub HandleEvent(ByVal sender As Object, ByVal e As
EventArrivedEventArgs)

Console.Write("OK")

End Sub

End Class

but after I changed the Query String to :

'Dim eventQuery As New EventQuery("SELECT * FROM __InstanceCreationEvent
WHERE TargetInstance ISA 'Win32_NTLogEvent' 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_NtlogEvent, bu t i can register to the
application part in Win32_ntlogevent?

Is that a security problem?

Thank you for you time.

Jul 21 '05 #1
4 4200
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.EnablePrivileges = 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( _
"__InstanceCreationEvent", _
New TimeSpan(0, 0, 10), _
"TargetInstance ISA ""Win32_NTLogEvent"" " & _
"and (" & _
"TargetInstance.LogFile = ""Audit Success"" or " & _
"TargetInstance.LogFile = ""Audit Failure"" or " & _
"TargetInstance.LogFile = ""Application"" or " & _
"TargetInstance.LogFile = ""System"" " & _
")")

which explicitly identifies the logfiles of interest (and does not require
EnabledPrivilages 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("winmgmts:\\" & strComputer & "\root\cimv2")

strWQL="SELECT * FROM __InstanceCreationEvent WITHIN 5 WHERE
TargetInstance ISA ""Win32_NTLogEvent"" "

Set objEventSource = objWMIService.ExecNotificationQuery(strWQL)

Do

Set objLatestEvent = colMonitoredEvents.NextEvent

Wscript.Echo "OK"

Loop

I use it to register the Win32_ntlogEvent , 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("winmgmts:" & "{impersonationLevel=
impersonate, (Security)}!\\" & strComputer & "\root\cimv2")

Set colMonitoredEvents = objWMIService.ExecNotificationQuery _

("Select * from __instancecreationevent WITHIN 5 where TargetInstance
isa 'Win32_NTLogEvent' ")

Do

Set objLatestEvent = colMonitoredEvents.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.Options.Impersonation = ImpersonationLevel.Impersonate

watcher.Scope.Options.Authentication = AuthenticationLevel.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.management

Module Module1

Sub main()

Dim eventQuery As New EventQuery("SELECT * FROM
__InstanceCreationEvent WHERE TargetInstance ISA 'Win32_NTLogEvent' ")

'Initialize an event watcher object with this query

Dim watcher As New ManagementEventWatcher

watcher.Scope.Path.Server = "."

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

watcher.Scope.Path.NamespacePath = "root\CIMV2"

watcher.Scope.Options.Impersonation = ImpersonationLevel.Impersonate

watcher.Scope.Options.Authentication = AuthenticationLevel.Default

watcher.Scope.Options.EnablePrivileges = False

watcher.Query = eventQuery

watcher.Start()

MsgBox("Listening started!")

Dim handler As New EventHandler

AddHandler watcher.EventArrived, AddressOf handler.HandleEvent

System.Threading.Thread.Sleep(-1)

End Sub

End Module

Public Class EventHandler

Public Sub HandleEvent(ByVal sender As Object, ByVal e As
EventArrivedEventArgs)

Console.Write("OK")

End Sub

End Class

but after I changed the Query String to :

'Dim eventQuery As New EventQuery("SELECT * FROM __InstanceCreationEvent
WHERE TargetInstance ISA 'Win32_NTLogEvent' 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_NtlogEvent, bu t i can register to the
application part in Win32_ntlogevent?

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.EnablePrivileges = True"
but i still can not access the whole "Win32_NtlogEvent" 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.EnablePrivileges = 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( _
"__InstanceCreationEvent", _
New TimeSpan(0, 0, 10), _
"TargetInstance ISA ""Win32_NTLogEvent"" " & _
"and (" & _
"TargetInstance.LogFile = ""Audit Success"" or " & _
"TargetInstance.LogFile = ""Audit Failure"" or " & _
"TargetInstance.LogFile = ""Application"" or " & _
"TargetInstance.LogFile = ""System"" " & _
")")

which explicitly identifies the logfiles of interest (and does not require
EnabledPrivilages 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.EnablePrivileges = True"
but i still can not access the whole "Win32_NtlogEvent" 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.EnablePrivileges = 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( _
"__InstanceCreationEvent", _
New TimeSpan(0, 0, 10), _
"TargetInstance ISA ""Win32_NTLogEvent"" " & _
"and (" & _
"TargetInstance.LogFile = ""Audit Success"" or " & _
"TargetInstance.LogFile = ""Audit Failure"" or " & _
"TargetInstance.LogFile = ""Application"" or " & _
"TargetInstance.LogFile = ""System"" " & _
")")

which explicitly identifies the logfiles of interest (and does not require
EnabledPrivilages 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.public.dotnet.framework 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.EnablePrivileges = True"
but i still can not access the whole "Win32_NtlogEvent" 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.EnablePrivileges = 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( _
"__InstanceCreationEvent", _
New TimeSpan(0, 0, 10), _
"TargetInstance ISA ""Win32_NTLogEvent"" " & _
"and (" & _
"TargetInstance.LogFile = ""Audit Success"" or " & _
"TargetInstance.LogFile = ""Audit Failure"" or " & _
"TargetInstance.LogFile = ""Application"" or " & _
"TargetInstance.LogFile = ""System"" " & _
")")

which explicitly identifies the logfiles of interest (and does not require
EnabledPrivilages 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
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...
11
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...
3
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",...
0
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...
28
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();...
9
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...
11
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
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
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.