macdonaldalex
asked on
Running a .bat file in ASP
Having problems running a .bat file from an ASP page - Does anybody have some working code I could see
I'm trying to use the WScript.Shell object at the moment - but without any success
I can't even get the script at the end of this link to run
http://www.4guysfromrolla.com/webtech/102998-1.shtml
Al
I'm trying to use the WScript.Shell object at the moment - but without any success
I can't even get the script at the end of this link to run
http://www.4guysfromrolla.com/webtech/102998-1.shtml
Al
Any error codes?
What is in the .bat file? if you are trying to run a program on the server you have succeeded, but it just does not show the program visible. Correct, since it is ran under the IUSR_ account in the IIS memory.
CJ
CJ
ASKER
Error Type:
(0x80070483)
/desktop/rudi.asp, line 13
rudi.asp is my asp file...
line 13 is RetCode = WShShell.Run("C:\Documents and Settings\smansoori\Desktop \DoPing.ba t", 1, True)
DoPing.bat file contents is
ping -a 199.173.152.24 > "C:\Documents and Settings\smansoori\Desktop \ping.txt"
The Ping.txt file is never created.
(0x80070483)
/desktop/rudi.asp, line 13
rudi.asp is my asp file...
line 13 is RetCode = WShShell.Run("C:\Documents
DoPing.bat file contents is
ping -a 199.173.152.24 > "C:\Documents and Settings\smansoori\Desktop
The Ping.txt file is never created.
I have just tried this myself and got it to work.
Is your batch file stored on the server in a folder with the correct permissions set?
Make sure that your folder on the server has the correct permissions in order to execute the batch file and create/delete temporary files (for this example).
FYI, I run exactly what I found on you link, though I changed the file path and IP addresses to make it work?
Is your batch file stored on the server in a folder with the correct permissions set?
Make sure that your folder on the server has the correct permissions in order to execute the batch file and create/delete temporary files (for this example).
FYI, I run exactly what I found on you link, though I changed the file path and IP addresses to make it work?
ASKER
Looks like the inital problem was not permissions, but rather the directory - C:\Documents and Settings\smansoori\Desktop \ping.txt
which has spaces in !! Once we changed directory it worked
- If we can go back to the original problem not -
ASP page reads as follows -
"
<%
Set FileSys = Server.CreateObject("Scrip ting.FileS ystemObjec t")
FileName = FileSys.GetTempName
Set WShShell = Server.CreateObject("WScri pt.Shell")
IP = " 199.173.152.24" ' or whatever you want to ping
RetCode = WShShell.Run("c:\test\DoPi ng.bat", 1, True)
if RetCode = 0 Then
'There were no errors
else
Response.Redirect "PingErrors.htm"
end if
'Set TextFile = FileSys.OpenTextFile("c:\t est\ping.t xt", 1)
'TextBuffer = TextFile.ReadAll
'For i = 1 to Len(TextBuffer)
'If Mid(TextBuffer,i,1) = chr(13) Then
'Response.Write("<BR>")
'else
'Response.Write(Mid(TextBu ffer,i,1))
'end if
'Next
'TextFile.Close
'FileSys.DeleteFile "c:\test\ping.txt"
%>
"
and by .bat file -
"
kill notepad.exe
"
The .bat file works when run directly, but via the asp page it doesn't - no asp errors - just nothing
Hope you guys can help
Al
which has spaces in !! Once we changed directory it worked
- If we can go back to the original problem not -
ASP page reads as follows -
"
<%
Set FileSys = Server.CreateObject("Scrip
FileName = FileSys.GetTempName
Set WShShell = Server.CreateObject("WScri
IP = " 199.173.152.24" ' or whatever you want to ping
RetCode = WShShell.Run("c:\test\DoPi
if RetCode = 0 Then
'There were no errors
else
Response.Redirect "PingErrors.htm"
end if
'Set TextFile = FileSys.OpenTextFile("c:\t
'TextBuffer = TextFile.ReadAll
'For i = 1 to Len(TextBuffer)
'If Mid(TextBuffer,i,1) = chr(13) Then
'Response.Write("<BR>")
'else
'Response.Write(Mid(TextBu
'end if
'Next
'TextFile.Close
'FileSys.DeleteFile "c:\test\ping.txt"
%>
"
and by .bat file -
"
kill notepad.exe
"
The .bat file works when run directly, but via the asp page it doesn't - no asp errors - just nothing
Hope you guys can help
Al
I have taken your code and modidied it slightly, ensuring Option Explicit and objects are set to nothing when finished. I have also stripped out the stuff I didn't use.
The "ping.bat" file exists in a dir with read & exec permissions on my web server.
The listing that is created lists the c: of my web server into a file on its own c drive.
I have used a simple example of a bat file to ensure that there were no problems with it.
ASP:
<%
Option Explicit
Dim FileSys, FileName, WShShell, RetCode
Set FileSys = Server.CreateObject("Scrip ting.FileS ystemObjec t")
FileName = FileSys.GetTempName
Set WShShell = Server.CreateObject("WScri pt.Shell")
RetCode = WShShell.Run("c:\websites\ taff\ping. bat", 1, True)
'retcode key: 0 = no error, 1 = error encountered
Response.Write RetCode
Set WShShell = Nothing
Set FileSys = Nothing
%>
BAT:
dir c:\ > "c:\test.txt"
The "ping.bat" file exists in a dir with read & exec permissions on my web server.
The listing that is created lists the c: of my web server into a file on its own c drive.
I have used a simple example of a bat file to ensure that there were no problems with it.
ASP:
<%
Option Explicit
Dim FileSys, FileName, WShShell, RetCode
Set FileSys = Server.CreateObject("Scrip
FileName = FileSys.GetTempName
Set WShShell = Server.CreateObject("WScri
RetCode = WShShell.Run("c:\websites\
'retcode key: 0 = no error, 1 = error encountered
Response.Write RetCode
Set WShShell = Nothing
Set FileSys = Nothing
%>
BAT:
dir c:\ > "c:\test.txt"
ASKER
Thanks Taff22,
I have just changed my .bat file to match the your dir command and that works fine -
Unfortunatly the thing is I need to get the .bat program to kill a process on the server (notepad was just an example)
I have just changed my .bat file to match the your dir command and that works fine -
Unfortunatly the thing is I need to get the .bat program to kill a process on the server (notepad was just an example)
I must confess that I know very little about the "kill" command, my W2k box doesn't recognise it.
If it is used to kill processes, I assume that you have to have admin permissions, which your internet guest account is unlikely to have...
If it is used to kill processes, I assume that you have to have admin permissions, which your internet guest account is unlikely to have...
ASKER
Good point - but at the moment I'm logged in as the administrator of the NT server
I *think* that if you are you using anonymous access to the site, the process will run as IUSR_MachineName, regardless of who you are logged on as...
taff22
You're right. But if someone is anonymous he shouldn't get the option the run such scripts.
Als, I guess, the wscript object will not run under the anonymous user context. (I hope)
You're right. But if someone is anonymous he shouldn't get the option the run such scripts.
Als, I guess, the wscript object will not run under the anonymous user context. (I hope)
I have run it as a guest user, but did have to explicitly give him permission to exec scripts in that folder...
ASKER
Did you run it with a kill command ?? - As dir commands run fine with the anonymous user
Maybe we should put a terminate process command in a vbs script ? What do u think ?
Maybe we should put a terminate process command in a vbs script ? What do u think ?
No, sorry, was a lil' confused, I thought you meant run *any* scripts... I missed where you put "such" ;-)
ASKER
Have piped the result of running
kill notepad.exe
into a txt file and get back
"adjusttokenprivileges failed with 1300"
Any Ideas ???
Cheers
Al
kill notepad.exe
into a txt file and get back
"adjusttokenprivileges failed with 1300"
Any Ideas ???
Cheers
Al
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Have found that - Thanks
Also have found local security policy program on Win 2000 server - try to alter diff privileges now
Also have found local security policy program on Win 2000 server - try to alter diff privileges now
ASKER
No luck - but I will award the points to Taff any away
Al
Al
ASKER
No Luck I'm afraid
Al
Al
Thanks Al,
Good luck with that, now I've had a look at that I might be using it myself at some point, so keep your eyes peeled for any problems/solutions I come across!!!
Taff
Good luck with that, now I've had a look at that I might be using it myself at some point, so keep your eyes peeled for any problems/solutions I come across!!!
Taff