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
Solved

WSH Object required running a VB script

Posted on 2009-05-07
7
1,776 Views
Last Modified: 2012-05-06
I have a script to copy a file. It runs fine on my PC, but on another person's PC it gives a WSH (Windows Script Host) error with the error "Object Required". Both PCs are running Windows XP SP3.

Here is the script:
Option Explicit
Dim oArgs, fileToCopy, destination, objShell, objFolder
Set oArgs = WScript.Arguments.Unnamed
fileToCopy = oArgs.Item(0)
destination = oArgs.Item(1)
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(destination)
objFolder.CopyHere fileToCopy

If I comment out the last line of the script, I don't get any errors.

I presume the other PC has got VB Script installed, as it can run the following simple script:
WScript.Echo "Hello World"
0
Comment
Question by:AlexInAustralia
  • 4
  • 2
7 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 200 total points
ID: 24332521
According to

   http://msdn.microsoft.com/en-us/library/bb774085(VS.85).aspx

the Namespace method returns null if the folder could not be created. It appears that is the case here. Since objFolder is null when you get to the Copy() line, the method fails. You need to research why the folder could not be created--most likely, it is a permissions issue.
0
 
LVL 17

Expert Comment

by:OriNetworks
ID: 24332526
Does it give a line number of the error and what are the two arguments you are passing to the script?
0
 

Author Comment

by:AlexInAustralia
ID: 24333079
The following were tried on another PC:
CopyFile C:\MyFolder\aaa.txt C:\
CopyFile C:\MyFolder\aaa.txt \\135.145.35.183\c$
CopyFile C:\MyFolder\aaa.txt \\135.145.35.183\MySharedDirectory

All 3 lines worked on my PC.
On the other PC, the first line worked, but the other two gave the error.
Based on my new script, the error reported was a WSH on line 27, char 3, error 'Object Required', code 800A01A8, source 'Microsoft VB Script runtime error'.

Copying the file manually to that box worked fine.

Here is my complete new script:
' This script copies a file to a destination folder

' Author: (enter author here)
' (add additional comments here)


'To use it, pass the following parameters (in the following order):
' 1: the path and name to the file that will be copied (eg, c:\temp\SomeFile.txt)
' 2: the destination path (eg, c:\temp\ or \\135.145.35.183\c$\)

Option Explicit

Dim oArgs, fileToCopy, destination, objShell, objFolder

Set oArgs = WScript.Arguments.Unnamed

fileToCopy = oArgs.Item(0)
destination = oArgs.Item(1)

Const FOF_YESTOALL = &H10&

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(destination)

If (Not objShell Is Nothing) Then
      If (objFolder Is Nothing) Then
            WScript.Echo "Could not find destination folder " + objFolder.Title
      Else
            objFolder.CopyHere fileToCopy, FOF_YESTOALL
      End If
Else
      WScript.Echo "Could not create the shell application object"
End If

Set objFolder = Nothing
Set objShell = Nothing
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:AlexInAustralia
ID: 24333115
Oops.
I've now changed the line:
WScript.Echo "Could not find destination folder " + objFolder.Title
to:
WScript.Echo "Could not find destination folder"

And now it doesn't throw the WSH error any more.
But the question now becomes, why is it giving me "Could not find destination folder" on the other PC.

As I said, I can copy the file manually across to that box (on both PCs).
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24335933
Does the logged in user who is running the script have admin access on the machine @ 135.145.35.183? AFAIK, only admins are allowed to access admin shares (C$).
0
 

Author Closing Comment

by:AlexInAustralia
ID: 31579288
You've answered my initial question. And now my code displays the relevant error handling if it can't do the copy. The reason why it's not copying is a different issue all together which the system administrator will have to look into.
0
 

Author Comment

by:AlexInAustralia
ID: 24350594
You've answered my initial question. And now my code displays the relevant error handling if it can't do the copy. The reason why it's not copying is a different issue all together which the system/network administrator will have to look into.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBSScript Error IP Array 6 27
is there a way to grey-out all the controls within a windows screen in VBA 18 28
Clear Filter 8 59
get the ALL CAPITAL words from a cell 4 19
Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

856 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