Solved

window.navigate command getting "Access Denied" error

Posted on 2004-10-06
28
967 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
ID: 12244799
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
ID: 12244811
nope, same message "permission denied"

Dom
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12244821
So you're using something like:

file://c:/WINDOWS/Temp/
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:domj
ID: 12244840
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
ID: 12244869
Try this:

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

Author Comment

by:domj
ID: 12244898
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
ID: 12244913
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
ID: 12244945
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
ID: 12245055
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
ID: 12245066
Thanks anyway Zyloch. appreciate your help. anybody else? Have increased points value to 500.

Dom
0
 
LVL 3

Expert Comment

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

Author Comment

by:domj
ID: 12245948
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
 
LVL 3

Expert Comment

by:thunder_moose
ID: 12246246
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
ID: 12246676
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
ID: 12246828
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
ID: 12246908
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
ID: 12265665
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
ID: 12268629
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
ID: 12275508
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
ID: 12275610
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
ID: 12280936
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
ID: 12281198
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
ID: 12282736
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
ID: 12284638
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
ID: 12482501
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
replace quotes with UTF-8 character 38 112
AngularJS directive issue 6 80
use of cookies and regulations 1 103
Optimum versions of Selenium Webdriver with Python On Windows 7 1 174
Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

726 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