Solved

WScript.run output redirect fails

Posted on 2004-10-12
1
3,087 Views
Last Modified: 2007-12-19
I am trying to call a command from WScript.run and redirect that command's output to a file.
When I call:

errCode = oShell.run("%comspec% /c nslookup " & ipStr,0,True)

everything goes fine and errCode gets a zero.  When I try:

errCode = oShell.run("%comspec% /c nslookup " & ipStr & " > " & filePath,0,True)

errCode gets a 1.  I have tried setting IIS to use the Administrator account for Anynomous Access thinking that this an issue of write permissions, but this didn't solve the problem.  When I enter the command in the run box, everything works as expected.

Please help.  Thanks.
0
Comment
Question by:egjeg
1 Comment
 
LVL 4

Accepted Solution

by:
mistyrae earned 125 total points
ID: 12294406
The thing about setting the Anonymous User in IIS is this: You are only change the IUSR_ account, not the IWAM_ account (which is the account that your script is running under when it launches anything).

Provided your output path (the variable value of filepath in your example code) is located within your web site, you must perform these steps in order to save the file:
1. Change the account back to the IUSR_ account. No need giving Administrator access through your website.
2. Make sure that IUSR_ and IWAM_ both have Change permission on the directory that the file is to be saved to.
    - In explorer, go to the directory, right click it and select Properties
    - Go to the security tab
    - If IUSR_<machinename> and IWAM_<machinename> don't exist in the permission list, add them.
    - Repeat for each IUSR_ and IWAM_:
             Highlight account
             Check the Modify Permission (this will check Modify, Read & Execute, List Folder Contents and Write... Clicking the Full Control option gives WAY too many permissions - for an idea, click Advanced to see how many more)
3. In the Internet Information Services MMC, navigate to the directory that the file will be saved to (within your website) and click properties.
4. On the Directory tab, check the Write option, located in the center of the dialog.
5. Click OK.

That should allow you to pipe the command output into your webspace to access it later.

If your machine has the latest and greatest VBScript interpreter (5.6), you can get around having to pipe the info out at all and just read it directly from the stdOut of the command line like:

Set oShell = Server.CreateObject("WScript.Shell")
Set oExec = oShell.Exec("%comspec% /c nslookup " & ipStr)
Do
      tmpStr = oExec.StdOut.ReadAll()
Loop While Not oExec.Stdout.atEndOfStream
RetCode = oExec.stderr.readall

Set oExec = Nothing
Set oShell = Nothing

The variable tmpStr will now contain all of the info from the stdout for nslookup. The RetCode variable will hold the error code as you are accustomed to.

Hope this helps!

- misty
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now