Hi,
I am trying to access Vista Event Logs say Applications and Services
Logs.
For example if I wanted to query DFS replication log (this log is not
present in XP and 2003) what would my query be.
Query to be initiated by box running Win2003 and .NET 2.0 (not 3.0)
Please advise whether I can query vista from box running .NEt 2.0 and
what should my WQL query look like.
Working code perfectly for 2003 and XP is below.
PS: Even if you don't know the answer feel free to point out a
resource or website that might be helpful
Regards,
beeess
bool res = true;
ManagementClass mc = null;
m_mngScope = null;
try
{
if (PropertyNames == null)//No specific properties given,
return all
of them
{
mc = new ManagementClass(wmiClass);
PropertyDataCollection props = mc.Properties;
PropertyNames = new string[props.Count];
int idx = 0;
foreach (PropertyData pd in props)
{
PropertyNames[idx++] = pd.Name;
}
}
string strQuery = "SELECT * from " + wmiClass;
if (queryCondition != null)
strQuery = strQuery + " Where " + queryCondition;
objQuery = new ObjectQuery(strQuery);
m_mngScope = new ManagementScope(@"\\" + connectOptions.IP + "\
\root\
\cimv2", connectOptions);
}
catch (Exception ex)
{
Trace.WriteLine("WMI exception at :" +
DateTime.Now.ToString());
IPrincipal threadPrincipal = Thread.CurrentPrincipal;
Trace.WriteLine(ex.StackTrace);
Trace.WriteLine("Identity Name:" +
threadPrincipal.Identity.Name);
Trace.WriteLine("Authentication: " +
threadPrincipal.Identity.AuthenticationType);
Trace.WriteLine("Authenticated: " +
threadPrincipal.Identity.IsAuthenticated.ToString());
}
if (mc != null) mc.Dispose();
return res;
...
...
...
ArrayList moCollect = new ArrayList();
if (!PrepareForQuery(null)) return moCollect;
ManagementObjectSearcher oSearcher = null;
try
{
oSearcher = new ManagementObjectSearcher(m_mngScope, objQuery);
if (m_Timeout > 0)//execute semisynchronously
{
AsyncSearcherGet asg = new AsyncSearcherGet(oSearcher,
m_Timeout);
bool success = asg.Execute(moCollect);
}
else
{
ManagementObjectCollection moCollection = null;
try
{
moCollection = oSearcher.Get();
foreach (ManagementObject mo in moCollection)
{
moCollect.Add(mo);
}
}
catch { }
if (moCollection != null) moCollection.Dispose();
}
}
catch { }
finally
{
if (oSearcher != null) oSearcher.Dispose();
}


