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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I lose the driveletter in this script?

Status
Not open for further replies.

CLSVengeance

Technical User
Aug 19, 2008
4
NL
First off, the script given in thread216-1226233 was very helpfull, just one problem left: I want it to run on various systems so the driveletter may differ on each seperate system, is there a way to solve this?

The script was this:

<script type="text/javascript">
function runApp(which) {
WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run (which,1,false);
}
</script>

<font onClick="runApp('file://E:/subpages/artikelen/1.bat');" style="cursor: hand;" onmouseover="this.style.textDecoration='underline'"
onmouseout="this.style.textDecoration='none'">run</font>

Please help.
 
You would need to know the drive letter (for each system) and code it specifically. Javascript is not going to be able to figure it out on the fly without some help.

One solution might be like this (requiring you to pass in the drive letter and then the path to the script - which are combined in the function to give the path). It still requires you to know the drive letter (specifically) for each script:
Code:
function runApp(drive, which) {
  which = 'file://' + drive + ':/' + which;
  WshShell = new ActiveXObject("WScript.Shell");
  WshShell.Run (which,1,false);
}
...
<font onclick="runApp('E','subpages/artikelen/1.bat');">run</font>
See what you think, and whether it's an appropriate solution for your environment.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
That won't work, the idea is to put the site on a CD-Rom, but the assigned drive letter won't always be E, I tried searching for a way to change this with a batch file, but no luck so far. In short: I've built an offline site to help the employees of my compagny to get an understanding of what's going on, this site should become available on CD-Rom and work on all computers. In order to do so I have to get rid off all drive letters that might compromise the efficiancy of the site. Any idea's?
 
[tt]<script type="text/javascript">
function runApp(path) {
var s=window.location.toString();
var rx=/^((file:\/\/\/)?)([a-z]):/i;
if (rx.test(s)) {
var a=rx.exec(s)
[red]var[/red] WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run([blue]a[a.length-1]+":"[/blue]+path,1,false);
WshShell=null;
}
}
</script>

<font onClick="runApp('[blue]/subpages/artikelen/1.bat[/blue]');" style="cursor: hand;" onmouseover="this.style.textDecoration='underline'"
onmouseout="this.style.textDecoration='none'">run</font>
[/tt]
 
Thanks for the help, but that one didn't do the trick either. Please keep posting all suggestions are welcome.
 
Could you not just loop through all the possible letters until you find a file that you expect i.e check if a file exists in A:\, B:\ to Z:\

there may be more than one cd drive.
 
Will fail completly on a linux clinet (may not be a problem in your scenario though)
 
I'm not sure about relative paths, I mean, relative to what? Unless the actual path for the Shell is the same where the html resides, and I don't think that's true.

Cheers,
Dian
 
First off: Thanks for all you efford so far.
Second: The problem I'm talking about is indeed in one of the subfolders of the site. If I put the stuff in the root it will be a very messy site from a developers point of view. It's also not unlikely that someone other than me will have to add certain files in the future, so I made a couple of subfolders for a better overview. But despite all of your help, the problem still isn't solved. I don't know jack about VB-scripting, so if someone does, please provide the script I need. keenanbr yours didn't do the trick either. Most of my links look something like this: .././blah.htm, which is like using basic dos commando's, .. if you wanna go up, . for remaining where you are. But despite all that it still doesn't work.
I put this line in a batch file:
start notepad Artikeloverzicht.txt
This results in the txt being opend in notepad, but when I call it through a link in my site, it doesn't work. So please keep posting, I'll certainly will keep trying what you say.

mail
 
I would expect call paths to be relative to the 1st page you open (but could be wrong)
 
I've tried this

Code:
<script>
function showMeThePath() {
//  which = 'file://' + drive + ':/' + which;
  WshShell = new ActiveXObject("WScript.Shell");
  WshShell.Run ("explorer.exe /e,.",1,false);
}
</script>
...
<font onclick="showMeThePath();">Show me the path</font>

And the explorer shows my Desktop, not the path where the html is. This is the behaviour I expect. If not, what path should be opened when called from a http server?

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top