0

I have a script below:

Dim g_oWShell 
Set g_oWShell = CreateObject("WScript.Shell")

But when I validate the value of g_oWShell first, that object is null (nothing). Below are the codes I'm debugging:

If g_oWShell Is Nothing Then
    'display an error. 
Else
    'run Something... (Ex. g_oWShell.Run("...")
End If

I'm new to VBS and I'm not sure why is that the case. I have read a short definition of CreateObject method here: VBA CreateObject

Advance thanks for explaining what might I have missed.

EDIT:

I'm creating an MSI installer using Visual Studio.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Cyberpau
  • 125
  • 9
  • What is the error you are getting ? – Mithilesh Indurkar Jun 28 '17 at 08:56
  • Actually its not an error. I just made an if else and if g_oWShell is nothing, it will show me some error I made, because obviously .Run("...") won't work if the object is nothing. It's just a validation... Sorry if it's confusing.. – Cyberpau Jun 28 '17 at 09:02
  • 2
    How are you validating the "value" of g_oWShell? What do you mean by value of an object exactly? Your code should run fine. – Gurmanjot Singh Jun 28 '17 at 09:10
  • 1
    As Kira said, this code should run fine, provided that the CreateObject and your If condition are in the same scope. E.g. same Function or SubRoutine. – Mithilesh Indurkar Jun 28 '17 at 10:22

0 Answers0