Solved

WMI query to get element as string

Posted on 2006-12-01
4
293 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…

749 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