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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Wscript.Shell on asp page

Status
Not open for further replies.

malaygal

IS-IT--Management
Feb 22, 2006
192
US
I am desperately trying to run a script on my website by using WScript.Shell.

.................

set fs = CreateObject ("Scripting.FileSystemObject")
sourceScriptPath = "C:\Program Files\Batch Jobs\"
destScriptPath = "C:\Program Files\Temp\"
sourceScript = "testload.wsf"
destScript = = "temp_testload.wsf"

Batch1 = "True"
Batch2 = "False"

Response.write "<br>Creating script file.</br>"

fs.CopyFile sourceScriptPath&sourceScript,destScriptPath&destScript

Set f = fs.OpenTextFile(destScriptPath&destScript, 1, True)
sContents=f.ReadAll
f.close


sContents=Replace(sContents,Batch1,Batch2)
Set f = fs.OpenTextFile(destScriptPath&destScript, 2, True)
f.write sContents
f.close

'response.write "<br>" & destScriptPath&destScript & "</br>"

end if

<script language="vbscript">
Dim shell, strCommand
strCommand = destScriptPath & destScript
Set shell = CreateObject("WScript.Shell")
shell.Run strCommand
</script>

The asp page copies a script into another folder, replace some string inside the script, saves and run it.
I keep getting an error: System cannot find file specified, although the new script file is created.

I tried destScript = "hello.vbs" , with no avail

It might have something to do with the space in the strCommnad string (Program Files),I had google'd this and tried every trick suggested.




 
The code you posted is not ASP but more a simple vbs script that will only be runnable on the client.

You need to first declare objects with Server.
Are there <% %> encapsulation tags?
Get rid of the script tags.

Security will be an issue running scripts on the server. You'll need to research this carefully or you'll run into many issues. Is it your intention to even run the script on the server or are you really trying to run it on the client?

[sub]____________ signature below ______________
The worst mistake you'll ever make is to do something simply the way you know how while ignoring the way it should be done[/sub]
 
I am getting object required if I remove the <script> tag.
I have revised the code as :

if fs.fileexists(destScriptPath&destScript) then
Dim shell, strCommand
Set shell = Server.CreateObject("WScript.Shell")
strCommand = destScriptPath&destScript
shell.Run strCommand
end if

 
Being that the script (.wsf) is in the web server and is being run by a web user without admin rights to execute the script, how can I grant the user permission to execute the script?
 
By default, the web server will execute ASP under the security profile of a local account IUSR_MachineName

 
Thanks for the reply.
What about the script (.wsf) that the ASP page is trying to execute? Does the web user needs permission to execute this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top