Solved

WScript.run output redirect fails

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

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 was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
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…

777 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