Solved

Invoke the Windows Explorer from a web page

Posted on 1998-06-26
24
553 Views
Last Modified: 2013-12-25
For an Intranet application, I need to be able to
invoke the Windows Explorer from a web page.

Requirements:
o  Work for Netscape 4+ and IE 4+.
   Version 3 browsers a bonus.
o  Work for Windows NT 4+.
   Windows 95/98 or NT 3.51 a bonus).
o  Need to be able to pass command line arguments
   to specify a directory or file to select.
   (e.g., explorer /select,c:\winnt\system32\calc.exe ).
o  Click a link or button on a web page to get the
   explorer.  The web page should not redraw.
o  The web server is IIS.
o  Java or Javascript allowed.
o  No prior configuration on machine used to browse
   and invoke the Windows Explorer.
o  The security of the browsing machine is not
   totally compromised.
o  The Windows Explorer has no special privileges.
   It behaves just as if the user browsing had
   started the Windows Explorer and pointed it toward
   the specified directory.

How do I set this up?
0
Comment
Question by:bjherbison
  • 8
  • 6
  • 5
  • +3
24 Comments
 
LVL 2

Expert Comment

by:tpryor
ID: 1858429
use the tag...
<INPUT NAME="upload" TYPE="file">
this will bring it up if the user hits the button.

You will need Netscape 2.0 or higher, or some other browser that supports HTML file uploads. (like IE)

go to "http://www.cabletron.com/support/upload/"
for an example, hit the browse button

GL,
t
0
 
LVL 6

Expert Comment

by:alamo
ID: 1858430
tpryor, the standard file open dialog isn't really the same as Explorer, and you can't control what directory it opens to.

The easiest way to do this, for Internet Explorer, is to make the link an actual .lnk file just like you have as a desktop shortcut. When the user clicks on it in IE, they may get an "open or save" dialog (for security reasons) then when they select "open" explorer will run, opened to the correct directory.

Netscape is a little more troublesome - IE has the association for a .lnk file built into it, but Netscape doesn't. This is where your "no prior configuration" requirement eliminates a lot of posssibilities. What you need to do is to associate a file type with Explorer - not sure if .lnk would work or if you would need to create a special one, I don't think Explorer has any built in associations that would work from Netscape.

I am pretty pessimistic you can do this with all your restrictions completely intact - certainly not as a single solution for both IE and Netscape. A custom ActiveX control could do it but requires downloading and is IE-only. A signed Java applet might be able to do it, I'm not sure if one of the abilities signing an applet give it is the ability to run programs locally but it's a possibility, though that would be Netscape-only. If you relax your requirements such that a user must for Netscape download and run a little program once which makes a Netscape file association to Explorer like it works in IE, then that would probably be the easiest solution overall.

Even though I gave the IE-solution, since I don't have a real Netscape solution I'll hold off posting this as an answer and will look into the Netscape side of things a little more. Let me know if the above sounds promising, and good luck.
0
 
LVL 2

Expert Comment

by:tpryor
ID: 1858431
thats true, but it does do everything else with no prior configuration, got version 3 support in both browsers, 2 for netscape.

If all he needed was the standard open/save dialog then this may be an option.

Knowing what the goal was would be useful too.

simple is best ; >

GL,
t
0
 
LVL 2

Expert Comment

by:ndnet
ID: 1858432
This isn't too hard in IE4 and 3.
It will probably work in NS4.

Go to builder.com
Go down to cool tools and click on "Window Builder'
Have "C:" without the quotes be the address
Get the code.
It should do it.
0
 
LVL 6

Expert Comment

by:alamo
ID: 1858433
ndnet, that's a pop-up directory listing, but it's not Explorer.

Although for Netscape it is probably the best you can do, it's definitely not the best you can do for Internet Explorer.

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1858434
Netscape 4 can do it with acceptance from the user - I have the script, bj,  if you want it
0
 

Author Comment

by:bjherbison
ID: 1858435
Wow, I never expected such activity.  That's the last time I'll post a question on Friday when I plan on taking the weekend off.
I need to go and do some urgent work, then I'll come back and
study these comments.
0
 
LVL 2

Expert Comment

by:Jagar
ID: 1858436
Just as a little side note.  If you could do an all IE4 solution it would be extremely simple.  All you would have to do is redirect the browser's URL to "C:\" or whatever path was necessary.
0
 

Author Comment

by:bjherbison
ID: 1858437
Thank you all for your thoughts on my problem.

ndnet:
Your proposed answer doesn't work for me with Netscape 4,
I get `JavaScript Error: illegal URL method 'c:' ' for a local
file and a different error for an UNC.
It's also not acceptable for IE -- as someone else noted
it isn't an explorer view.  If the explorer view isn't
possible, your suggestion would appear better, but I'd prefer
to have it come up in details view rather than icon view.

tpryor:
The upload was a good suggestion, but it doesn't hit the mark.
The biggest problem is the inability to specify a starting
directory, with a minor problem being that I really just want
to have a small image button to press rather than a text field
and a browse button.

Your comment about the goal was on the mark.  The purpose is
for system management -- a tool that looks for problems in the
file system (binaries in a source directory, a new large file
appears somewhere).  The results are viewed through a browser
and I want the admin to be investigate or fix the problem
easily and giving them an explorer window pointing to the
problem file or directory is one tool to provide.

Thinking about the goal led me to realize that I left off
some requirements:
o  The solution needs to work with UNCs.
o  The directory isn't constant, but comes from a database.

alamo:
The .lnk files seem like a possible aproach, but I have some
questions:
1) How could it be made to work with Netscape.  Netscape 4 pulls
over the file, saves it with the name XYZZY.com (instead of
lnk).  When I renamed the file to .lnk I was ablt to execute it.
2) How would I generate the .lnk files on the fly? (Due to
my previously unstated requirement?)  If I knew the format of
the .lnk file I could probably create an ISAPI .dll to take
the record number, look the details up in the database, and build
and return the correct contents of the .lnk file, but that sounds
fragile.

As to your comment about not being able to find a solution for
both IE and Netscape, two solutions would be workable since I
should be able to detect the browser and send the appropriate
solution.

You mentioned a signed Java applet.  Does anyone know if that
could be made to work?  Were would I find out about that
approach?

mplungjan:

Yes, I would like your script.  Can the script also work with IE?

Jagar:

Your approach is basically the proposed answer, and that doesn't
fit my needs.
0
 
LVL 2

Expert Comment

by:tpryor
ID: 1858438
ok, that helps alot.
So it appears that you need some webbased file/directory management system.  If thats the case I would suggest CGI.
That way you could support any browser.  The cgi would read through the files/db identify problems and generate a report. It could also allow web based modification of the file.

If that is the case I can recommend a free script that does that.
You can customize it to suit your needs.

SiteMgr - a web site manager  Free This CGI script will perform
 most of the file operations required for web site maintenance. You can use it to copy, move, edit, delete and upload files, and
 to create, move and delete directories. Installation can be done by the user or at the system level.

UNIX:
http://www.halcyon.com/sanford/cgi/sitemgr/

NT, IIS 3.0:
http://www.halcyon.com/sanford/cgi/sitemgr/ports.html

GL
t
0
 
LVL 6

Expert Comment

by:alamo
ID: 1858439
>1) How could it be made to work with Netscape.  Netscape 4 pulls
>  over the file, saves it with the name XYZZY.com (instead of
> lnk).  When I renamed the file to .lnk I was able to execute it.

I seem to recall a way with HTTP headers to tell Netscape what filename to use, I can find the details if you want to do this. You'd need to call a CGI to generate a temporary .lnk file and return it to the browser with the right headers.

>2) How would I generate the .lnk files on the fly? (Due to
> my previously unstated requirement?)  If I knew the format of
> the .lnk file I could probably create an ISAPI .dll to take
> the record number, look the details up in the database, and build
>and return the correct contents of the .lnk file, but that sounds fragile.

The CGI I mentioned above could do this and create a temporary .lnk file, and then feed the file back to the user. Shortcuts are implemented through an OLE interface called IShellLink. MS has a Knowledge Base article about creating links at    http://support.microsoft.com/support/kb/articles/Q179/9/04.asp

I can see why you'd want a real Explorer inteface for this sort of thing. The .lnk solution is the cleanest but a lot of work to implement... it all depends on how bulletproof you want the app and how it will be used. You could even simply print the desired Explorer command to the browser window in such a way that the user could copy the string to the clipboard and then use Start/Run to bring up the window. Probably not nice enough for your purposes but you'd have the exact interface you want. Just a thought.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1858440
I have NS3,4 and MSIE 3 covered - I am looking for the neatest MSIE4 solution

Michel
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:bjherbison
ID: 1858441
tpryor:

Before you get annoyed, see
http://www.experts-exchange.com/Q.10060781

Your solution is an approach I hadn't thought of.  It has some drawbacks:  1) we run on IIS 4, and the current port is for IIS 3. (Again I was guilty of not providing enough detail.)  2) The requirements I was given said Windows Explorer, and it is an interface people are used to.  3) We plan on selling this product so we would need to purchase the rights to the code.

It is possible to overcome these drawbacks, but I would like to keep this question open for other solutions.  Now go see if you can answer Q.10060781.

alamo:
Yes, I would like to hear more details on telling Netscape the file extension to use, and on the CGI script.

mplungjan:
I would like to see your script as well.

Anyone:
Can the signed Java applet approach mentioned above work?
0
 

Author Comment

by:bjherbison
ID: 1858442
tpryor:

Before you get annoyed, see
http://www.experts-exchange.com/Q.10060781

Your solution is an approach I hadn't thought of.  It has some drawbacks:  1) we run on IIS 4, and the current port is for IIS 3. (Again I was guilty of not providing enough detail.)  2) The requirements I was given said Windows Explorer, and it is an interface people are used to.  3) We plan on selling this product so we would need to purchase the rights to the code.

It is possible to overcome these drawbacks, but I would like to keep this question open for other solutions.  Now go see if you can answer Q.10060781.

alamo:
Yes, I would like to hear more details on telling Netscape the file extension to use, and on the CGI script.

mplungjan:
I would like to see your script as well.

Anyone:
Can the signed Java applet approach mentioned above work?
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 200 total points
ID: 1858443
Here is the information from various sources:

NN4:

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
function runIt() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalExecAccess");
java.lang.Runtime.getRuntime().exec("c:\\WINNT\\Explorer.exe C:\\WINNT");
}
</SCRIPT>
</HEAD>
<BODY>
<FORM><INPUT TYPE="BUTTON" ONCLICK="runIt();" VALUE="Explore"></FORM>
</BODY>
</HTML>

I will comment the rest...
Michel

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1858444
Alternatives:

For MSIE I would suggest you look really hard at Windows Scripting Host (WSH) at
http://www.microsoft.com/scripting/default.htm?/scripting/windowshost/default.htm

Example:
<script language="vbscript">
Set WshShell = CreateObject("WScript.Shell")
   Sub runlink_onClick()
      WshShell.Run "c:\\WINNT\\Explorer.exe c:\\WINNT", 1, 0
   End Sub
</script>

and in the page have <a name="runlink">Run</a>

You will get  

"An activex object on this page may be unsafe. Do you want to allow it to initialize and be accessed by scripts?"

when loading

One possibility is to use the PC Magazine programme WINCMD.  This
permits the launching of programmes from hyperlinks which target text
files.  The text files contain the launch command(s), and have a .wcm
extension which is associated with the WINCMD programme.  The WINCMD
programme ensures execution of the launch command(s).

Another is

Create a dos batch file that calls your program:

@echo off
C:\WINNT\Explorer C:\WINNT
exit

Set your link to the bat file.

If using NetScape, you'll have to define a Helper appl for the .bat
extension, perhaps command.com as a helper?


For just executing (probably without parameters - I had little time to dig out the old browsers you could do the following (Curtesy of JCS):

* 1 - setup the browser to accept running .exe instead of saving them:

-in N3, go the list of:

  Options|General prefs|Helper apps

In the list, locate and select "application/octet-stream", and set it up
with the "Launch application" action.

-in N4, go to:

  Edit|Preferences|Navigator|Applications

Then click on the "New type" button. Enter:

  Description: EXE file
  Extension  : exe
  MIME type  : application/exe
  Action     : "%1" %*

- There's nothing to add in E3.


* 2 - In your page, just have your link:

  <A HREF="file:///C:\WINDOWS\Calc.exe">CALC.EXE</A>


* 3 - When you click the link:

- N3 will show you the default "Save as..." dialog box. Just click the
"Cancel" button, and Calc.exe will be launched.

- N4 will show you the "What do you want me to do with that file" dialog,
with options to open it or save it. Select "open" and click "OK". Calc.exe
will be launched.

- E3 will prompt you for action, then warn you it's unsecure to run an
unsigned exe file, then will launch calc.exe



0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1858445
PS: I think if the java.exec() can be run from livescript, it should be possible to do the same in a signed applet or activex...

Michel
0
 
LVL 6

Expert Comment

by:alamo
ID: 1858446
very nice, Michel. BTW, bjherbison, Michel's javascript is the implementation of the "signed applet" approach you asked about and a signed certificate will be needed to implement it.

As for the CGI, if the cgi puts out the following headers Netscape will save the file as the desired filename rather than as an .exe:

Content-type: application/octet-stream
Content-disposition: filename="temp.lnk"; name="temp.lnk"

Here's a quick perl script I wrote to send the .lnk file from a CGI:

$name = "test.lnk";     # name of link file
$file = "c:\\path\\$name";      # full path+name of file
if (!open(FILE, "<$file")) {
        print "Content-type: text/plain\n\nCan't open file $file: $!\n"; die;
}
binmode FILE;
binmode STDOUT;
print "Content-type: application/octet-stream\r\n";
# set the download filename (for some browsers)
print "Content-disposition: filename=\"$name\"; name=\"$name\"\r\n";
$FILElen= (stat(FILE))[7];
print "Content-length: $FILElen\r\n" if $FILElen;
print "\r\n";
$blocksize = 2048;
while (!eof(FILE)) {
        read FILE,$FILEdata,$blocksize;
        print $FILEdata;
}
close(FILE);
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1858447
Alamo: It will complain but it will run witout the signing

Michel
0
 
LVL 6

Expert Comment

by:alamo
ID: 1858448
The script runs for me (complaining) when I run it from a local file. but when I run it via a web server (localhost, but still a server) it says

JavaScript Error: uncaught Java exception
netscape/security/ForbiddenTargetException ("User didn't grant the
UniversalExecAccess privilege.") "

but it never gave me the grant/deny dialog. Perhaps there is something askew with my system.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1858449
Hmm - I have problems testing this theory since all the servers I have easy access to are intranet and there I have no problems - Did you perhaps do a DENY and then Remember this option from your localhost before?

Also possible: in the pref.js deep in the Netscape directories, you might find you have a priviledge override that conflicts with this...

Michel
0
 

Author Comment

by:bjherbison
ID: 1858450
Thanks for the comments.  I started to look at them and ran into the problem alamo mentioned where I couldn't get permission.  It looks like I need to investigate signing.  (Does anyone know any good tutorials on that?)

I've got some other issues to deal with (bugs to track down) so it may be a couple of days before I get much time to spend on this.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1858451
0
 

Author Comment

by:bjherbison
ID: 1858452
I tried the batch file, and that worked, but when I tried to parameterize it (having IIS process it as an .ASP page) I couldn't get IE to execute the .BAT file -- it would just display the contents.  (I was able to get IIS to process it as a .BAT file and have IE use it as a .BAT file, it only refused to execute it when I added ?Directory=... on the end.)

I was able to get a signed Java applet to work with the applet viewer, but it doesn't work from Netscape.  I need to learn more about signing, and I'm not sure it will work then.  (I didn't try IE with the applet.)

I was able to get a signed Javascript routine to work once with Netscape but IE doesn't support that.

I haven't tried CGI instead of ASP processing -- that's a new technology for me and I don't have time to work on it this week.

I'm going to use a file: URL pointing to the directory with IE, something for Netscape, and go on vacation.  When I come back I'll read the comments again and give it another try.

alamo, see http://www.experts-exchange.com/Q.10062425.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

760 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

20 Experts available now in Live!

Get 1:1 Help Now