I am new to VB.Net and am converting a vbscript to a vb.net app so it can be run as a service. I need some help with with my function using wmi to backup an event log. I currently recieve an access denied error. I recieve the access denied error at the outParams line. I have tried evey different setting for the three connectionoptions with no luck. Any help would be greatful.
Dim
myconnectionoptions As New System.Management.ConnectionOptions
With myconnectionoptions
.Impersonation = Management.ImpersonationLevel.Impersonate
.Authentication = Management.AuthenticationLevel.Packet
.EnablePrivileges = True
End With
Dim myManagementScope As System.Management.ManagementScope
myManagementScope = New System.Management.ManagementScope("\\" & strComputer & "\root\cimv2", myconnectionoptions)
myManagementScope.Connect()
If myManagementScope.IsConnected = False Then
Console.WriteLine("Could not connect to WMI Namespace")
End If
Dim myobjectsearcher As System.Management.ManagementObjectSearcher
Dim mycollection As System.Management.ManagementObjectCollection
Dim myobject As System.Management.ManagementObject
myobjectsearcher = New System.Management.ManagementObjectSearcher(myManagementScope.Path.ToString, "Select * from win32_NTEventLogFile")
'* execute query
mycollection = myobjectsearcher.Get()
'* Get Event Log Files
For Each myobject In mycollection
Dim numsizeperc
Dim txtTotalSavePath
Dim counter
Dim txttiebreaker
numsizeperc = myobject.GetPropertyValue("FileSize") / myobject.GetPropertyValue("MaxFileSize")
If numsizeperc >= numPercOfMax Then 'compares percent of used logged size to cut of percent
txtTotalSavePath = txtlogsavepath & "_" & myobject.GetPropertyValue("LogFileName") & "_" & backupname
Console.WriteLine(txtTotalSavePath)
counter = 0
txttiebreaker = ""
Do While System.IO.File.Exists(txtTotalSavePath & txttiebreaker & ".evt")
counter = counter + 1
txttiebreaker = "-ver" & counter
Loop
txtTotalSavePath = txtTotalSavePath & txttiebreaker & ".evt"
Dim inParams As Management.ManagementBaseObject = myobject.GetMethodParameters("BackupEventLog")
inParams("ArchiveFileName") = txtTotalSavePath
Dim outParams As Management.ManagementBaseObject = myobject.InvokeMethod("BackupEventLog", inParams, Nothing)
End If
Next