【问题标题】:Cannot create shell objects无法创建外壳对象
【发布时间】:2016-10-14 11:16:46
【问题描述】:

在使用 VB 编写 asp.net 网页脚本时,我似乎无法创建任何与 shell 相关的对象

Server.CreateObject("Wscript.Shell")

CreateObject("shell.application")

似乎返回相同的错误消息。我相信我做错了我不知道的事情。谁能指出我哪里出错了?

它给出以下错误消息

无法创建组件“shell.application”。只能在带有<%@ Page aspcompat=true %> 页面指令的页面上创建单元线程组件。

无法创建组件“Wscript.Shell”。只能在带有<%@ Page aspcompat=true %> 页面指令的页面上创建单元线程组件。

【问题讨论】:

    标签: asp.net vb.net com


    【解决方案1】:

    MSDN Article for COM Component Compatibility

    <%@ Page AspCompat="true" Language="VB" %>
    
    <script runat="server">
        Dim WshShell = Server.CreateObject("Wscript.Shell")
    
        Protected Sub doStuff(strCommand, cliint)
            Select Case cliint
                Case "cmd"
                    strCommand = "%SYSTEMROOT%\cmd.exe /c " & strCommand & " 2>&1 %SYSTEMROOT%\Logs\some_kind_of.log"
                Case "ps"
                    'will obviously require you modify execution policies...
                    strCommand = "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe " & strCommand & " 2>&1 %SYSTEMROOT%\Logs\some_kind_of.log"
                Case else
            End Select
            WshShell.Run(strCommand)
        End Sub
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
            </div>
        </form>
    </body>
    </html>
    

    【讨论】:

    • 非常感谢您的帮助。现在我没有收到任何错误,但我仍然不能使用带有 shell.application 的对象来使用 GetDetailsOf 函数。你能帮我解决 shell.application 问题吗?
    • @IshaqSheikMohamed 这是一个不同的问题。
    • @Lankymart 我已经指定我面临两件事的问题。我无法在其他地方找到任何解决方案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-19
    • 1970-01-01
    • 2013-10-22
    • 2017-10-01
    • 2013-10-21
    • 1970-01-01
    相关资源
    最近更新 更多