Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

VBScript Error

Posted on 2009-02-13
12
Medium Priority
?
494 Views
Last Modified: 2013-11-26
Hello Experts,

I have a VBScript that runs without any problems on Windows XP however it throws an error on Vista. The error is Permission denied (Code 800A0046) Here is the line it does not like:

logfileobj.WriteLine "  "& sourcefolders(indx2) &" "&FormatNumber(ifobj.Size/1048576, 1)&" Megabytes"

The complete code is below


'**************************************************************
' Write out information about input folders
' Write each ones name and size to the log file
' Also log the total space needed to backup all input folders
'**************************************************************
  logfileobj.WriteLine "Input Folders to be copied:"
  Dim ifobj,indx2  ' Input Folder object, an index to the array
  For indx2 = 0 to UBound(sourcefolders, 1) 
    Set ifobj =  fso.GetFolder(sourcefolders(indx2))
    logfileobj.WriteLine "  "& sourcefolders(indx2) &" "&FormatNumber(ifobj.Size/1048576, 1)&" Megabytes"
    TotalInputBytes = TotalInputBytes + ifobj.Size
    Set ifobj = Nothing
  Next     'ifobj.Drive&"\"&ifobj.Name did not work well when copying from local dir
  Dim neededspace
  neededspace = FormatNumber(TotalInputBytes/1048576, 1) & " Megabytes"
  logfileobj.WriteLine "  Total size of input folders " & neededspace

Open in new window

0
Comment
Question by:eddiepardon
  • 6
  • 6
12 Comments
 
LVL 5

Expert Comment

by:vachooho
ID: 23637424
check what folder it is failing on
Is that user folder?

in any way on Vista you need more privileges
try running it elevated - Run as administrator
0
 

Author Comment

by:eddiepardon
ID: 23637486
How do I check check which folder it is failing on?

I am running it as the administrator.
0
 
LVL 5

Expert Comment

by:vachooho
ID: 23637582
what is the value of sourcefolders(indx2)

0
Industry Leaders: 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!

 

Author Comment

by:eddiepardon
ID: 23638325
The value of sourcefolders(indx2) = 0
0
 
LVL 5

Expert Comment

by:vachooho
ID: 23638395
that's the value which gets passed to GetFolder() and supposed to be folder path
if filesystemobject assumes null as system directory then it is a problem

shouldnt that be correct path there?
check your code when you fill in sourcefolders
0
 

Author Comment

by:eddiepardon
ID: 23640574
I check and the path for the sourcefolders are correct. Valid path correctly spelled.
0
 
LVL 5

Expert Comment

by:vachooho
ID: 23649548
you wrote:
>> The value of sourcefolders(indx2) = 0

0 is not correct value to pass to GetFolder()

Vista has additional security requirements - for example, if you are accessing other user folders you need privilege elevation, i.e. not only logged as admin, but also run as admin. There are others too.
I wanted to see what kind of folder you are trying to access. It may be the reason of permission denied.

I dont see any other problem with your code.
0
 

Author Comment

by:eddiepardon
ID: 23654853
How can I run it as the Admin? I am not sure this will make a difference, due to my ID being the administrator.

The types of folder are the default "My Document" & "Desktop" Folders.
0
 
LVL 5

Expert Comment

by:vachooho
ID: 23655769
Vista does not elevate process privileges to admin even your ID is admin.
You have to request it.

Click on start button. In search box type in cmd.exe
when CMD Shell appear in search list righclick and choose run as administrator
THen type
cscript your_script_file_name.vbs
or wscript your_script_file_name.vbs

it should run ok

You can create shortcut and run it with admin elevation also.
0
 

Author Comment

by:eddiepardon
ID: 23664089
I still get the same error. I have attached the vbs file as a text file. Maybe you can change the path for the sourcefiles and run it to see if you get the same error.
backup.txt
0
 
LVL 5

Accepted Solution

by:
vachooho earned 2000 total points
ID: 23674362
I wasn't able to access to users\...\Documents folder's size from vbscript's Folder object on Vista.
nor I was able to find information on the web on how to make this work.
Tightened security?...

Surprisingly Desktop folder is still accessible.

Here is another approach - I run DIR command and parse output to get folder size.
This works on all folders accessible by user.

You can put this (after a little modification) into your script and use it to get folder size.



        set oShell = CreateObject("WScript.Shell")
        sCmd = "cmd /C dir /S /-C """ & WScript.Arguments(0) & """ | find.exe ""File(s)"""
        WScript.Echo sCmd
        Set oExec = oShell.Exec(sCmd)
        if IsObject(oExec) then
            sLine = ""
            Do While oExec.Status = 0
                sLine = oExec.StdOut.ReadLine
                WScript.Sleep 100
            Loop
            Do While not oExec.StdOut.AtEndOfStream 
                sLine = oExec.StdOut.ReadLine
            Loop 
            Do While not oExec.StdErr.AtEndOfStream
                WScript.Echo oExec.StdErr.ReadLine
            Loop
 
            if sLine <> "" then
                nPos = InStr(sLine, "File(s)")
                sLine = Split(Trim(Mid(sLine, nPos + 7)), " ")(0)
                nSize = Int(sLine)
                WScript.Echo nSize
            end if
 
            WScript.Echo "Done with exit code " & oExec.ExitCode
        else
            WScript.Echo "Can not run command..."
        end if

Open in new window

0
 

Author Closing Comment

by:eddiepardon
ID: 31546770
Thanks for your help! It looks like I can modify this to work.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

572 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