Script to open a DOS Command Window and run exe on client (INTRANET)

K

KathyB

Hi,

I have an asp.net app running on an Intranet. From one of my aspx
pages I would like to run a javascript that will run the following
command OUTSIDE of the IIS/asp.net environment on the CLIENT machine
(remember, a controlled Intranet!). Is this possible? This windows
program needs to be opened and data entered periodically while using
the asp.net app as well.

The exe runs in a dos command window, tied to a Citrix ica file.

C:\Program Files\Citrix\ICA Client\wfica32.exe ciq.ica

PLEASE help me...the boss really wants this!

Thanks,

Kathy
 
L

Lee

KathyB said:
Hi,

I have an asp.net app running on an Intranet. From one of my aspx
pages I would like to run a javascript that will run the following
command OUTSIDE of the IIS/asp.net environment on the CLIENT machine
(remember, a controlled Intranet!). Is this possible? This windows
program needs to be opened and data entered periodically while using
the asp.net app as well.

The exe runs in a dos command window, tied to a Citrix ica file.

C:\Program Files\Citrix\ICA Client\wfica32.exe ciq.ica

PLEASE help me...the boss really wants this!


IE only:
var shell=new ActiveXObject("WScript.Shell");
shell.Run("cmd /K CD C:\ & Dir", 1);

peeve:
It is not "a javascript", any more than a Java program is "a Java".
 
K

kaeli

Hi,

I have an asp.net app running on an Intranet. From one of my aspx
pages I would like to run a javascript that will run the following
command OUTSIDE of the IIS/asp.net environment on the CLIENT machine
(remember, a controlled Intranet!). Is this possible?

You can use an HTA for this (jscript or vbscript).
They run on the client.

"Normal" javascript, as in just a link to the application/exe or a
window.open, would require a browser environment.
You could have a link in the aspx page that points to your hta, which
opens the process and shows the dos window.

<a href="myHTA.hta">Click here for process</a>

HTA documentation:
http://msdn.microsoft.com/workshop/author/hta/overview/htaoverview.asp

--
 
K

Kathy Burke

Lee, I tried this but get an IE6 error that a ";" is expected...at
position 15 but that doesn't make sense.

Specifically, from an onclick event in aspx page, I have

Response.Write("<script>var shell=new
ActiveXObject(""WScript.Shell"");shell.Run(""cmd /K CD C:\\Program
Files\\Citrix\\ICA Client\\wfica32.exe ciq.ica"", 1);</script>")

I see the script in the html source when I run it, but I get the error
as mentioned above. Any thoughts?

Thanks for your help.

Kathy

p.s. what does the "1" do at the end of the shell.run line?
 
K

Kathy Burke

kaeli,

First, I trust anyone who listens to their rice krispies!

Although I've never used it, this seems like a great idea. I created an
hta page (that I open from the button onclick event in aspx page) and
put in an onload javascript:

function openCIQ() {
var shell=new ActiveXObject("WScript.Shell");
shell.Run("C:\\Program Files\\Citrix\\ICA Client\\wfica32.exe ciq.ica",
1); }

I get prompted for the File Download (Open/Save, etc.)

When clicked, I get an error message that the ica file can not be found.
I suspect it's looking for the file on my http local host instead of the
c: directory?

Anyhow, any ideas of where I may be going wrong?

Thanks again.

Kathy

Kathy
 
K

kaeli

kathyburke40 said:
kaeli,

First, I trust anyone who listens to their rice krispies!

hehe


function openCIQ() {
var shell=new ActiveXObject("WScript.Shell");
shell.Run("C:\\Program Files\\Citrix\\ICA Client\\wfica32.exe ciq.ica",
1); }

I get prompted for the File Download (Open/Save, etc.)

Try
var shell = WScript.CreateObject("Wscript.Shell");
instead of ActiveX. With an HTA, you don't need ActiveX. Less overhead,
I think, too.
When clicked, I get an error message that the ica file can not be found.
I suspect it's looking for the file on my http local host instead of the
c: directory?

Anyhow, any ideas of where I may be going wrong?

It's an oddity with the quotes because of the space in the "Program
Files".
In VBScript, I'd do
shell.Run """C:\\Program Files\\Citrix\\ICA Client\\wfica32.exe
ciq.ica"""

I'm not sure how it goes in JScript. If you can't get it, get the space
out using DOS filename for Program Files with the tilde.

--
 
L

Lee

Kathy Burke said:
Lee, I tried this but get an IE6 error that a ";" is expected...at
position 15 but that doesn't make sense.

Specifically, from an onclick event in aspx page, I have

Response.Write("<script>var shell=new
ActiveXObject(""WScript.Shell"");shell.Run(""cmd /K CD C:\\Program
Files\\Citrix\\ICA Client\\wfica32.exe ciq.ica"", 1);</script>")

I see the script in the html source when I run it, but I get the error
as mentioned above. Any thoughts?

Thanks for your help.

Kathy

p.s. what does the "1" do at the end of the shell.run line?

In Javascript, you don't nest quotes by doubling them, as you do in VBScript.
Try changing ""WScript.Shell"" to \"Wscript.Shell\"
and the same for the other embedded quotes.
You'll also have to escape every backslash, so all of those instances
of \\ need to change to \\\\

The "1" argument says to show the DOS window:
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsmthrun.asp>
 
K

kaeli

It's an oddity with the quotes because of the space in the "Program
Files".
In VBScript, I'd do
shell.Run """C:\\Program Files\\Citrix\\ICA Client\\wfica32.exe
ciq.ica"""

I'm not sure how it goes in JScript. If you can't get it, get the space
out using DOS filename for Program Files with the tilde.


This worked for me with VBScript. If all your users have IE, VBScript is
fine.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>Run Executable HTA</TITLE>
</HEAD>
<body bgcolor=#565656>
<script language="VBScript" type="text/vbscript">
set oShell = CreateObject("WScript.Shell")
oShell.run """C:\Program Files\Microsoft Office\Office\Excel.exe""",1
window.close
</script>
</BODY>
</HTML>


This worked with javascript.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>Run Executable HTA</TITLE>
</HEAD>
<body bgcolor=#565656>
<script language="javascript" type="text/javascript">
var oShell = new ActiveXObject("WScript.Shell");
var prog = "C:\\Program Files\\Microsoft Office\\Office\\Excel.exe";
oShell.run ('"'+prog+'"',1);
window.close();
</script>
</BODY>
</HTML>

--
 
K

Kathy Burke

kaeli,

Tried the changes you suggested. Now I get an error that "WScript is
undefined". I've also changed over to using DOS filename.

From the examples I've found on line, this seems like it should work...

sigh...?

Kathy
 
K

Kathy Burke

Hi again,

Seems to work, but can't find the file. However, when I copy and paste
the file name (as shown below) into the cmd window, it runs the program
as expected.

(note \\ used for javascript)

"c:\\Progra~1\\Citrix\\ICAACLI~1\\wfica32 vbciq.ica"

Does anyone have any idea of where I can look next?

Thanks again.

Kathy
 
K

Kathy Burke

Ah ha!

Oddly enough I had to set a variable with the full file path for the
target file.

var file = "c:\\progra~1\\Citrix\\ICACLI~1\\vbciq.ica"

oShell.Run("c:\\progra~1\\Citrix\\ICACLI~1\\wfica32 " + file,1);

That did it. Thanks for all the help!

Kathy

p.s. I thought using an HTA would mean I WOULDN'T get the open/save
confirmation window when this loads. Any way around that?
 
K

kaeli

kathyburke40 said:
p.s. I thought using an HTA would mean I WOULDN'T get the open/save
confirmation window when this loads. Any way around that?

No. According to MS site on HTAs, it is designed that way for security.


--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top