[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2123
  • Last Modified:

WScript.Shell command run method returns 1

Hi

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("wscript.shell")
 intReturn = wshell.run("%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

0
galaxy78r
Asked:
galaxy78r
  • 3
  • 2
1 Solution
 
HilaireCommented:
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("wscript.shell")
 intReturn = wshell.run("c:\test.vbs", 0, True)
 Response.Write( intReturn )
 set wshell = nothing
%>



0
 
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 ???
0
 
HilaireCommented:
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 ?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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  
 
0
 
mk_bCommented:
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)
file.WriteLine(strResult)
file.Close
%>
check the text file....



this looked interesting to>
http://www.outlookexchange.com/articles/glenscales/icomprn.asp

../mk
0
 
HilaireCommented:
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)
http://www.serverobjects.com/products.htm

- use you own component, full code available on microsoft site
HOWTO: Impersonate a User from Active Server Pages
http://support.microsoft.com/default.aspx?scid=KB;en-us;q248187

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

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now