Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Re: executing notepad.exe on client PC from url link on server

Status
Not open for further replies.

phumes1

Programmer
Nov 7, 2001
9
CA
Hi,

I have the following code in my html file but it won't execute notepad.exe on my PC. What am I doing wrong?

If I do a message box as a test it works but the shell doesn't?

Basically I have a file link on the server that when clicked I want that file (ascii file) to be opening on my PC (client) in notepad.


<form>
<input type=&quot;button&quot; language=&quot;VBScript&quot; value=&quot;UltraEdit&quot; name=&quot;cmd&quot;>
</form>

<SCRIPT LANGUAGE=&quot;VBScript&quot;>
<!--
Sub cmd_OnClick()
dim wshShell
Set WshShell = WScript.CreateObject(&quot;WScript.Shell&quot;)
WshShell.Run &quot;c:\windows\notepad.exe&quot;
End Sub
-->
</SCRIPT>


 
Hmm.

Works fine for me as follows:
Code:
<SCRIPT LANGUAGE=&quot;VBScript&quot;>
Sub Notepad()
   Dim ws
   Set ws = CreateObject(&quot;WScript.Shell&quot;)
   ws.Run(&quot;%windir%\notepad.exe&quot;)
End Sub
</SCRIPT>
I believe your problem is assuming that you have the object WScript available to you, and trying to use its CreateObject method.

Instead use the CreateObject method of the default object. Is this
Code:
document
?
Code:
window
? The docs don't show a CreateObject for either one - but it works!

Of course the user will get the usual ActiveX control warning and have to OK it.
 
Hi,

I can't get the above code to work!!???

I've been messing around a little and my code has changed since my last post.

This is what I have and notepad won't load on my PC (client) or on the server??

I'm stummped. Should something else be installed? I'm by no means an expert so this is very frustrating. Just to clarify my question. When you run this code. Does notepad open up on your PC or on the server?


<html>

<script language=&quot;vbscript&quot;>
Sub btnRunVB_OnClick
Dim WshShell
Set WshShell = CreateObject(&quot;WScript.Shell&quot;)
WshShell.Run (&quot;c:\windows\notepad.exe&quot;)
End Sub
</script>

<body>

<form NAME=&quot;frmRun&quot;>
<input type=&quot;button&quot; id=&quot;btnRunVB&quot; name=&quot;btnRunVB&quot; value=&quot;Notepad with VBScript&quot;>
</form>

</body>

</html>


 


phumes,


Run your script from the command line and tell us what the error is and what line the code is getting the error.

fengshui_1998
 

I'm really new at this.

How do I run my code at the command line. Whats the syntax?
 
OK.

I took the following code and put it into a file called test.vbs

Sub Notepad()
Dim ws
Set ws = CreateObject(&quot;WScript.Shell&quot;)
ws.Run(&quot;c:\windows\notepad.exe&quot;)
End Sub


I then went on the server running NT4 and opened a command prompt windows and typed the following:

C:\>cscript.exe test.vbs

Microsoft (R) Windows Script Host Version 5.6
Copyright (R) ...etc


NO ERRORS...and notepad did not open?

 
I also ran the below code from the command line and got this message. Should the code have the &quot;sub&quot; and &quot;end sub&quot;?


Set WshShell = CreateObject(&quot;WScript.Shell&quot;)
WshShell.Run (&quot;c:\windows\notepad.exe&quot;)

C:\>cscript.exe test.vbs

Dialog box pops up saying:

The procedure entry point DoOpenPipeStream could not be located in the dynamic link library. ScrRun.dll

I click on &quot;OK&quot; and then in the command window I get:

C:\>test.vbs Microsoft VBScript runtime error: ActiveX component can't create object: 'WScript.Shell'

HELP!!!!!!!!!!

Microsoft (R) Windows Script Host Version 5.6
Copyright (R) ...etc

 
Maybe this'll help:
Code:
<HTML>
<HEAD>
<TITLE>Run Notepad</TITLE>
<SCRIPT LANGUAGE=&quot;VBScript&quot;>
Sub Notepad()
   Dim ws
   Set ws = CreateObject(&quot;WScript.Shell&quot;)
   ws.Run(&quot;%windir%\notepad.exe&quot;)
End Sub
</SCRIPT>
</HEAD>
<BODY>
<H1>Scripto!</H1>
<INPUT id=button1 type=button value=&quot;Notepad&quot;
 name=button1 onclick=&quot;Notepad()&quot;>
</BODY>
</HTML>
 
Version II, like your example using the onClick event-handler approach:
Code:
<HTML>
<HEAD>
<TITLE>Run Notepad</TITLE>
<SCRIPT LANGUAGE=&quot;VBScript&quot;>
Sub button1_onClick()
   Dim ws
   Set ws = CreateObject(&quot;WScript.Shell&quot;)
   ws.Run(&quot;%windir%\notepad.exe&quot;)
End Sub
</SCRIPT>
</HEAD>
<BODY>
<H1>Scripto!</H1>
<INPUT id=button1 type=button value=&quot;Notepad&quot;
 name=button1>
</BODY>
</HTML>
[/code]
Note that onClick must be spelled correctly.
 
I don't know guys.

None of the code samples work.

I don't have a clue.
 
Well, I just tried opening this file on my client PC and its works OK.

I want to be able to click a link in a page from my PC (client) that resides on the webserver. It only works if the file is sitting on my (client) pc.

 
You're right, I finally paid closer attention to what you were saying and tried it myself.

All along we've been assuming there was something wrong with your code.

The reason it won't work is browser security. The WScript object is not &quot;safe for scripting&quot; from the point of view of web access. All of this is to keep people from installing trojans via web pages I guess.

As I think about it, there are darned few ways of having a web page edit/store much on the client's PC besides cookies. The ONLY way I can think of is to write an ActiveX control and mark it &quot;safe for scripting.&quot; And something that starts Notepad is verboten, because a malicious web page could potentially do something like save a bunch of crap and fill up the user's hard drive.

Maybe if you described your eventaul goal I could suggest an alternative. Maybe you can live with a &quot;web deployed application&quot; instead of a &quot;web application?&quot; There are ways to do this using DHTML. The one that comes to mind is to create an HTML Application (HTA).

There is a sample at
Try looking under his &quot;unclassified downloads&quot; first - or maybe it has been moved to another section of the site. This is a small site so you won't have to flip over very many rocks ;-)
 
Just incase you are interested, IE 6 will let you create the WScript object after an ActiveX warning.
 
Hey phumes1,

Try again with this code from command line:


call Notepad

Sub Notepad()
Dim ws
Set ws = CreateObject(&quot;WScript.Shell&quot;)
ws.Run(&quot;notepad.exe&quot;)
End Sub

 
Hads, Re. your message about IE6:

His problem only occurs when he tries to do this in a page loaded from a web server. Local pages work just fine. I tried it myself (IE6 too) and get the same results he does.

Are you doing something else different?
 
my solution to :
The procedure entry point DoOpenPipeStream could not be located in the dynamic link library. ScrRun.dll

it is caused by a ocx file that is not well registered -- wshom.ocx to be precise -- to solve it, reinstall the windows script engine -- e.g. v5.6 from the microsoft site.

worked for me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top