We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

VBScript Error

Medium Priority
506 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

Comment
Watch Question

Commented:
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

Author

Commented:
How do I check check which folder it is failing on?

I am running it as the administrator.

Commented:
what is the value of sourcefolders(indx2)

Author

Commented:
The value of sourcefolders(indx2) = 0

Commented:
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

Author

Commented:
I check and the path for the sourcefolders are correct. Valid path correctly spelled.

Commented:
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.

Author

Commented:
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.

Commented:
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.

Author

Commented:
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
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thanks for your help! It looks like I can modify this to work.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.