Questo è un post di non molto tempo fa:
Questa è una classe per eseguire programmi (mettila in Shell.asp):
codice:Class cShell Public WScript Public Output Public Error Private Sub Class_Initialize() Set WScript = Server.CreateObject("WScript.Shell") End Sub Public Function Execute(commandLine) Dim oExec on error resume next Set oExec = WScript.Exec(commandLine) If Err.number <> 0 then Response.Write("<p style='font-family:verdana;font-size:11px'>Shell Error "& Err.Description & " CommandLine : " & commandLine) Response.End end if on error goto 0 Error = False Output = oExec.StdOut.ReadAll() if Output="" then Output = oExec.StdErr.ReadAll() Error = True End If Execute = Error End Function Private Sub Class_Terminate() Set WScript = nothing End Sub End Class
Un esempio:
codice:Set Shell = new cShell Response.Write("<BODY style='font-size:11px;font-family:verdana'>") Response.Write ("Questa è un'esecuzione senza errori (return code=0): " & " ") Response.Write("<dir>") Response.Write("Execute"& Shell.Execute("cmd /?") & " ") Response.Write("Error:"&Shell.Error & " ") Response.Write("Output:"&Shell.Output & " ") Response.Write("</dir>") Response.Write ("Questo genera un errore del programma eseguito (return code <>0): " & " ") Response.Write("<dir>") Response.Write("Execute:"&Shell.Execute("cmd /rf") & " ") Response.Write("Error:"&Shell.Error & " ") Response.Write("Output:"&Shell.Output & " ") Response.Write("</dir>") Response.Write ("Il programma non esiste : ") Response.Write(Shell.Execute("cmd1") & " ") Response.Write("</body>") Set Shell = Nothing
Funziona così:
Shell.Execute
Esegue un programma se non lo trova viene bloccata l'esecuzione
Se il programma termina con un codice 0 restituisce false e Error sarà false.
Shell.Error
Ottiene se l'ultimo programma eseguito ha generato un errore.
Shell.Output
Ottiene l'output dell'ultimo programma eseguito.

Rispondi quotando