Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

WMI query to get element as string

Posted on 2006-12-01
4
Medium Priority
?
298 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
4 Comments
 
LVL 9

Accepted Solution

by:
DjDezmond earned 500 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 500 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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

971 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