Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBS access denied when executed via login script

Posted on 2014-09-04
5
Medium Priority
?
264 Views
Last Modified: 2014-09-04
I created the below from bits and pieces and it works fine when running it manually but making it run via group policy at login time results in "line 13 permission denied 800A0046 error". Its purpose is to perform a dir on a particular folder location then send the network. The location on the network allows "everyone" write access so I don't understand why. I would like to re-direct to another location if someone could tell me what to change....but would I still get permission denied?

Please help

Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim WshNetwork
Set WshNetwork = CreateObject("WScript.Network")
ComputerName = WshNetwork.ComputerName

set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders ("Desktop")

strRootFolder = strDesktop & "\list"
strOutputFile = computername & "DirListing.txt"
strResults = ""
EnumerateFolder objFSO.GetFolder(strRootFolder)
Set objOutput = objFSO.CreateTextFile(strOutputFile, True)
objOutput.Write strResults
objOutput.Close

Sub EnumerateFolder(objFolder)
      For Each objFile In objFolder.Files
            If strResults = "" Then
                  strResults = """" & Replace(objFile.Path, "\", """,""") & """"
            Else
                  strResults = strResults & VbCrLf & """" & Replace(objFile.Path, "\", """,""") & """"
            End If
      Next
      For Each objSubFolder In objFolder.SubFolders
            EnumerateFolder objSubFolder
      Next
End Sub
0
Comment
Question by:SimonJohnG
[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
  • 3
  • 2
5 Comments
 
LVL 36

Expert Comment

by:Kimputer
ID: 40303059
strOutputFile = computername & "DirListing.txt"

would resolve to something like: PcnameDirListing.txt

Later on you do:

 Set objOutput = objFSO.CreateTextFile(strOutputFile, True) which resolves to
 Set objOutput = objFSO.CreateTextFile(PcnameDirListing.txt, True) (location could be anywhere?)

So I'd say try this instead:

strOutputFile = strDesktop & "\" & computername & "DirListing.txt"

Open in new window

0
 

Author Comment

by:SimonJohnG
ID: 40303071
Hi Kimputer,

If I replace I get another error, would it be possible to show the complete code with your modifications, please note I'm new to this :)
0
 
LVL 36

Accepted Solution

by:
Kimputer earned 2000 total points
ID: 40303085
updated and tested (but remember, error if  desktop\list folder doesn't exist!

Set objFSO = CreateObject("Scripting.FileSystemObject")
 Dim WshNetwork
 Set WshNetwork = CreateObject("WScript.Network")
 ComputerName = WshNetwork.ComputerName

 set WshShell = WScript.CreateObject("WScript.Shell")
 strDesktop = WshShell.SpecialFolders ("Desktop")

 strRootFolder = strDesktop & "\list"
 strOutputFile = strDesktop & "\" & computername & "DirListing.txt"
 strResults = ""
 EnumerateFolder(strRootFolder)
 Set objOutput = objFSO.CreateTextFile(strOutputFile, True)
 objOutput.Write strResults
 objOutput.Close

 Sub EnumerateFolder(objFolder)
       For Each objFile In objFSO.GetFolder(objFolder).Files
             If strResults = "" Then
                   strResults = """" & Replace(objFile.Path, "\", """,""") & """"
             Else
                   strResults = strResults & VbCrLf & """" & Replace(objFile.Path, "\", """,""") & """"
             End If
       Next
       For Each objSubFolder In objFSO.GetFolder(objFolder).SubFolders
             EnumerateFolder objSubFolder
       Next
 End Sub

Open in new window

0
 

Author Comment

by:SimonJohnG
ID: 40303116
Perfect!!! Your a star!

Thank you
S
0
 

Author Closing Comment

by:SimonJohnG
ID: 40303117
Great solution and fantastic response. Thank you!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
For anyone that has accidentally used newSID with Server 2008 R2 (like I did) and hasn't been able to get the server running again because you were unlucky (as I was) and had no backups - I was able to get things working by doing a Registry Hive rec…
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

722 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