WScript.Shell command run method returns 1


I was trying to run a WScript.Shell command in an asp page
the commande runs the  file test.vbs which does a very simple thing it just output a message hello

 Dim wshell, intReturn
 set wshell = server.createobject("")
 intReturn ="%comspec% /c dir *.* > c:\test.vbs", 0, True)
 Response.Write( intReturn )
 set wshell = nothing

-the problem is that :the code always return 1 which indecates failure
I have set the permissions of the web folder to Read/Write and also Script Access/Executables and also set permissions for the IUser_XXXXX on the cmd.exe file

 any help would be appreciated

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

There's a problem with your command

dir *.* > c:\test.vbs

runs a dir *.* command on the current directory and redirects the output to the test.vbs file
">" is a redirection symbol

To run test.vbs, just use

 Dim wshell, intReturn
 set wshell = server.createobject("")
 intReturn ="c:\test.vbs", 0, True)
 Response.Write( intReturn )
 set wshell = nothing

galaxy78rAuthor Commented:
ok I put the code  you supplied in an asp file and call it ... and that's what happens
1- The server beeps
2-The explorer page keeps pretending to execute  the code
but the code is not executed .
Next i  changed the code in the vbs .. to make it create  a txt file instead of the hello message .... and i gave the IUser_xxxxx full permission on the folder  where the txt file is supposed to be created  ... but the same scenario of the beep happens
what the  wrong am doing ???
When you run VBS from the server, it's not connected to a user session !
The output of the VBS is not redirected to the HTTP stream as if it were a Response.Write

The code, executes on the server, period.

Now if you need to create a file you could do it directly in your ASP code.
Could you elaborate on what you actually need to achieve ?
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

galaxy78rAuthor Commented:
ok that's exactly what i want to do  .... i Have an excahange server and  I want the user to be able to create  his own mailbox through a registration form on my site ... But to create account and mailbox on the server i need to run the script as admin .So after alot of digging and after i kept on pulling out my hair for three day I  found some impersnation code that can create the user account succeffully on the server after putting the admin user name and password hard coded in the asp file.But when i use impersonation on creating the  mailbox it gives me an error so i thought of a work arround that is:To put the creation script in a VBS and running it through an asp page .But then I will get to the main old problem which is that the executer of the code has to admin and not IUser_xxxxxx
Here ,that's my story since i was born  :) and i came out with no hair left :D hehehe
Help me please  
try this i copies my ipconfig.exe into the wwwroot and then ran this script

strWshCommand = Server.MapPath("ipconfig.exe")

dim objExec, objWshShell, objStdOut
dim strComputerName, strResult

set objWshShell = CreateObject("WScript.Shell")
set objExec = objWshShell.Exec (strWshCommand)
set objStdOut = objExec.StdOut

strResult = objStdOut.ReadAll

set objExec = nothing
set objWshShell = nothing
set objStdOut = nothing
set fs = CreateObject("Scripting.FileSystemObject")
set file = fs.CreateTextFile("C:\temp\10312000.txt", true, false)
check the text file....

this looked interesting to>

There are several methods available to impersonate another user
- use the ASPExec free component
available at the bottom of this page (zip comes along with sample asp code)

- use you own component, full code available on microsoft site
HOWTO: Impersonate a User from Active Server Pages;en-us;q248187

- use Wscript.Shell to run the RUNAS dos command
type runas /? in a dos box to get help on runas

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.