473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Calling WSH scripts from ASP

Bob
I have created some WSH scripts on my Webserver that are executed by
the Windows Task Scheduler. I want to be able to execute some of these
scripts using a web interface and don't want to duplicate these scripts
in ASP. I know this can be done using the WScript.Shell run method but
I am having no success. Below is a test application I have thrown
together to demonstrate my problem.

If I run c:\intetpub\wwwroot\wshasp\storetime.vbs from the server's
command line it appends the text file
c:\intetpub\wwwroot\wshasp\storetime.vbs with the current time. I can
do this forever and it keeps adding the time to the file, no problem
whatsoever. If I run the ASP using a browser I get nothing, no errors,
just a browser page with "objWSH.run Result: 0", no time is appended to
storedtime.txt, no errors are recorded in any logs.

I have adjusted security settings for iusr_MACHINENAME to allow
read/write/execute.

Finally, I have successfully used the wscript.shell object in an ASP
function to make a direct call to ping, dir, etc. and pipe the results
to a text file.

I have incorporated many things in the following code that I found
searching this group and many links found on Google. Nothing seems to
work, any ideas?
EXAMPLE CODE FOLLOWS

c:\intetpub\wwwroot\wshasp\default.asp:
= = = = = = = = = = = = = = = = = = = = = = = =
<% @ Language = "VBScript" %>
<%
option explicit

function testScript()
dim objWSH
dim intReturn

intReturn = 7 'initialized the value to insure it changed
set objWSH = server.createObject("wscript.shell")
intReturn = objWSH.run("c:\intetpub\wwwroot\wshasp\storetime.v bs")
set objWSH = nothing
response.write("objWSH.run Result: " & intReturn & "<br />")
end function 'daily_scripts
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>

<title>Test WSH</title>

</head>

<body>

<%
testScript()
%>

</body>

</html>
= = = = = = = = = = = = = = = = = = = = = = = =
c:\intetpub\wwwroot\wshasp\storetime.vbs:
= = = = = = = = = = = = = = = = = = = = = = = =
option explicit
dim objFSO
dim objTextFile

set objFSO = createObject("scripting.fileSystemObject")
set objTextFile =
objFSO.openTextFile("c:\intetpub\wwwroot\wshasp\st oredtime.txt", 8,
true)
objTextFile.writeLine(now())
objTextFile.close
set objTextFile = nothing
set objFSO = nothing
= = = = = = = = = = = = = = = = = = = = = = = =

Jun 19 '06 #1
3 4375
Dim oShell
Set oShell = Server.CreateObject("WSCript.shell")
dScript = "wscript \\hank\scripts\test.vbs"
try = oShell.Run(dScript)
Response.Write try

"Bob" <ne*********@gmail.com> wrote in message
news:11*********************@p79g2000cwp.googlegro ups.com...
I have created some WSH scripts on my Webserver that are executed by
the Windows Task Scheduler. I want to be able to execute some of these
scripts using a web interface and don't want to duplicate these scripts
in ASP. I know this can be done using the WScript.Shell run method but
I am having no success. Below is a test application I have thrown
together to demonstrate my problem.

If I run c:\intetpub\wwwroot\wshasp\storetime.vbs from the server's
command line it appends the text file
c:\intetpub\wwwroot\wshasp\storetime.vbs with the current time. I can
do this forever and it keeps adding the time to the file, no problem
whatsoever. If I run the ASP using a browser I get nothing, no errors,
just a browser page with "objWSH.run Result: 0", no time is appended to
storedtime.txt, no errors are recorded in any logs.

I have adjusted security settings for iusr_MACHINENAME to allow
read/write/execute.

Finally, I have successfully used the wscript.shell object in an ASP
function to make a direct call to ping, dir, etc. and pipe the results
to a text file.

I have incorporated many things in the following code that I found
searching this group and many links found on Google. Nothing seems to
work, any ideas?
EXAMPLE CODE FOLLOWS

c:\intetpub\wwwroot\wshasp\default.asp:
= = = = = = = = = = = = = = = = = = = = = = = =
<% @ Language = "VBScript" %>
<%
option explicit

function testScript()
dim objWSH
dim intReturn

intReturn = 7 'initialized the value to insure it changed
set objWSH = server.createObject("wscript.shell")
intReturn = objWSH.run("c:\intetpub\wwwroot\wshasp\storetime.v bs")
set objWSH = nothing
response.write("objWSH.run Result: " & intReturn & "<br />")
end function 'daily_scripts
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>

<title>Test WSH</title>

</head>

<body>

<%
testScript()
%>

</body>

</html>
= = = = = = = = = = = = = = = = = = = = = = = =
c:\intetpub\wwwroot\wshasp\storetime.vbs:
= = = = = = = = = = = = = = = = = = = = = = = =
option explicit
dim objFSO
dim objTextFile

set objFSO = createObject("scripting.fileSystemObject")
set objTextFile =
objFSO.openTextFile("c:\intetpub\wwwroot\wshasp\st oredtime.txt", 8,
true)
objTextFile.writeLine(now())
objTextFile.close
set objTextFile = nothing
set objFSO = nothing
= = = = = = = = = = = = = = = = = = = = = = = =

Jun 20 '06 #2
Bob
Slim, thanks but . . .
function testScript()
dim objWSH
dim intReturn
' edit
dim strRun
' /edit
intReturn = 7 'initialized the value to insure it changed
set objWSH = server.createObject("wscript.shell")
' edit
strRun = "wscript c:\intetpub\wwwroot\wshasp\storetime.vbs"
intReturn = objWSH.run(strRun)
' /edit
set objWSH = nothing
response.write("objWSH.run Result: " & intReturn & "<br />")
end function 'testScript
Same result (no vbs execution). Again, thanks for the reply.
Slim wrote:
Dim oShell
Set oShell = Server.CreateObject("WSCript.shell")
dScript = "wscript \\hank\scripts\test.vbs"
try = oShell.Run(dScript)
Response.Write try


Jun 20 '06 #3
Bob
For those interested I found a solution. I had not specified the
command interpreter. See the edited line. You can use either "cmd" or
"%comspec%" to call the primary or secondary command interpreters
respectively.

function testScript()
dim objWSH
dim intReturn

intReturn = 7 'initialized the value to insure it changed
set objWSH = server.createObject("wscript.shell")
'edit
intReturn = objWSH.run("cmd /c
c:\intetpub\wwwroot\wshasp\storetime.vbs, 0, true")
'/edit
set objWSH = nothing
response.write("objWSH.run Result: " & intReturn & "<br />")
end function 'testScript

Jun 21 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Doug Rosser | last post by:
I'm writing a fairly complicated test framework and keeping configuration data inside ini files that are parsed at runtime by the ConfigParser module. For example, there would be a section...
1
by: delrocco | last post by:
Hello, I really appreciate anyone who has time to read this and help, Thanks up front. I'm very new to python, having picked it up for the first time a week ago, but I feel I'm very close to...
8
by: Vinod | last post by:
Hi, I have a problem, i am calling an exe from asp program. Its not working fine. When i execute the exe through the dos program directly i get the desired result. My exe will convert files in...
5
by: Pekka Niiranen | last post by:
Hi there, I have two scripts. The first "main.py" sets some variables and then imports another called "gen.py". The idea is to provide "main.py" that defines some paths, variables etc. without...
4
by: soumitra.mishra | last post by:
Hi All, I want to call (execute) some python scripts from my C# program. I know that this can be done but have not idea how. The other option that I can think of is developing python web...
1
by: dcnicholls | last post by:
This is my first post to this forum: I use ASP occasionally but don't know a lot of it, and the Windows IIS was invented by MS to torture me :) So I'm not sure if this should be herre or on the IIS...
0
by: inimaykumar | last post by:
Hi, As a part of migration i need the following info: In the current environment the DB and the scripts are in the same environment i,e the same server.So it's easy to connect to the DB jus using...
6
by: geek7 | last post by:
Hello all! I have written a helpdesk ticket webapp which uses many javascript calls to different php scripts to update a mysql database. My question is, a) is there a way to prevent access from...
1
by: Memphis Steve | last post by:
Is it possible to combine multiple javascipts into one file and then call that file from a linked URL in the head section of an XHTML file? Here are the two scripts I want to use with the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.