1

I'll try to keep this basic. I'm trying to run a shell on the server side (not the client). I've broken down my code so it's pretty basic. right now if I run this on the client side using CreateObject("Wscript.shell") it will 'document.write' the user in my browser.

<script type="text/vbscript" >
Set Shell = CreateObject("WScript.Shell")
Set whoami = shell.exec("whoami")
Set whoamiOutput = whoami.StdOut
strWhoamiOutput = whoamiOutput.ReadAll
document.write strWhoamiOutput

</script>

Now if I change my code to run on the server side:

<script type="text/vbscript" >
Set Shell = Server.CreateObject("WScript.Shell")
Set whoami = shell.exec("whoami")
Set whoamiOutput = whoami.StdOut
strWhoamiOutput = whoamiOutput.ReadAll
document.write strWhoamiOutput

</script>

I get an error in my browser telling me 'object required: server' at line 11. Line 11 is the 'Server.CreateObject' line. What am I missing here?

Thanks

2 Answers 2

1

From your 'document.write' and 'script' lines it would appear that you are trying to run this code in the browser... if so, you won't be able to do what you want to do.

server.createobject would be for VBScript/ASP usage on the server itself. (the 'server' object is an ASP object and would not be available in VBScript in the client browser)

To do what you want (if I am reading between the lines correctly) you would need to create an ASP script (or similar) on your server to grab the output from 'whoami' and return/output it. You could call it from your client-side page via javascript/AJAX.

(Keep in mind that running a command using 'WScript.Shell' carries its own set of security challenges, as well)

Sign up to request clarification or add additional context in comments.

1 Comment

I did find out yesterday I needed to use response.write if I'm executing at the server, which I was trying to do. But your are also right, I ran into a stop running command at the server. My actual script was trying to execute SQLCMD which turned out to be an issue when I executed it at the server. That CMD was running with the server account, not the AppPool PIN i specified that had the access I needed to run the SQLCMD. I researching some other options at this point.
0

In order for the script to run on the server, you need the runat attribute on your script tag:

<script type="text/vbscript" runat="server">

or, if your default scripting language is VBScript (which it will be unless you've explicitly changed it), then you should use the ASP script delimiters <% %> instead to avoid any unexpected results due to script execution order (see this SO question for more information).

Comments

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.