Solved

WScript.run output redirect fails

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 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