Solved

WMI query to get element as string

Posted on 2006-12-01
4
288 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 125 total points
Comment Utility
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
Comment Utility


u Must Write only oProperty.Value.ToString

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

Try It

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now