Solved

VBS access denied when executed via login script

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Moving on from sbs 2008... 36 129
vb.net deleting excel sheet in workbook 11 50
FTP servers in Windows 2008 5 88
User Folder Creation and Permissions 3 32
You might have come across a situation when you have Exchange 2013 server in two different sites (Production and DR). After adding the Database copy in ECP console it displays Database copy status unknown for the DR exchange server. Issue is strange…
A procedure for exporting installed hotfix details of remote computers using powershell
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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…

734 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