Solved

space within path in HTA file

Posted on 2010-11-18
16
677 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Read about how to choose the best possible content marketing agency to suit your needs. Content marketing has become an integral part of running a successful tech business, so it is wise to be informed.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

785 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