none
Cannot run string in oShell.Run RRS feed

  • Question

  • Hello,

    I have a script which has to call 32 bits objects (starting SCCM actions).

    I created a main vbs script and a secondary script containing the 32 bits objects, called StartCMPolicies.vbs

    In the main script I can easily call the second script:

    oShell.Run("C:\Windows\SysWOW64\cmd /k cscript C:\Users\alexandru.cojocaru\Desktop\StartCMPolicies.vbs")

    The problem is that I want to run this on any computer so I have to use %userprofile% instead of my name. I just can't make it work. If I try something like:

    userProfilePath = oShell.ExpandEnvironmentStrings("%UserProfile%")

    str = " " & userProfilePath & "\Desktop\StartCMPolicies.vbs"

    oShell.Run("C:\Windows\SysWOW64\cmd /k cscript & str")

    ... it will take literally the & str characters instead of the path behind. I can't put "str" either. I think it's something simple that I can't see. Could you please help me with that.

    Thanks, Alex

    Wednesday, August 13, 2014 5:45 PM

Answers

  • The Run method expands environment variable references in %; e.g.:


    oShell.Run("%SystemRoot%\SysWOW64\cscript.exe %USERPROFILE%\Desktop\StartCMPolicies.vbs")

    (If that's really what you want to do)


    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by Mike Laughlin Wednesday, August 13, 2014 8:28 PM
    • Marked as answer by Alex Cojocaru Thursday, August 14, 2014 7:22 AM
    Wednesday, August 13, 2014 5:51 PM
    Moderator

All replies

  • The Run method expands environment variable references in %; e.g.:


    oShell.Run("%SystemRoot%\SysWOW64\cscript.exe %USERPROFILE%\Desktop\StartCMPolicies.vbs")

    (If that's really what you want to do)


    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by Mike Laughlin Wednesday, August 13, 2014 8:28 PM
    • Marked as answer by Alex Cojocaru Thursday, August 14, 2014 7:22 AM
    Wednesday, August 13, 2014 5:51 PM
    Moderator
  • Thank you so much, it worked! I preferred see it in cmd for better visual of the actions:

    oShell.Run("%SystemRoot%\SysWOW64\cmd /k cscript %UserProfile%\Desktop\StartCMPolicies.vbs")

    Thursday, August 14, 2014 7:22 AM