Calling WSH from ASP 
Author Message
 Calling WSH from ASP

I have been reading all the messages I can find on this subject, but
still can not solve my problem.
I have an asp page with the following:
ShellObject = new ActiveXObject("WScript.Shell");
retCode = ShellObject.Run("c:\\temp\\create.wsf",1,0);

where create.wsf:
<package>
<job id="DoneInJS">
<script language="JavaScript">
FileObject = new ActiveXObject("Scripting.FileSystemObject");
tf = FileObject.OpenTextFile("hello.txt",8,1); // 8=ForAppending
1=True
tf.WriteLine ("HELLO" );
tf.close();
FileObject=null;
</script>
</job>
</package>

When I hit the asp page I see wscript.exe come up in the process list
of task manager and just stay there.

Of course if I run create.wsf from explorer it runs fine.
If I call create.bat instead of create.wsf it is able to create
hello.txt

create.bat:
c:
cd\temp
copy file1.txt hello.txt

Which makes me believe it is not a rights issue.

I also tried to make create.wsf as an empty file, but wscript.exe
still just shows up in the process list and never goes away.

Thanks in advance,
Bob K.



Sat, 01 Oct 2005 04:18:53 GMT  
 Calling WSH from ASP

Quote:

> I have been reading all the messages I can find on this subject, but
> still can not solve my problem.
> I have an asp page with the following:
> ShellObject = new ActiveXObject("WScript.Shell");
> retCode = ShellObject.Run("c:\\temp\\create.wsf",1,0);

> where create.wsf:
> <package>
> <job id="DoneInJS">
> <script language="JavaScript">
> FileObject = new ActiveXObject("Scripting.FileSystemObject");
> tf = FileObject.OpenTextFile("hello.txt",8,1); // 8=ForAppending
> 1=True
> tf.WriteLine ("HELLO" );
> tf.close();
> FileObject=null;
> </script>
> </job>
> </package>

> When I hit the asp page I see wscript.exe come up in the process list
> of task manager and just stay there.

You are getting an unhandled runtime error and the WScript.exe host displays
that in a modal message window that has an OK button.  But the process does
*not* run in the context of the visible desktop so you can't even see it.

The underlying error is probably a permission denied trying to create
"hello.txt" (probably in the system2 folder since you don't provide a path.

Quote:
> Of course if I run create.wsf from explorer it runs fine.
> If I call create.bat instead of create.wsf it is able to create
> hello.txt

> create.bat:
> c:
> cd\temp
> copy file1.txt hello.txt

> Which makes me believe it is not a rights issue.

Why?  In the *.wsf version, you don't provide a path or otherwise point to
the c:\temp folder.

Quote:
> I also tried to make create.wsf as an empty file, but wscript.exe
> still just shows up in the process list and never goes away.

a *.wsf can't be empty (i.e., a 0 length file or all blank lines.  There is
minimal xml tags required.  You are still getting an unhandled runtime
error.

When you ShellObject.Run() scripts, be explicit about the host...

    retCode = ShellObject.Run("cscript.exe c:\\temp\\create.wsf",0,false);

and within the *.wsf, always use fully qualified paths for all file
accessed.  You can *not* assume that the working directory is the temp
folder containing the script.  That's generally only true when you run it
interactively via double click in Windows Explorer and it's Explorer that
sets the working directory to the script's folder for you, not wscript.exe
or WshShell.Run method.

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US

Technet Script Center
http://www.microsoft.com/technet/scriptcenter/default.asp



Sat, 01 Oct 2005 11:15:49 GMT  
 Calling WSH from ASP

Thank you for the quick response Michael.

I have tried pathing every file name.  I have also executed a batch
file that tries to run the wsf and re-direct its results to another
file:

create.bat:
c:
cd\temp
cscript c:\temp\create.wsf /B >junk.txt

create.wsf:
<package>
<job id="DoneInJS">
<script language="JavaScript">
FileObject = new ActiveXObject("Scripting.FileSystemObject");
tf = FileObject.OpenTextFile("c:\\temp\\hello.txt",8,1); //
8=ForAppending
1=True
tf.WriteLine ("HELLO" );
tf.close();
FileObject=null;
</script>
</job>
</package>

and junk.txt:
CScript Error: Loading your settings failed. (Access is denied.
)

I even made IUSR_<machinename> an administrator.
I added the registry keys outlined in other posting with similar
errors.
I logged in as IUSR_<machinename> before I made it an administrator
and it worked.

Also the "blank" .wsf file that I tried was:
<package>
<job id="DoneInJS">
<script language="JavaScript">
</script>
</job>
</package>



Sun, 02 Oct 2005 00:22:13 GMT  
 Calling WSH from ASP

Quote:
> CScript Error: Loading your settings failed. (Access is denied.
> )

Check the permissions on the following 2 registry keys and ensure that the
IUSR/IWAM_machinename local accounts have read access.

HKEY_USERS\.DEFAULT\Software\Microsoft\Windows Script Host\Settings
HKEY_LOCAL_MACHINE\.DEFAULT\Software\Microsoft\Windows Script Host\Settings

The IUSR/IWAM accounts are normally in the local Users group and the Users
group has read access.

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US

Technet Script Center
http://www.microsoft.com/technet/scriptcenter/default.asp



Sun, 02 Oct 2005 07:56:57 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. WSH calls VBA or VBA calls WSH

2. no results-call asp pg using WSH

3. How do you call an asp page using wsh

4. HOW TO: call WSH object from ASP

5. Calling wsh objects within asp

6. call an ASP file from wsh?

7. calling asp page from another asp page

8. Calling ASP-engine outside ASP

9. WSH/VBS Login Script Calls

10. WSH Shell to call .EXE

11. Call the Windows API with WSH?

12. WSH + Calling techniques

 

 
Powered by phpBB® Forum Software