Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

space within path in HTA file

Posted on 2010-11-18
16
Medium Priority
?
726 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
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.

 

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 2000 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Read about how to approach blogging and about ways to do it right. Stand out from the crowd and let your knowledge be consumed by a large audience. This article aims to explain how your blog should look like,  the most important things to do while b…
The burden of debt that average person carries today has not only increased, but it keeps on growing. It is quite common nowadays that people find it extremely difficult to make ends meet in the face of millions of competing priorities that they hav…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

885 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