无法创建shell对象

时间:2016-06-13 22:04:15

标签: asp.net vb.net com

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

Server.CreateObject("Wscript.Shell")

CreateObject("shell.application")

似乎返回相同的错误消息。我相信我做错了,我不知道。任何人都可以指出我出错的地方吗?

它提供以下错误消息

  

组件&#39; shell.application&#39;无法创建。公寓线程组件只能在具有<%@ Page aspcompat=true %>页面指令的页面上创建。

     

组件&#39; Wscript.Shell&#39;无法创建。公寓线程组件只能在具有<%@ Page aspcompat=true %>页面指令的页面上创建。

1 个答案:

答案 0 :(得分: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>
相关问题