Anyone know how to execute a Windows Script from ASP?

L

Larry Woods

I need to execute a Windows script (wscript/cscript) from an ASP page for
some administrative functions. Anyone doing this? If so, how?

TIA,

Larry Woods
 
K

Ken Schaefer

WScript.Shell?

Cheers
Ken


: I need to execute a Windows script (wscript/cscript) from an ASP page for
: some administrative functions. Anyone doing this? If so, how?
:
: TIA,
:
: Larry Woods
:
:
 
L

Larry Woods

Have you ever done it? I have tried using WScipt.Shell in about every way
that I know how and it doesn't execute the script. If you have an example I
would appreciate seeing it.

Thanks

Larry Woods
 
K

Ken Schaefer

There are lots of sample scripts on the web. When you say "it doesn't
work" - what do you mean? Do you get an error? (the number 1 problem I see
is permissions problems)

Cheers
Ken

: Have you ever done it? I have tried using WScipt.Shell in about every way
: that I know how and it doesn't execute the script. If you have an example
I
: would appreciate seeing it.
:
: Thanks
:
: Larry Woods
:
: : > WScript.Shell?
: >
: > Cheers
: > Ken
: >
: >
: > : > : I need to execute a Windows script (wscript/cscript) from an ASP page
: for
: > : some administrative functions. Anyone doing this? If so, how?
: > :
: > : TIA,
: > :
: > : Larry Woods
: > :
: > :
: >
: >
:
:
 
L

Larry Woods

I get no indication that the script worked. The script is supposed to
create a small text file. The file ain't there! When I execute the script
from the command line it works fine.
 
K

Ken Schaefer

Do you have On Error Resume Next in your ASP page?

Also, when you talk about a script - I assume you don't mean a .bat batch
file, but rather a .vbs WScript file (or similar)?

Cheers
Ken

: I get no indication that the script worked. The script is supposed to
: create a small text file. The file ain't there! When I execute the
script
: from the command line it works fine.
:
:
: : > There are lots of sample scripts on the web. When you say "it doesn't
: > work" - what do you mean? Do you get an error? (the number 1 problem I
see
: > is permissions problems)
: >
: > Cheers
: > Ken
: >
:
 
M

MSFT

Hi Larry,

Did you want to execute a VBS file or some VB Script code? On client side
or server side?

Luke
Microsoft Online Partner Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
L

Larry Woods

I'm talking about a .vbs WScript.

Here is the ASP Page ( in wwwroot ):

<% dim s

s=Server.MapPath("listprocesses.vbs")
CommandLine s,""

Sub CommandLine(progName,strVariable)
'Create Shell Object
Set objScriptShell = Server.CreateObject("Wscript.Shell")
'now run your program and dump the results into a .txt file
ss= "cscript " & progName & " " & strVariable _
& "> " & Server.MapPath("shellLog") & "\log" & ".txt"

objScriptShell.Run (ss, 0, True)
End Sub

And here is the vbs script that I am trying to execute ( in wwwroot ):

'
' listprocesses.vbs
'
set objService = getobject("winmgmts:")
dim s
for each Process in objService.InstancesOf("Win32_process")
if lcase(process.name)="dllhost.exe" then
s=s & Process.Name & vbTab & Process.processid & vbCrLf
end if
Next
WScript.echo s

TIA,

Larry
 
L

Larry Woods

Thanks, Bob, but I am not running Norton, etc. on this server so it can't be
the "culprit".

Larry
 
L

Larry Woods

Ken,

Additional information:

I am getting a return code of "1" from the Run method--but can't find any MS
doc that tells me what that means.

Larry
 
L

Larry Woods

I want to execute a .vbs file on the server. I want to execute it from an
ASP page.

Larry Woods
 
K

Ken Schaefer

That's an "error". Possible return codes are (if I'm looking at the right
info):

0 SUCCESS
1 ERROR
2 WARNING
4 INFORMATION
8 AUDIT_SUCCESS
16 AUDIT_FAILURE


Looking at the script you are running - I suspect that IUSR_<machinename>
wouldn't be able to enumerate a list of running processes (if it is in the
Guests group) - but I'm not sure about that.

Can you turn off "Allow Anonymous Access", and authenticate as a local
administrator, and see if your script runs?

Cheers
Ken


: Ken,
:
: Additional information:
:
: I am getting a return code of "1" from the Run method--but can't find any
MS
: doc that tells me what that means.
:
: Larry
:
: : > Do you have On Error Resume Next in your ASP page?
: >
: > Also, when you talk about a script - I assume you don't mean a .bat
batch
: > file, but rather a .vbs WScript file (or similar)?
: >
: > Cheers
: > Ken
: >
: > : > : I get no indication that the script worked. The script is supposed to
: > : create a small text file. The file ain't there! When I execute the
: > script
: > : from the command line it works fine.
: > :
: > :
: > : : > : > There are lots of sample scripts on the web. When you say "it
doesn't
: > : > work" - what do you mean? Do you get an error? (the number 1 problem
I
: > see
: > : > is permissions problems)
: > : >
: > : > Cheers
: > : > Ken
: > : >
: > :
: >
: >
:
:
 
L

Larry Woods

I think that it is something much more basic, Ken. I commented ALL of the
lines of the script and I am still getting the return code of 1. I checked
the script and all permissions are turned on ("Full Control"). Also inetpub
and wwwroot. I can't figure out what I am missing.

Larry
 
M

MSFT

Hi Larry,

I found "WScript.Echo" in your VBS code, this method will outputs text to
either a message box or the command console window. However, you can't do
this in ASP server side. You may use LogEvent method instead.


Luke
Microsoft Online Partner Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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

Forum statistics

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

Latest Threads

Top