Solved

WScript.run output redirect fails

Posted on 2004-10-12
1
3,128 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
[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
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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/…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

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