Link to home
Start Free TrialLog in
Avatar of keystrokes
keystrokesFlag for United States of America

asked on

WScript Object - Example needed

[I accidentally posted this question under "web development" but I don't know how to delete it - needless to say I got no answer there and wasted points]

I know how to write the codes but it doesn't work for me.  I mean thing was done after running the asp file.

Here is the ASP code:
'=========================
<%
dim WshShell
set wshshell=server.CreateObject("WScript.shell")
WshShell.Run("c:\test.bat")
Set WshShell=Nothing
%>
'==========================
Here is the content of test.bat:

echo this is a test>test.log

After running the above asp code I expect to see a file test.log in my c:\ directory on the server.  But I don't see it.  Can someone give me an example of a working code so I can test to see this shell command object actually works ?

Thanks in advance.  If it works I'll increase the points of course.
Avatar of ejulson
ejulson

The Wscript.Shell object is not available to IIS.This object is only available to the Windows Scripting Host.

If you want to write to a file, you should consider using a FileSystemObject in your ASP page.
The Wscript.Shell object is not available to IIS.This object is only available to the Windows Scripting Host.

If you want to write to a file, you should consider using a FileSystemObject in your ASP page.
Avatar of keystrokes

ASKER

Do you have any links, references?
I found a link from microsoft that this object works. http://support.microsoft.com/default.aspx?scid=kb;en-us;301309#5
This crap only works on some servers.  I have heard some report from some people the exact same code worked.  Anyone knows why?
keystrokes:

That code runs provided that you have Visual Studio 6.0 (or up I assume).

"This method requires that you install Visual Basic 6.0. In this method, you create a Visual Basic ActiveX DLL project in order to create a COM component that you can use in your ASP page. This COM component contains a method that uses the LogEvent method of the Application object to write the passed text to the Event Log."

Whereas FSO is always available.
Look at the example here: http://asp-hispeed-logging.pstruh.cz/help/ScptUtl/pa24.htm

Mikkol
It is the process permissions that IIS 5 is running under.  I'm looking for a doc to explain this, but if you change the "Application Protection" on the website to "Low", your problem should be solved.  (With noted security issues!)
Application Protection

Select whether applications are run in the same process as Web services (low), in an isolated pooled process in which other applications are also run (medium), or in an isolated process separate from other processes (high).

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iisref/htm/developingdebuggingandsecuringiisapplications.asp


Avatar of Mark Franz
"The Wscript.Shell object is not available to IIS.This object is only available to the Windows Scripting Host."???

What is this?

Your code is fine, the problem has to do with permissions that the file and the directory you are trying to run the WScript from, the IUSER_ has to have Read/Write/Exe perms on the directory or the file.
More details here; http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsoriWindowsScriptHost.asp

And:
* Run the Internet Services Manager for IIS.
* Right Click on the Website in question and select properties
* Under the 'Directory' Tab, Towards the bottom, change Execute Permissions from Scripts Only to Scripts and Executables.

You don't need Visual Basic either, WSH is installed with XP and W2K, but if you are not sure it's installed you can get it here; http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/728/msdncompositedoc.xml
ASKER CERTIFIED SOLUTION
Avatar of Mark Franz
Mark Franz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
mikkolsoft:

Where did you get the quote from?  Please send me the link.  This sounds odd: I actually tried to LogEvent method and it worked.  But the Run function didn't work.  If it was a VB component problem, wouldn't it affect the LogEvent method also?
mqfranz:
You know I am very generous with the points.  I give 20 points to the answer that sounds technically correct regardless of the issue, eventhough it doesn't solve my problem.  If it does, the points will increased accordingly.
Did you try my suggestion of unregistering the .ocx and .dll, then reinstalling WSH?

There are a lot of good suggestions here, (some better than others), have you had a chance to try them out?

If you ask CS to delete the Q at WD I'm sure they will accomidate you.
keystrokes:

haha I found that from the MS link you provided! Just a bit under it which says "Requirements That Are Specific to This Method" :P Good luck.

Mikkol
mikkolsoft:

I don't doubt that this component is required for specific IIS settings, otherwise I'd have made it work already, with mqfranz's so many suggestions.
Guess what guys?

The component was working all this time but I just didn't know it because it took me for a detour.  I did a file search and I found the product of the asp using wsh.  It's actually under two directries, one is the "winnt\system32" and the other one is under "documents and settings\user1\recent", instead of the root directory where the batch file is located.  

As for running any other files such as exe files, I guess I'll have to change the setting of the server to see if it works.  For the time being, this is fine for my purpose.  

Hope this will help your future development!  Hey you guys got to give me the points instead.  

Actually, I'll give mqfranz the points for his hard work, and thanks everyone.
Glad to know it works. Yes mqfranz deserves the pts for the research and stuff :)

Mikkol