Solved

space within path in HTA file

Posted on 2010-11-18
16
709 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

 

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
 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
In this blog, I will share you some basic tips for content marketing and to rank your website on Google.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

624 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