3

I'm an amateur VB scripter. I'm making a script to check to see if one of two files exists, and if so, give a flag that says "Installed". If neither file exists, flag "Not Installed". Here is my script...

Option Explicit
DIM fso    
Set fso = CreateObject("Scripting.FileSystemObject")
CreateObject("WScript.Shell") 

If (fso.FileExists("C:\Program Files (x86)\Dell\KACE\AMPAgent.exe")) OR (fso.FileExists("C:\Program Files\Dell\KACE\AMPAgent.exe")) Then
  WScript.Echo("Installed")
  WScript.Quit()
Else
  WScript.Echo("Not Installed")
  WScript.Quit()

End If

It works when I run it in Windows 7. When I add it to BGInfo, it throws up this error...

Error evaluating scripted field 'KACE'

Microsoft VBScript runtime error

Line 7, position 2

Variable is undefined: 'WScript'

[OK]

I think I just need a way to define or call WScript to action since it's obviously not doing it through BGInfo on its own, and what I did isn't working. I haven't seen anything to help with this particular problem on StackOverflow already.

Any thoughts?

2
  • 3
    Would be useful to mention what BGinfo is, for us that don't know. Info here: technet.microsoft.com/en-us/sysinternals/bb897557.aspx. Good first post! Commented May 23, 2013 at 23:36
  • 1
    Thanks for the tip! I noticed yesterday that I always seem to find my answer on StackOverflow, but I had never joined it. This place is my goto place now. I'm glad my first Q&A go-round went well. :) Commented May 24, 2013 at 15:26

1 Answer 1

6

BGInfo implements its own scripting host and doesn't appear to emulate the WScript object. Browsing some snippets I found on the Internet, it looks like just plain Echo works inside BGInfo. A snippet:

On Error Resume Next
    call WScript.Echo(strReturn)    'for cmd line
    call Echo(strReturn)    'for BGInfo
on error goto 0

Note how On Error helps to make it work either way.

Sign up to request clarification or add additional context in comments.

2 Comments

+1. You beat me to it. I just found it in Mark's article here and was writing the same thing.
That worked perfectly! I also removed the quit lines since they seemed unnecessary, and it tested perfect on every test machine. Thank you very much for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.