Solved

WScript.run output redirect fails

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

615 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