Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please help ActiveX component can't create object: 'Scripting.FileSyst 1

Status
Not open for further replies.

stewh77

IS-IT--Management
Aug 3, 2005
10
GB
Hi,

I have the following code in one of my Intranet pages. It is used to allow workers to be able to see customer signatures through a web page. My problem is that the line Set fso = CreateObject("Scripting.FileSystemObject") keeps resulting in the error ActiveX component can't create object: 'Scripting.FileSystemObject'

I can't understand it though as before this line I have a createobject for the database connection and this works fine. I am not trying to write to a file so I don't think permissions are a problem either. Please can anybody help though as it is making me mad now.

<SCRIPT LANGUAGE=VBScript>

sub ValidKeyPress()
if window.event.keycode < 48 or window.event.keycode > 57 then
window.event.returnvalue = false
msgbox "The value must be numeric",,"Shepshed"
end if
end sub

sub Search()

if frmSearch.txtCriteria.value = "" then
msgbox "Please enter a criteria before searching.",,""
frmSearch.txtCriteria.focus
exit sub
end if

if frmSearch.R1(2).checked = true AND len(frmSearch.txtCriteria.value) <> 9 then
msgbox "Please enter a correct Mantis account number.",,"Shepshed"
frmSearch.txtCriteria.focus
exit sub
end if

dim dbpath
dim ipath
dim conn1
dim rs1
dim result
dim fso

dbpath = "db1.mdb"

set conn1 = CreateObject("ADODB.Connection")

conn1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath

conn1.Open

if frmSearch.R1(0).checked = true then
set rs1 = conn1.Execute("SELECT * FROM Customers WHERE NFMLCustomerNo=" & FrmSearch.txtCriteria.value)
end if

if frmSearch.R1(1).checked = true then
set rs1 = conn1.Execute("SELECT * FROM Customers WHERE MantisCustomerNo=" & FrmSearch.txtCriteria.value)
end if

if frmSearch.R1(2).checked = true then
set rs1 = conn1.Execute("SELECT * FROM Customers WHERE MantisCustomerNo=" & FrmSearch.txtCriteria.value)
end if



if rs1.eof = false then
result = rs1("MantisCustomerNo")
'ipath = "file:///X:\Bmp\Bmp\Signature\" & result & ".jpg"
ipath = "file://Ssbs/2001/Bmp/Signature/" & result & ".jpg"
set fso = CreateObject("Scripting.FileSystemObject")
if fso.FileExists(ipath) then
NewTableHTML = "<img border=" +chr(34)+ "0" +chr(34)+ " src="+chr(34)+ ipath +chr(34)+ " width=" +chr(34)+ "278" +chr(34)+ " height=" +chr(34)+ "107" +chr(34)+">"
document.all.myTableLocation.innerHTML=NewTableHTML
else
NewTableHTML = "No Signature file found for this customer."
document.all.myTableLocation.innerHTML=NewTableHTML
end if
end if

end sub

sub setclearall
document.all.myTableLocation.innerHTML=""
frmSearch.txtCriteria.value = ""
frmSearch.R1(0).checked = true
end sub

Sub SubmitForm
frmSearch.submit
End Sub

</SCRIPT>
 
Did you try it this way yet?

Server.CreateObject()
 
Hi Sheco,

Yes, I did try it with the Server.CreateObject syntax but got the error Object Required: 'Server' because I am not running the code in ASP but through VBSCRIPT on the client computer.

Thanks
 
that errors makes me think that it is due to either permissions problem or object not registered properly...

-DNG
 
Really DotNetGnat?

Do you know how I can find that out/prove it? Or even better if it is this, how to correct it?

Thanks
 
so if you ran a little .vbs file like the one below it would raise the same error?
Code:
set fso = CreateObject("Scripting.FileSystemObject")
set fso = nothing
msgbox "done"
 
Hi Sheco,

I did what you said, created a vbs file and entered the code you mentioned and everything worked fine so I guess the scripting engine is fine also. I am really puzzled with this one!
 
Maybe it is a typo? The when I first typed it I did: FileSystemObect

Also sometimes the line number is off from what you expect so perhaps some other line is the cause of this error.
 
can you put some response.write statements in your code and tell us what line is causing the error...

-DNG
 
Hi,

Sheco - I thought it was possibly a typo error too at first and so copy and pasted your to be sure but the same error occured. I never thought that may be another line could be causing the problem. I am wondering if for some reason because I call the CreateObject function to create the database connection it is causing a problem later on when I try to use it again for the file. I'll have a look in to this now just in case.

DotNetGnat - I see what your saying but unfortunately becasue I am not using ASP I don't think it is possible to use these staements.

Thanks for both your input though, keep any ideas coming! :)

 
Maybe you could use MsgBox() to help debug the same way you would use Response.Write to debug your ASP ?
 
Have you simplified your code to test?

Write a page that does nothing other than create the object and test for the existance of a file and run it.
Then try running that file from your desktop directly instead of from the server and see what happens.

Also this line
ipath = "file://Ssbs/2001/Bmp/Signature/" & result & ".jpg"
You have no drive specification so where could it be pointing? If this is supposed to be pointing to a file on the local PC or across a path the local PC has access to then it should have a drive specification or servername\path.
file://C:\mypath\myfile.jpg
or even just
C:\mypath\myfile.jpg
or
\\myserver\myfolder\myfile.jpg

The first thing is to start with the most basic of code so you can tell if it is a security issue or if something in the code is interfering.
This code works for me as a test.
Code:
<html>
<head>
<title>Untitled</title>
<SCRIPT LANGUAGE=VBScript>
  ipath = "C:\desktop.txt"
  set fso = CreateObject("Scripting.FileSystemObject")
  if fso.FileExists(ipath) then
    document.write "File exists"
  else
    document.write "File does NOT exist"
  End If
</script>
</head>
<body>
</body>
</html>

If this works for you then you know you have a problem in your code. If it fails then it is security.
I suspect that using CreateObject to create an ADODB connection may be less restricted than directly accessing the file system. Do you get ActiveX warnings when it establishes the DB connection? Do you get them when it attempts to establish the FSO object?



Stamp out, eliminate and abolish redundancy!
 
Hi TheNiteOwl,

I did what you suggested. Put your code into a simple htm file and ran it from my desktop. It worked fine - no problems. I then copied the file into my directory on the local computer and I got the same ActiveX error message.

I'm not sure why it is doing this. I have XP sp2 but it doesn't display a blocked message for the activex control.

I'm lost on this.
 
oh - I don't get activex warnings when I create the db connection. Only the FSO.
 
So you get the ActiveX warning that you have to answer Yes to to continue and then you get the cannot create object error?

I would think that if it were browser security you would not get the ActiveX warning at all if it were disallowed in your settings. Does it give you the Yes No options?

Can you try from another computer likely to have unmodified browser settings to see if the version on the web server gives the same error there?


Stamp out, eliminate and abolish redundancy!
 
Sorry theniteowl I misunderstoon you the last time. No I don't get any prompt asking me if it is ok to run the activex control and giving me the options yes / no to continue. It just goes straight to the error message.

I will see if I can do this from my home PC later.
 
It sounds as if your browser is set to higher security levels preventing the activex control from accessing the local file system. Since it does not execute you do not get the prompt but your code continues anyway and tries using the object that did not get created...
Probably just a matter of lowering your browser security setting. I believe it is the option marked "Initialize and script ActiveX controls not marked as safe"
This is set to Prompt in my browser.


Stamp out, eliminate and abolish redundancy!
 
theniteowl - you are an aboslute star, it works fine now. Thank you very much. I can't believe it is the web browser settings though. Now I am going to have to make sure each PC is set the same! Nightmare!!:(

Solve one problem and fine another.

Anyway thanks a lot for that and to everyone else for trying to help also.

Much appreciated.
 
Glad it worked.
The default settings for IE should prompt about the ActiveX control and allow them to select Yes or No to run it.
Unless they have changed their defaults to a higher level things should work unless the clients panic and click No.

There is no way around the ActiveX alert save for changing everyone's settings to a lower security level or packaging and publishing an ActiveX control so it becomes trusted.

Also, your code will be IE only as it is using ActiveX.
If you are working in an intranet like me it generally is not a big issue.


Stamp out, eliminate and abolish redundancy!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top