Solved

WMI query to get element as string

Posted on 2006-12-01
4
294 Views
Last Modified: 2008-02-01
Experts,

I am attempting to obtain the windows directory path from a computer and then put the path to string.... here is what I have;

        'Query the windows directory installation
        Dim myScope As New ManagementScope("\\" & Environment.MachineName & "\root\cimv2")
        Dim WindowsDirectory As String
        Dim oQuery As New SelectQuery("SELECT WindowsDirectory FROM Win32_OperatingSystem")
        Dim oResults As New ManagementObjectSearcher(myScope, oQuery)
        Dim oItem As ManagementObject
        Dim oProperty As PropertyData
        For Each oItem In oResults.Get()
            For Each oProperty In oItem.Properties
                Try
                    WindowsDirectory = (oProperty.Name.ToString, (oProperty.Value.ToString))
                Catch ex As Exception
                End Try
            Next
        Next

I am getting a syntax error on the WindowsDirectory line... please help
0
Comment
Question by:nickmarshall
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 9

Accepted Solution

by:
DjDezmond earned 125 total points
ID: 18052693
You could query the Environmental variable "SystemRoot" instead?

-----------------------------------------------------------------
WinPath = Environment.GetEnvironmentVariable("SystemRoot")
Msgbox WinPath
-----------------------------------------------------------------

I don't understand what your trying to do with this line in your code:
  WindowsDirectory = (oProperty.Name.ToString, (oProperty.Value.ToString))

That wouldn't return a string...

But this code will work nicely
0
 
LVL 6

Assisted Solution

by:manch
manch earned 125 total points
ID: 18052717


u Must Write only oProperty.Value.ToString

i.e.
WindowsDirectory = oProperty.Value.ToString()

Try It

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question