0

I cant seem to create any shell related object while scripting asp.net web page with VB

Server.CreateObject("Wscript.Shell")

and

CreateObject("shell.application")

seems to return same error message. I believe I have done something wrong that I am not aware of. Can anybody please point where I am going wrong?

It gives the following error message

The component 'shell.application' cannot be created. Apartment threaded components can only be created on pages with an <%@ Page aspcompat=true %> page directive.

The component 'Wscript.Shell' cannot be created. Apartment threaded components can only be created on pages with an <%@ Page aspcompat=true %> page directive.

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you so much for your help. Now I'm not getting any error but still I can't use objects with shell.application to use the GetDetailsOf function. Can you pls help me with the shell.application problem?
@IshaqSheikMohamed That's a different question.
@Lankymart I have specified that I am facing problem with two things. I am not able to find any solution elsewhere

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.