Solved

VBS access denied when executed via login script

Posted on 2014-09-04
5
260 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

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.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

828 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