首页 文章

没有窗口的html cmd或powershell命令

提问于
浏览
0

有没有办法在不打开控制台窗口的情况下从html文件激活powershell或cmd命令?例如,以下代码运行l.bat文件,我没有显示输出,但仍然有一个PowerShell窗口,该文件运行时打开

码:

<OBJECT id=z classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" width=5 height=5>
<PARAM name="Command" value="ShortCut">
<PARAM name="Button" value="Bitmap::shortcut">
<PARAM name="Item1" value=",powershell.exe ,Start-Process &#45WindowStyle hidden 'l'">
</OBJECT>

任何的想法?

1 回答

  • 1

    如果你想在html文件或你的网站中运行脚本或bat文件想要运行脚本你可以使用visual studio并添加名为PowerShellExecution的Web应用程序default.aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="PowerShellExecution.Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
    </head>
    <body>
    <form id="form1" runat="server">
        <div>
            <table>
                <tr><td>&nbsp;</td><td><h1 align="left">PowerShell Command Harness</h1></td></tr>
                <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
                <tr><td>&nbsp;</td><td>PowerShell Command</td></tr>
                <tr><td>
                    
    </td><td> <asp:TextBox ID="Input" runat="server" TextMode="MultiLine" Width="433px" Height="73px" ></asp:TextBox> </td></tr> <tr><td> &nbsp;</td><td> <asp:Button ID="ExecuteCode" runat="server" Text="Execute" Width="200" onclick="ExecuteCode_Click" /> </td></tr> <tr><td>&nbsp;</td><td><h3>Result</h3></td></tr> <tr><td> &nbsp;</td><td> <asp:TextBox ID="ResultBox" TextMode="MultiLine" Width="700" Height="200" runat="server"></asp:TextBox> </td></tr> </table> </div> </form> </body> </html>

    工具菜单选择库包管理器>>包管理器控制台包管理器控制台执行“Install-Package System.Management.Automation”成功执行该包安装后,您将要添加对Default.aspx.cs文件的引用:

    using System.Management.Automation;
    

    在你的Default.aspx.cs中

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Management.Automation;
    using System.Text;
    
    namespace PowerShellExecution
    {
        public partial class Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void ExecuteCode_Click(object sender, EventArgs e)
            {
                // Clean the Result TextBox
                ResultBox.Text = string.Empty;
    
                // Initialize PowerShell engine
                var shell = PowerShell.Create();
    
                // Add the script to the PowerShell object
                shell.Commands.AddScript(Input.Text);
    
                // Execute the script
                var results = shell.Invoke();
    
                // display results, with BaseObject converted to string
                // Note : use |out-string for console-like output
                if (results.Count > 0)
                {
                    // We use a string builder ton create our result text
                    var builder = new StringBuilder();
    
                    foreach (var psObject in results)
                    {
                        // Convert the Base Object to a string and append it to the string builder.
                        // Add \r\n for line breaks
                        builder.Append(psObject.BaseObject.ToString() + "\r\n");
                    }
    
                    // Encode the string in HTML (prevent security issue with 'dangerous' caracters like < >
                    ResultBox.Text = Server.HtmlEncode(builder.ToString());
                }
            }
        }
    }
    

    “PowerShell命令”窗口Get-EventLog安全性 - 最新10(或您最喜欢的cmdlet用于测试) . 或者把脚本放在那只是改变

    //shell.Commands.AddScript(Input.Text);
    shell.Commands.AddScript("C:\\Scripts\\PowerShell\\PowerShellScript.ps1")
    

    但对于运行脚本,您应该在PowerShell 32位和64位64位中运行Set-ExecutionPolicy旁路

    C:\Windows\System32\WindowsPowerShell\v1.0
    

    32位

    C:\Windows\SysWOW64\WindowsPowerShell\v1.0
    

    你应该运行visual studio并在你的iis中发布非常简单,为你可以使用的dns添加功能iis

    C:\Windows\System32\drivers\etc
    

    在主机文件中

    127.0.0.1 soheil.com
    

    我希望我理解你的需要问候

相关问题