Solved

visual basic script

Posted on 2014-10-30
8
421 Views
Last Modified: 2014-10-30
I am about as new to scripting as you can get, however, I am encouraged that I think I can follow pretty well what a script is trying to do. So I found the follow script which is supposed to get the version of IE it reads as follows.

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & _
    "\root\cimv2\Applications\MicrosoftIE")

Set colIESettings = objWMIService.ExecQuery _
    ("Select * from MicrosoftIE_Summary")

For Each strIESetting in colIESettings
    Wscript.Echo strIESetting.Version
Next

So I think what is happening is, the first line sets the variable strComputer, then objWMIService is set using the command GetObject from the path \\computername\root\cim2\Application\MicrosoftIE
Then colIESettings is set to everything gathered from MicroSoftIE_Summary
lastly each thing is displayed from StrIESetting.Version

If that is correct, I don't understand why when I run the script on my PC I get a Windows Script Host error at
line 2, Char 1 error 0x8004100E code 8004100E Source (null)
Any ideas what I am doing wrong?
0
Comment
Question by:JeffBeall
  • 3
  • 3
  • 2
8 Comments
 
LVL 28

Assisted Solution

by:omgang
omgang earned 250 total points
ID: 40413321
Apparently the namespace \root\cimv2\applications\microsoftie_summary was removed in Windows Vista and later.  That's why it's not working on your Windows 7 machine.
OM Gang
0
 
LVL 28

Expert Comment

by:omgang
ID: 40413333
See this PAQ for a sample of a script that you can use to get IE version.
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_26761987.html

OM Gang
0
 
LVL 33

Accepted Solution

by:
it_saige earned 250 total points
ID: 40413341
You are getting this error because Microsoft removed the MicrosoftIE namespace from the WMI namespaces starting with Windows Vista.

So instead we have to settle for querying the registry:
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Internet Explorer"
strValueName = "Version"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
Wscript.Echo "Installed IE Version: " & strValue & VBCRLF & "IE Version: " & Left(strValue,1)

Open in new window


-saige-
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 1

Author Comment

by:JeffBeall
ID: 40413657
a-ha, so that's want is going on! I have two more questions then, first, because this happened, I was wondering, is there a way to list what is in the WMI namespace?
and 2nd does strComputer= "." mean it is looking on the computer that the script is running on? if so, would I be able to have this run on a remote computer using something like
strComputer="remotecomputername"
also - just to be sure I'm on the right page, strComputer is just a variable, correct? I could use
bob="."
if I wanted to. Not that I would, just making sure I have this correct.
0
 
LVL 28

Expert Comment

by:omgang
ID: 40413713
Not sure about enumerating the WMI namespace.

Yes, strComputer="." means the local machine.

Yes, it's possible to run the script against another machine by changing the value assigned to strComputer.

Yes, strComputer is variable and could be replaced by almost anything.  By convention, many choose to preface variables with the intended data type, e.g. strComputer for a String data type variable, intCounter for an integer type variable, etc.  It helps when reading code.  In vbscript, however, all variables are actually Variant data types so it's possible for strComputer to get assigned a value of 297.

OM Gang
0
 
LVL 33

Expert Comment

by:it_saige
ID: 40413715
Yes you can list what is in the WMI namespace.
' List All WMI Namespaces

strComputer = "."
Call EnumNameSpaces("root")
 
Sub EnumNameSpaces(strNameSpace)
    WScript.Echo strNameSpace
    Set objWMIService=GetObject _
        ("winmgmts:{impersonationLevel=impersonate}\\" & _ 
            strComputer & "\" & strNameSpace)

    Set colNameSpaces = objWMIService.InstancesOf("__NAMESPACE")

    For Each objNameSpace In colNameSpaces
        Call EnumNameSpaces(strNameSpace & "\" & objNameSpace.Name)
    Next
End Sub

Open in new window


Yes, strComputer is a variable (you could use bob).
Yes, the value for strComputer, ".", refers to the local computer.  It's the same as using:
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2\Applications\MicrosoftIE")

Open in new window


For running on a remote computer you would have to use the remote computer name as you indicated.

-saige-
0
 
LVL 33

Expert Comment

by:it_saige
ID: 40413772
Ofcourse a better version of the above script does not use seperate echo's for each namespace:
' List All WMI Namespaces


strComputer = "."
strNamespaces = EnumNameSpaces("root")
wscript.echo strNamespaces
 
Function EnumNameSpaces(strNameSpace)
	EnumNameSpaces = EnumNameSpaces & strNamespace & VBCRLF
	Set objWMIService=GetObject _
		("winmgmts:{impersonationLevel=impersonate}\\" & _ 
		strComputer & "\" & strNameSpace)

	Set colNameSpaces = objWMIService.InstancesOf("__NAMESPACE")

	For Each objNameSpace In colNameSpaces
		EnumNameSpaces = EnumNameSpaces & EnumNameSpaces(strNameSpace & "\" & objNameSpace.Name)
	Next
End Function

Open in new window


-saige-
0
 
LVL 1

Author Closing Comment

by:JeffBeall
ID: 40414011
awsome, thanks for the namespace thing. you must really know scripting. some day i hope to be able to write my own scripts.
now I just have to try and have the script that shows the IE version output the versions of IE from a list of computers. but I think that's outside this question.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

By default the complete memory dump option is disabled in windows . If we want to enable the complete memory dump for a diagnostic purpose, we have a solution for it. here we are using the registry method to enable this.
While working, an annoying popup showing below will come and we cannot cancel or close it form the screen. The error message will come again and again.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
This Micro Tutorial will go in depth within Systems and Security in Windows 7 and will go into detail regarding Action Center, Windows Firewall, System, etc. This will be demonstrated using Windows 7 operating system.

776 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