Solved

Wscript.Shell

Posted on 2003-12-11
9
104,730 Views
Last Modified: 2011-08-18
Hi

I was trying to run a WScript.Shell command on the server so that i can zip the files in a folder. But to test it out i was trying to just do a simple command

<%
  set wshell = server.createobject("wscript.shell")
 intReturn =  wshell.run ("cmd.exe dir *.* > c:\test.txt")
 Response.Write(intReturn) ' This returns 0
 set wshell = nothing
%>

I have set the permissions of the web folder to Read/Write and also Script Access/Executables

RG
0
Comment
Question by:rgarimella
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 19

Expert Comment

by:Dexstar
ID: 9922536
@rgarimella:

> I was trying to run a WScript.Shell command on the server so that i can zip
> the files in a folder. But to test it out i was trying to just do a simple command

I don't see a question or problem here.  The 0 indicates it executed successfully.  Also, the IUSR_ is going to need to have write access on the file C:\Test.txt.

What were you expecting?

Try this:
     <%
          Dim wshell, proc
          set wshell = server.createobject("wscript.shell")
          set proc = wshell.exec("%comspec% /c dir *.*")

          ' Wait the process to finish
          Do While proc.Status = 0
               WScript.Sleep 100
          Loop

          Response.Write proc.StdOut.ReadAll
          set wshell = nothing
     %>

Hope That Helps,
Dex*
0
 

Author Comment

by:rgarimella
ID: 9922570
Dex,

Your code is giving me the following error

Object doesn't support this property or method: 'exec'

Also in my code i dont see the test.txt file physically.

IUSR also has the permission

RG
0
 
LVL 19

Accepted Solution

by:
Dexstar earned 50 total points
ID: 9922667
That's really odd.  It should support that method.  Maybe you're using an older version of it?

Try this:
     <%
          Dim wshell, intReturn
          set wshell = server.createobject("wscript.shell")
          intReturn = wshell.run("%comspec% /c dir *.* > c:\test.txt", 0, True)
          Response.Write( intReturn )
          set wshell = nothing
     %>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rgarimella
ID: 9922747
I am using Win 2K

OK now it worked

I still dont understand why my code did not work. What is the difference

RG
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9922768
@rgarimella:

> I still dont understand why my code did not work. What is the difference

     Your Line:   intReturn = wshell.run ("cmd.exe dir *.* > c:\test.txt")
     Mine Line:   intReturn = wshell.run ("%comspec% /c dir *.* > c:\test.txt", 0, True)

1) In mine, I use the environmental COMSPEC, which will contain the full path to the CMD.EXE.  Like C:\Winnt\system32\cmd.exe ... It might not work because it can't find cmd.exe.

2) I also added the /c, which tells CMD to run the command, and then exit.  Without it, you might end up with a bunch of cmd.exe running on your server with no way to kill them.

3) I also set the last parameter to Run to be "True", which tells it to wait until the program exits before continuning.  That way, if there is a delay creating that file, you won't miss it.

HTH,
Dex*
0
 

Author Comment

by:rgarimella
ID: 9922790
Thanks Dex Appreciate it

RG
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9922805
No problem!  :)

Peace,
Dex*
0
 

Expert Comment

by:zguille
ID: 10401561
Hi, in javascript I'm using WScript.Shell, but the line var ws = new ActiveXObject("WScript.Shell"); cause a warning message asking to accept or not the ActiveX interaction. Is there a wau to avoid this message?
Thanx in advance,
Guillermo
0
 

Expert Comment

by:__ZaM__
ID: 10830143
The user must set internet secury preferences to allow scripting on activeX control nor marked as "safe"

The easy way to solve this is including your web site in the "safe zone", and relax the security restrictions on that zone


Another tip, the run method is available from JScript 5.6, and Win2K comes by default with JScript 5.5. So if you want the run method works, you must either update the browser to IE6 or the JScript runtime standalone.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Html form and modal / img src -problem 3 60
Send form to asp server side 6 38
Html split(text) 2 49
Post from Jquery mobile form goes wrong in classic asp action page 2 37
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question