Solved

space within path in HTA file

Posted on 2010-11-18
16
673 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
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: 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

914 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

20 Experts available now in Live!

Get 1:1 Help Now