VB Script error

Posted on 2014-08-10
Last Modified: 2014-08-10
Hey guys.

So, I've been trying to teach myself scripting by looking at my company's existing scripts and attempting to reverse engineer.  I've had some experience with scripting and programming many moons ago, but I can still more or less follow what's going on.

So, I have a maddening issue.  A script created in 2004 by either a former employee or one found on the internet intermittently works.  The job of the script is to take an AD group as input, verify the domain and OU and return a list of accounts in that group.  As I've said, it works sometimes and other times it fails with an access denied message on a specific line.  I've added it below.

Set objGroupLog = fso.CreateTextFile(strGroupLog, True)

This line is in a section where it's trying to write a log, but I'm not sure where it's trying to write to.  I have more lines of the script, but have seen people be annoyed at posters for copy and pasting the entire script.  I can add any info you'd like to give me a hand.
Question by:Ray Drummond
    LVL 142

    Assisted Solution

    by:Guy Hengel [angelIII / a3]
    Check the content of strGrouplog variable, it contains the file name. If that contains some special character not allowed for file names, this could raise this error

    Author Comment

    by:Ray Drummond
    Hi Guy.

    Thanks for responding.  I think this is the line you're referencing.

    strGroupLog = "c:\" & strGroup & "_" & strDateStamp & ".txt"

    When I run the script, where I would enter the group name there is a value already listed and I have to delete it and enter the correct group name.
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    So can you show some group names where your script goes into the error?
    LVL 67

    Accepted Solution

    (Hi Guy :^)

    My guess would be it's not launching from an elevated environment.  Typical users won't have access to write to the root of C:
    Either launch the script elevated, or modify the variable strGroupLog.

    strGroupLog = "c:\ADGroupInfo\" & strGroup & "_" & strDateStamp & ".txt"

    Open in new window

    '(Make sure C:\AdGroupInfo exists before running)

    Author Comment

    by:Ray Drummond
    So, both of you helped, but it turns out that SirBounty's info is what fixed the issue.  I always commented to colleagues that it always worked on Windows XP.  Forgot about that difference to Windows 7

    Thank you both.

    Author Closing Comment

    by:Ray Drummond
    Another step closer to understanding this.  Thanks.
    LVL 67

    Expert Comment

    Glad you found your solution.  Thanks for the grade! :^)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
    Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    794 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