Hi

The following script works OK when run interactively from the command
line, but when run as a scheduled task - via SQL Enterprise Manager in
preperation for another SQL task - returns the error:-

The process could not be created for step 2 of job
0x0882C8212587254BB055CCD056C84FD0 (reason: %1 is not a valid Win32
application). The step failed.

The VB script is as follows, and it fails before the copy operation:-
dim yr
dim mth
dim day
dim objFile
dim objFso
dim objFolder
dim objFileLoop

yr = cstr(4)
mth =cstr(2)
day = cstr(2)
file = cstr(51)

yr = datepart("yyyy",Now)
mth = datepart("m",Now)
day = datepart("d",now)

if mth = "1" then
mth = "01"
end if

if mth = "2" then
mth = "02"
end if

if mth = "3" then
mth = "03"
end if

if mth = "4" then
mth = "04"
end if

if mth = "5" then
mth = "05"
end if

if mth = "6" then
mth = "06"
end if

if mth = "7" then
mth = "07"
end if

if mth = "8" then
mth = "08"
end if

if mth = "9" then
mth = "09"
end if

if day = "1" then
day = "01"
end if

if day = "2" then
day = "02"
end if

if day = "3" then
day = "03"
end if

if day = "4" then
day = "04"
end if

if day = "5" then
day = "05"
end if

if day = "6" then
day = "06"
end if

if day = "7" then
day = "07"
end if

if day = "8" then
day = "08"
end if

if day = "9" then
day = "09"
end if


set objFso = createobject("scripting.FileSystemObject")

objFile = "AGRESSODB01_agresso_Full_" & yr & mth & day & "2200 (1 of
1).safe"

if objFso.FileExists(objFile) then
objFso.CopyFile objFile, "\\agressodr\e$\sqlsafe
\AGRESSODB01_Live_Full.safe"
end if

set objFso = Nothing

set objFso = createobject("scripting.FileSystemObject")
set objFolder = objFso.GetFolder("J:\SqlSafe")

for each objFileLoop in objFolder.Files

if datediff("d",objFileLoop.DateCreated,Now) > 7 then
objFile = objFileLoop.Name

if objFileLoop.Name <> "CopyFile.vbs" then
objFso.DeleteFile(objFile)
end if

end if

next

Any assistance appreciated

Re: Newbie - Error in script by McKirahan

McKirahan
Tue Dec 04 02:46:53 PST 2007

"Gary" <gary.cobden@nhs.net> wrote in message
news:c00d98e6-df44-4a80-9bdb-a5d007ab8c7c@w34g2000hsg.googlegroups.com...
> Hi
>
> The following script works OK when run interactively from the command
> line, but when run as a scheduled task - via SQL Enterprise Manager in
> preperation for another SQL task - returns the error:-
>
> The process could not be created for step 2 of job
> 0x0882C8212587254BB055CCD056C84FD0 (reason: %1 is not a valid Win32
> application). The step failed.

[snip]

First off, remove the following 85 lines:

dim yr
dim mth
dim day

yr = cstr(4)
mth =cstr(2)
day = cstr(2)

yr = datepart("yyyy",Now)
mth = datepart("m",Now)
day = datepart("d",now)

if mth = "1" then
mth = "01"
end if

if mth = "2" then
mth = "02"
end if

if mth = "3" then
mth = "03"
end if

if mth = "4" then
mth = "04"
end if

if mth = "5" then
mth = "05"
end if

if mth = "6" then
mth = "06"
end if

if mth = "7" then
mth = "07"
end if

if mth = "8" then
mth = "08"
end if

if mth = "9" then
mth = "09"
end if

if day = "1" then
day = "01"
end if

if day = "2" then
day = "02"
end if

if day = "3" then
day = "03"
end if

if day = "4" then
day = "04"
end if

if day = "5" then
day = "05"
end if

if day = "6" then
day = "06"
end if

if day = "7" then
day = "07"
end if

if day = "8" then
day = "08"
end if

if day = "9" then
day = "09"
end if

objFile = "AGRESSODB01_agresso_Full_" & yr & mth & day & "2200 (1 of
1).safe"

and replace them with these 5 lines

Dim strYMD
strYMD = DatePart("yyyy",Now) _
& Right(100+DatePart("m",Now),2) _
& Right(100+DatePart("d",Now),2)

objFile = "AGRESSODB01_agresso_Full_" & strYMD & "2200 (1 of 1).safe"


Then remove these unnecessary lines:

set objFso = Nothing
set objFso = createobject("scripting.FileSystemObject")


Also, you may want to change
dim objFile
to
dim strFile
as it's a string not an object;
yoi could also change it to a "Const".


As to why it's failing -- I suspect the mapped drive is invalid:
"\\agressodr\e$\sqlsafe\AGRESSODB01_Live_Full.safe"



Re: Newbie - Error in script by Dr

Dr
Tue Dec 04 14:05:46 PST 2007

In microsoft.public.scripting.vbscript message <BrednSLe7N6ArcjanZ2dnUVZ
_uiknZ2d@comcast.com>, Tue, 4 Dec 2007 04:47:41, McKirahan
<News@McKirahan.com> posted:
>"Gary" <gary.cobden@nhs.net> wrote in message
>news:c00d98e6-df44-4a80-9bdb-a5d007ab8c7c@w34g2000hsg.googlegroups.com...

>First off, remove the following 85 lines:

>and replace them with these 5 lines
>
>Dim strYMD
> strYMD = DatePart("yyyy",Now) _
> & Right(100+DatePart("m",Now),2) _
> & Right(100+DatePart("d",Now),2)
>objFile = "AGRESSODB01_agresso_Full_" & strYMD & "2200 (1 of 1).safe"

Then remove those five inefficient lines and replace them with

dim YMD, Tmp
Tmp = Now
YMD = Year(Tmp)*1e4 + Month(Tmp)*1e2 + Day(Tmp)
objFile = "AGRESSODB01_agresso_Full_" & YMD & "2200 (1 of 1).safe"

after correcting any typos.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.