Solved

window.navigate command getting "Access Denied" error

Posted on 2004-10-06
28
951 Views
Last Modified: 2008-01-09
For some reason I cant get the window to navigate to the new address. The address is a local path to a file in the temp directory. Code is below. The function main simply uses a recordset to create a new html page in the users TEMP directory and the window.navigate is meant to just open this page but no go! I'm sure it is something simple but, any ideas?

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<script language=vbscript>
'**Start Encode**
Set fso=CreateObject("Scripting.FileSystemObject")
Set dbCon = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
pUBLIC STRdbcON
Public fsofile
Set wshell=CreateObject("WScript.Shell")
Public PCName
Public Curdir

pcname=Wshell.ExpandEnvironmentStrings("%USERNAME%")
curDir=WShell.ExpandEnvironmentStrings("%Temp%")

Function sesbyDate()
strDBCon="Provider=SQLOLEDB.1;User ID=dbUser;Initial Catalog=Templates_Synch;Data Source=foneent"
dbCon.Errors.Clear
dbCon.Open strDBCon

Main()
window.navigate CurDir & "\" & pcname & "Report.html"

End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Dom
0
Comment
Question by:domj
  • 9
  • 5
  • 5
  • +4
28 Comments
 
LVL 36

Accepted Solution

by:
Zyloch earned 250 total points
Comment Utility
Hi domj,

window.navigate is IE only (not really matter since you're using VBScript. I wonder. Does window.location.href=CurDir & "\" & pcname & "Report.html" work?

Regards,
Zyloch
0
 
LVL 3

Author Comment

by:domj
Comment Utility
nope, same message "permission denied"

Dom
0
 
LVL 36

Expert Comment

by:Zyloch
Comment Utility
So you're using something like:

file://c:/WINDOWS/Temp/
0
 
LVL 3

Author Comment

by:domj
Comment Utility
The file is being created in the users temp folder. Earlier in the script the curDir=WShell.ExpandEnvironmentStrings("%Temp%") line gets the current users temp fodler using the %TEMP% variable. Then I create a new text file in this directory and write html to it, dependent on the results of the recordset that is opened in the main() function. The file is created properly and i can manually navigate to it but I want the browser to jump to it, once it is finished creating it so that it is seamless for the end user.

Dom
0
 
LVL 36

Expert Comment

by:Zyloch
Comment Utility
Try this:

window.navigate "file://" & CurDir & "\" & pcname & "Report.html"
0
 
LVL 3

Author Comment

by:domj
Comment Utility
nope, same again. For some reason its not letting me change the access in code. weird. its got to have to do with security because when i run it locally (ie, when the page is not published) it runs fine but once it is run from a web server it fails.

Dom
0
 
LVL 36

Expert Comment

by:Zyloch
Comment Utility
Oh, you're running it from a webserver. Yes, it is the security. I don't believe you can get past that... Otherwise, a person could just change files on your computer without you knowing
0
 
LVL 3

Author Comment

by:domj
Comment Utility
yeh but it is doing the file stuff fine. the file is creating and everything without any problems. to facilitate this the end user needs to add the intranet site to trusted sites and heavily reduce the activex security for these sites but it works fine once these changes have been done. The stuff that should be really secure (ie. actually changing files and reading environment variables) is working fine once the appropriate changes have been made. The bit that doesnt work is simply navigating to view a html file on the local machine. all it is is trying to change the address of the current window which I thought would be the easiest thing in the world to do. its just the equivalent of clicking on a link but it doesnt work. (you can tell how little web development i have done!)

dom
0
 
LVL 36

Expert Comment

by:Zyloch
Comment Utility
Creating the file is totally different from accessing it. I'm not immensely familiar with ASP/VBScript. Possibly there's a way, but it's beyond my knowledge.
0
 
LVL 3

Author Comment

by:domj
Comment Utility
Thanks anyway Zyloch. appreciate your help. anybody else? Have increased points value to 500.

Dom
0
 
LVL 3

Expert Comment

by:sgayatri
Comment Utility
Just try something like this -- using javascript
<input type=button value=click Onclick=window.open("../../yourfile")>
0
 
LVL 3

Author Comment

by:domj
Comment Utility
sgayatri, thanks for the input but if i was going to do that i may as well just post a link. i can find ways around it but i am just intrigued as to why i am having this problem. for example, i can use the wshell.run command to shell the path of the file and open in a new browser. therefore i could shell any command including hostile script. i can't understand why it would block me then from doing something as simple as navigating the current window to a new page.

dom
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 3

Expert Comment

by:thunder_moose
Comment Utility
Hey there,

This might sound silly, but do you close the file? It could be that the file is still open for writing or for append and then you try and navigate to it while it's still in use.

Cheers,
TM
0
 
LVL 2

Expert Comment

by:Adesso21
Comment Utility
IE had some issues with cross domain security and they solved it by NOT ALLOWING it at all. This means that if you want to use a frame to load a diffrent domain from the current one it just tells you Access Denied..

The window.open option could solve your problem but if not .. try using a shell script to execute a new instance of IE with the file location of the current users file. Also remember that the shell command has to have local admin rights to do this or you would be back to the same problem...

Here is a alternet solution..

Instead of writing the file to the users PC.. let them download the thing... this way they can access it at there own will... To get that right send the browser a mall-formed header so it doesn't display the HTML file but wants to download it.. the rest is then up to the user..

Another idea is to write the file to a common file server and then redirect the user to that file server.

Cross doamin access is a bit of a mission...

Good Luck
Adesso21
0
 
LVL 3

Expert Comment

by:sgayatri
Comment Utility
domj,
I am not very sure about why you get that error. May be due to the reasons explained by Adesso21.
I could not understand much of what he is trying to tell.
I happened to see ur question in VB section and out of curiosity came here and posted my opinion.
That's all.
Adesso21,
If it is 'cross domain issue' , then enabling the security option 'Access data sources across domains'
in internet options , should solve the problem... Am I right?
0
 
LVL 3

Author Comment

by:domj
Comment Utility
Hi all,

Here I was thinking that it would be an easy fix! thunder_moose, yes the file is closed before I try to access it but I have been caught out with this before (as I am suremost people have)!

Adesso21, firstly, the page is published and accessed all on a common domain to which I am a Domain Admin and therefore I can't see where there should be a permissions problem. The window.open command doesnt work for me either (same issue, "Access Denied"). The shell command does work fine and I could use this method but then the user can't use the back button to get back to the first page and also it leaves the old page up and if I use a window.close to try and ditch it it comes up with the "Are you sure you want to close it" prompt. I am not sure what the suggestion regarding the downloading thing is. The reason that I am using a temp folder on the local PC is that the page is to display a report for a FTP synchronisation tool that I have written. The logs get pulled up into a SQL 2000 db and then I wanted a nice easily distributable reporting option to allow our help desk to access custom reports. The page allows the user to click on a number of links to run reports that it then prompts for user input and uses this info and embedded vb code to query the SQL db. It creates a recordset and then goes through each record, writing HTML containing this information into a new text document and then displays this document (or is meant to at least). The reason that this is done client side is because I dont have the skills to look at ASP or any server side solution.

All that said, the entire thing works great and apart from some early problems with security and the activex objects (like the fso and the environment variable access) and this one hiccup, the file gets created fine and you can manually go to the page and it displays like a charm. Its just that for some reason, IE locks down all access from code to anything that will get the current page to navigate away. I could redirect to a common file server but I dont know if that would even work. It might be worth a try and if someone was able to say "oh yeah, you cant do that because..." then i could look at another option but it just seems like the most trivial thing to be able to do from a webpage.

Thanks all for you input... Am still interested to hear if anyone has any further insight or common experience with a similar issue.

Dom
0
 
LVL 2

Expert Comment

by:Adesso21
Comment Utility
sgayatri

I am not sure that changing the setting in IE will do anything.. Last I read somthing about Microsoft wanting you to create some kind of Trusted certificate between the two domains and then implementing some funny browser security check .. I gave up..

As for the real question DomJ.. You are going to have to get your hand dirty with some kind of server side scripting.. The way you are going now is almost not possible. I get what you are trying to do, and let me tell you.. it's a breeze in server side scripting..

I like using PHP but ASP should be fine.. this is not rocket sience ... reporting.. but the way that you are trying to do it.. could be..

I hope you get a solution..

Regards

Adesso21
0
 
LVL 2

Expert Comment

by:JuergenHartl
Comment Utility
A suggestion: Why don't you create the file on the server and then link to that file vis HTTP ?
The main page would hve to be a ASP ot CGI page
0
 
LVL 4

Expert Comment

by:Zvika
Comment Utility
Excuse me, but shouldn't it be:
window.navigate CurDir & "/" & pcname & "/" & "Report.html"
or
window.navigate CurDir & "\" & pcname & "\" & "Report.html"

rather than:
window.navigate CurDir & "\" & pcname & "Report.html"

What I would suggest you to do first is print out (either in MsgBox, or better just to dynamically write it somewhere in the doc) the value of [CurDir & "\" & pcname & "Report.html"] and then just copy it and paste it to the address field in the browser.
also, put this output here, maybe we can see something in it....

Good luck
Zvika
0
 
LVL 4

Expert Comment

by:Zvika
Comment Utility
I'm quite sure that all you're missing is the extra "\" between pcname & "Report.html"...

Lemme know if that it...

0
 
LVL 3

Author Comment

by:domj
Comment Utility
No, that syntax is correct. The file path is "C:\Documents and settings\DominicJ\Local Settings\Temp\DominicJReport.html". I could copy and paste the value. Seems like a very poor way of coding it and open to problems. What if the user copies something in the meanwhile? How do I give focus to the address bar?

Dom
0
 
LVL 4

Expert Comment

by:Zvika
Comment Utility
domj

I didn't mean you to use this as workaround. just as a debugging way to see that the path is built ok and that the file is actually there.
anyway, it looks wierd.
one more test for you. write a hard-coded file path, to a file you KNOW is already there. I mean, make a test. put a "test.html" file in c:\, and write the path "c:\test.html" hard coded in your function. see if that also fails.

supply the feedback and we'll see how we take i forward...

Zvika
0
 
LVL 3

Author Comment

by:domj
Comment Utility
Oh, OK. Yeh the path works fine. I have tried replacing the path with another. For some reason IE is blocking any attempt that I make to access the window address object.

Dom
0
 
LVL 4

Assisted Solution

by:Zvika
Zvika earned 250 total points
Comment Utility
well, 3 more suggestios, long shots in the dark...
1. Maybe the problem is in your target page, and not in the way to it. try to navigate to an empty html page, or a simple one (no frames, no dhtml code).
2. a phenomena i once have - what is the name of the site from which you try to navigate? if the site name contains invaid chars, some IE versions consider the site as "unsafe" and won't redirect.
[another test for option 2 and similar is to put your first page, the one that calls the navigation, on the same local machine.]
3. are you sure the permission denied is on the Navigate function? maybe it something else in your code? (maybe something in the Main function?)

I used the following file:
<html>
<head>
<title>bla</title>
<script language=vbscript>
Set wshell=CreateObject("WScript.Shell")

pcname=Wshell.ExpandEnvironmentStrings("%USERNAME%")
curDir=WShell.ExpandEnvironmentStrings("%Temp%")

Function bla()
      msgBox(CurDir & "\" & pcname & "Report.html")
      window.navigate CurDir & "\" & pcname & "Report.html"
End Function
</script>
</head>
<body onload = "bla()">
</body>
</html>

and it works fine.

last possibility is that something is wrong in your permissions either in the browser properties (do remeber that your code generates ActiveX components that some users don't allow) or the folder properties.
0
 
LVL 4

Expert Comment

by:Zvika
Comment Utility
well, domj sisn't say if it helped him, so I can't say "Points to me".
I think that if no comment to him, it will be fair to split them among those who gave some effort.... what say you?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now