Solved

VBS access denied when executed via login script

Posted on 2014-09-04
5
256 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
  • 3
  • 2
5 Comments
 
LVL 35

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 35

Accepted Solution

by:
Kimputer earned 500 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…

910 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

20 Experts available now in Live!

Get 1:1 Help Now