Solved

WMI query to get element as string

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

624 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