0

I need to run PowerShell command lines in Classic ASP and return the search result.

I found a code, but it's not working

    <%
Set objShell = server.CreateObject("WScript.Shell")
Set objExec = objShell.Exec("powershell.exe -Command dir")
Set objStdOut = objExec.StdOut

While Not objStdOut.AtEndOfStream
   Response.write objStdOut.ReadLine
Wend

objExec.StdIn.Close()

%>

Does not generate error and page returns blank.

Can someone help me?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • Please _edit the question_ and add more details. What happens when you call the page? Do you get any output at all? If there's an error message, copy and paste the exact text into question body. If you add a few debugging `response.write` statements, do you get their output included in HTML source? – vonPryz Oct 08 '19 at 18:59
  • Hy @vonPryz, When the page runs, nothing happens. – Erick de Abreu Gomes Oct 08 '19 at 19:25
  • Did you check the page source? Depending on your browser, it might not show anything if there aren't proper HTML tags around. – vonPryz Oct 08 '19 at 19:34
  • The page contains only these lines. Does not generate error and page returns blank – Erick de Abreu Gomes Oct 08 '19 at 19:41
  • I can't imagine a scenario where running a PowerShell script from a web worker process is a good idea. Can you provide some details on what you're hoping to accomplish by doing this? – Daniel Mann Oct 08 '19 at 19:47
  • Hy @Daniel Mann, I am creating a web panel hosting, where I need to retrieve some information from the server, such as the PHP version, create a database, etc. The above example is for test run only. – Erick de Abreu Gomes Oct 08 '19 at 19:52
  • If you add a few debugging `response.write` calls, do you get output from those to the page? – vonPryz Oct 08 '19 at 19:54
  • Creating a database from your web process is *not* a good idea. You should have an asynchronous RESTful service you can call and query to do things that aren't rendering HTML and delivering it to a browser. – Daniel Mann Oct 08 '19 at 19:57
  • Hy @vonPruz, yes.if I digital response.write "test" returns test on page – Erick de Abreu Gomes Oct 08 '19 at 19:59
  • Hello @Daniel Mann, to create a MySQL database may not even be a good idea, but to add a new domain in IIS, manage the DNS server, I believe you do not have another solution. – Erick de Abreu Gomes Oct 08 '19 at 20:05
  • 1
    see:https://stackoverflow.com/a/53852374/1682881 – Flakes Oct 09 '19 at 16:35
  • 2
    `Set objExec = objShell.Exec("cmd /c powershell dir")` should do it. – Flakes Oct 09 '19 at 16:41
  • Possible duplicate of [Running VBS script on server from IIS (ASP)](https://stackoverflow.com/questions/17697924/running-vbs-script-on-server-from-iis-asp). Might not be Powershell but it runs the command line exactly the same way. – user692942 Oct 10 '19 at 07:16
  • 1
    @ErickdeAbreuGomes feel I have to say it but building a hosting platform using a 20+ year old technology is never a good idea. – user692942 Oct 10 '19 at 07:20

0 Answers0