Solved

VBS access denied when executed via login script

Posted on 2014-09-04
5
255 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Perfect!!! Your a star!

Thank you
S
0
 

Author Closing Comment

by:SimonJohnG
Comment Utility
Great solution and fantastic response. Thank you!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Scenario:  You do full backups to a internal hard drive in either product (SBS or Server 2008).  All goes well for a very long time.  One day, backups begin to fail with a message that the disk is full.  Your disk contains many, many more backups th…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This tutorial will give a an overview on how to deploy remote agents in Backup Exec 2012 to new servers. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as connecting to a remote Back…
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…

772 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

10 Experts available now in Live!

Get 1:1 Help Now