Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8875549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:00:00+00:00 2026-06-14T19:00:00+00:00

I am trying to call Powershell with the Exec method of the WshShell object.

  • 0

I am trying to call Powershell with the Exec method of the WshShell object. I am writing the script in JScript, but I have reproduced the problem in VBScript as well. Both of the following short test scripts will cause WSH to hang indefinitely:

test.js

var shell = new ActiveXObject("WScript.Shell");
WScript.Echo(shell.exec("powershell -Command $Host.Version; Exit").StdOut.ReadAll());

test.vbs

dim shell

set shell = CreateObject("WScript.Shell")
WScript.Echo shell.exec("powershell -Command $Host.Version; Exit").StdOut.ReadAll

Am I doing something wrong, or am I running into or a limitation/incompatibility? The Run method works very well, but I need to capture output, which it’s not capable of doing.

Edit: I forgot to mention that my platform is Windows 7 Pro, 64-bit with PowerShell 3. I’ve tested on Windows XP with PowerShell 1 as well.

Edit 2: I’ve updated the test scripts that I’m running to fit with x0n’s answer. Unfortunately, I’m still having trouble. Here are my current tests:

test.js:

var shell = new ActiveXObject("WScript.Shell");
WScript.Echo(shell.exec('powershell -noninteractive -noprofile -Command "& { echo Hello_World ; Exit }"').StdOut.ReadAll());

test.vbs:

dim shell

set shell = CreateObject("WScript.Shell")
WScript.Echo shell.exec("powershell -noninteractive -noprofile -Command ""& { echo Hello_World ; Exit }""").StdOut.ReadAll
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:00:01+00:00Added an answer on June 14, 2026 at 7:00 pm

    You have to close StdIn:

    var shell = new ActiveXObject("WScript.Shell");
    var exec = shell.Exec('powershell -noninteractive -noprofile -Command "& { echo Hello_World ; Exit }"');
    exec.StdIn.Close();
    WScript.Echo(exec.StdOut.ReadAll());
    

    Microsoft said:

    StdIn is still open so PowerShell is waiting for input. (This is an
    "implementation consideration" that we're hoping to fix in V2. The
    PowerShell executable gathers all input before processing.) So
    objexec.StdIn.Close() needs to be added.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a powershell script which call the .ftp file (
I'm defining a function in PowerShell and trying to call it as shown below.
Im trying to call a method that will add or subtract 1 from a
I'm trying to call a method from another class with a simple button in
I am trying to call c# function from javascript the code i have tried
I'm trying to come up with a powershell script thatcan determine the last number
I am trying to write a powershell script that automates Splunk's oneshot command which
I'm trying to run a Powershell command to call 7-Zip to zip up a
Can anybody help me with this?: I'm trying call a method from a my
Scenario : Trying to call the .AttachAll method on a table in my LinqToSql

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.