Solved

space within path in HTA file

Posted on 2010-11-18
16
668 Views
Last Modified: 2012-05-10
I use the code below to open several files on a HTA file that belongs to my asp intranet site:

<html>
<head>
<HTA:APPLICATION ID="oHTA"
      VERSION="1.0"
     APPLICATIONNAME="AmPost"
     BORDER="thin"
     BORDERSTYLE="normal"
     CAPTION="yes"
     CONTEXTMENU="no"
     ICON=""
     INNERBORDER="yes"
     MAXIMIZEBUTTON=no"
     MINIMIZEBUTTON="no"
     NAVIGABLE="yes"
     SCROLL="no"
     SCROLLFLAT="yes"
     SELECTION="yes"
     SHOWINTASKBAR="yes"
     SINGLEINSTANCE="yes"
     SYSMENU="yes"
     WINDOWSTATE="normal"
/>

<script language="VBScript">

Dim objShell

Sub Run(Name)
  Set objShell = CreateObject("WScript.Shell")
  objShell.Run Name
  On Error Resume Next
  Set objShell = Nothing  
End Sub

</script>

</head>
<body>

<!-- Launch Notepad, for example -->
<font onClick="javascript:Run('file://C:/Arquivos de programas/Winamp/winamp.exe');" style="cursor: hand;"><u>winamp</u></font>

<br>

<!-- Or use <a> descriptor -->
<a href="javascript:Run('file://C:/Arquivos de programas/Winamp/winamp.exe');">Winamp</a>

</body>
</html>


It works fine as long as there is no space character within the path of the file to execute. The sample above, for instance , does not work. Could any one give a hint on how to work around this?

Thanks,
Robert
0
Comment
Question by:Roberth509
  • 9
  • 7
16 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34164195
try

<a href="#" onclick=Run('file://C:/Arquivos de programas/Winamp/winamp.exe'.replace(/ /g,'%20'));return false">Winamp</a>
0
 

Author Comment

by:Roberth509
ID: 34165936
Sorry..an error msg appeared saying something like CONTANT SEQUENCE NOT TERMINATED...
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34166490
I forgot a  " in front of Run.

Here

<a href="#" onclick="Run('file://C:/Arquivos de programas/Winamp/winamp.exe'.replace(/ /g,'%20'));return false">Winamp</a>

or
<script type="text/javascript">
var winAmp = 'file://C:/Arquivos de programas/Winamp/winamp.exe'.replace(/ /g,'%20');

function Run(commandtoRun, commandParms) {
  var oShell = new ActiveXObject("Shell.Application");
  oShell.ShellExecute(commandtoRun, commandParms, "", "open", "1");
  return false;
}
</script>
<a href="#" onclick="return Run(winAmp,'song.mp3')">Winamp</a>
0
 

Author Comment

by:Roberth509
ID: 34166908
Thank you so much for trying to help...I think we are nearly there.

Putting in my real data into your script (as seen below), I  receive an error msg saying the path file://C:/Projetos%20Primavera/saprisco.xls does not exist .
I can assure you I have an excel file named saprisco.xls within the c:\projetos primavera folder.
What can be wrong?




<script type="text/javascript">
var saprisco = 'file://C:/Projetos Primavera/saprisco.xls'.replace(/

/g,'%20');

function Run(commandtoRun, commandParms) {
  var oShell = new ActiveXObject("Shell.Application");
  oShell.ShellExecute(commandtoRun, commandParms, "", "open", "1");
  return false;
}
</script>
<a href="#" onclick="return Run(saprisco,'excel file')">saprisco</a>
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 34167327
I would expect




<script type="text/javascript">
var saprisco = 'file://C:/Projetos Primavera/saprisco.xls'.replace(/ /g,'%20');

function Run(commandtoRun, commandParms) {
  var oShell = new ActiveXObject("Shell.Application");
  oShell.ShellExecute(commandtoRun, commandParms, "", "open", "1");
  return false;
}
</script>
<a href="#" onclick="return Run('excel.exe',saprisco)">saprisco</a>
0
 

Author Comment

by:Roberth509
ID: 34179877
Your code is perfect for what I asked, but what is I want to run C:\Arquivos de programas\Oracle\Primavera P6\Project Management\pm.exe?

One issue of it being an exe. What should go in  the RUN statement?

The second is the spaces within the several subfolders. Your code copes well with the spaces in the first level only (up to  'Arquivos de Programas' .


Could you please adapt the code?

I will also ask a new question based on this new point (don't know how awards work on these cases)

Thanks,
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34179894
Should look like

var PM = "file://C:/Arquivos de programas/Oracle/Primavera P6/Project Management/pm.exe".replace(/ /g,'%20');


<a href="#" onclick="return Run(PM,"some parameters to the PM if needed")">Project manager</a>
0
 

Author Comment

by:Roberth509
ID: 34179994
ARUIVOS DE PROGRAMAS is the PROGRAM FILES folder in portuguese...therefore, to iisolate any permission issue, I created an equivalent path:

C:/Projetos Primavera/Oracle/Primavera P6/Project Management/pm.exe

When executing your new code,
Windows returns error msg saying cannot find C:/Projetos%20Primavera/Oracle/Primavera%20P6/Project%20Management/pm.exe


Any idea? I expect c:\ refers to my client computer and not the server...


Thanks for your kind attention...
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.

 

Author Comment

by:Roberth509
ID: 34180013
the pm.exe file I have on C:/Projetos Primavera/Oracle/Primavera P6/Project Management is actually a rtenamed notepad.exe
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34180045
Sorry, no I do not have any idea.

If you try it from the windows explorer, it should give you some clue as to whether or not the file is where you think it is.

Yes the code I gave you is for the client only
0
 

Author Comment

by:Roberth509
ID: 34180082
When I paste C:/Projetos%20Primavera/Oracle/Primavera%20P6/Project%20Management in exp[lorer and press enter, an error msg appears :

Can`t find C:/Projetos%2520Primavera/Oracle/Primavera%2520P6/Project%2520Management...verify if you typed correctly...
Where did this 25 come from?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34180092
encoded % sign
0
 

Author Comment

by:Roberth509
ID: 34180097
Same happens in internet explorer...


Would there be a workaround? Something like creating a short cut and referering to it on your code. All within one new single named folder? Is this possible? How can a short cut be refererred to?

Thanks
0
 

Author Comment

by:Roberth509
ID: 34180150
Funny enough, when I copy C:/Projetos Primavera/Oracle/Primavera P6/Project Management into the comand line of iternet explorer, then it goes to the folder...
Not with C:/Projetos%20Primavera/Oracle/Primavera%20P6/Project%20Management .

Does this mean anything?
0
 

Author Comment

by:Roberth509
ID: 34180181
I replaced
var saprisco = 'file://C:/Projetos Primavera/saprisco.xls'.replace(/ /g,'%20');
with
var saprisco = 'file://C:/Projetos Primavera/saprisco.xls'.replace(/ /g,' ');


AND IT WORKED!!!!!!!!!


Thank you very much...
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34180796
You changed space to space???

Not very useful.

Then you are back to the beginning and can just use

var saprisco = 'file://C:/Projetos Primavera/saprisco.xls'
0

Featured Post

What Security Threats Are You Missing?

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.

Join & Write a Comment

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
This article will shed light on the latest trends when it comes to your resume building needs. For far too long, the traditional CV format has monopolized the recruitment market.
The viewer will learn how to dynamically set the form action using jQuery.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

705 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

19 Experts available now in Live!

Get 1:1 Help Now