Relancer iis via asp

cs_hasgaard Messages postés 4 Date d'inscription mercredi 7 mai 2003 Statut Membre Dernière intervention 29 avril 2008 - 9 avril 2008 à 22:04
zuff Messages postés 79 Date d'inscription lundi 28 octobre 2002 Statut Membre Dernière intervention 21 octobre 2008 - 10 avril 2008 à 11:12
Bonjour à tous,

Savez-vous si la méthode  wshell pour exécuter des lignes de commande peut être utilisée pour redémarrer iis d'un script asp ?

Déjà que pour notepad, ça ne semble pas fonctionner pour moi

set wshell=Server.CreateObject("wscript.shell")
cmd = "notepad"
wshell.Run cmd, SW_SHOWNORMAL,false
Set wshell=nothing

...je suppose qu'il sera plus difficile d'exécuter une tâche aussi sécurisée que le redémarrage d'IIS

Pourtant, c jouable, dans Plesk par exemple (php), l'interface permet de relancer IIS.

Avez-vous une idée sur la mnière de procéder.

Merci à tous de partager votre savoir, c'est précieux :)

Bonne soirée

1 réponse

zuff Messages postés 79 Date d'inscription lundi 28 octobre 2002 Statut Membre Dernière intervention 21 octobre 2008
10 avril 2008 à 11:12
La première chose vérifie que le WMI fonctionne correctement sur le serveur.
Ensuite le script que tu montre en exemple est du VBscript.

Voici le code que j'utilise sur mon serveur avec un fichier .bat qui lance mon programme qui génére des vignettes à partir de pdf  :

System.IO.

FileStream fs =
new System.IO.
FileStream(LeChemin +
"images" + Session[
"Login"].ToString() +
".bat", System.IO.
FileMode.OpenOrCreate, System.IO.
FileAccess.Write);System.IO.

StreamWriter sw =
new System.IO.
StreamWriter(fs);

string LigneBat =
"nconvert -npcd 2 -size 256x256+0 -ctype grey -corder inter -out jpeg -o "" + LeChemin +
"Miniatures\\%.jpg" -ratio -rtype lanczos -rflag orient -resize 160 120 -text_flag center -text_font "Bodoni MT Black" 15 -text_color 66 66 66 -text "URBALYON" "" + path + nomFichier +
""";sw.WriteLine(LigneBat);

sw.Flush();

sw.Close();

fs.Close();

// Get the full file path

string strFilePath = LeChemin +
"images" + Session[
"Login"].ToString() +
".bat";

// Create the ProcessInfo objectSystem.Diagnostics.

ProcessStartInfo psi =
new System.Diagnostics.
ProcessStartInfo("cmd.exe");psi.UseShellExecute false;psi.RedirectStandardOutput
true;psi.RedirectStandardInput true;psi.RedirectStandardError

true;psi.WorkingDirectory = LeChemin;

// Start the processSystem.Diagnostics.

Process proc = System.Diagnostics.
Process.Start(psi); 

// Open the batch file for readingSystem.IO.

StreamReader strm = System.IO.
File.OpenText(strFilePath);

// Attach the output for readingSystem.IO.

StreamReader sOut = proc.StandardOutput;

// Attach the in for writingSystem.IO.

StreamWriter sIn = proc.StandardInput; 

// Write each line of the batch file to standard input

while (strm.Peek() != -1){

sIn.WriteLine(strm.ReadLine());

}

strm.Close();

// Exit CMD.EXE

string stEchoFmt =
"# {0} run successfully. Exiting";sIn.WriteLine(

String.Format(stEchoFmt, strFilePath));sIn.WriteLine(

"EXIT");

// Close the processproc.Close();

// Read the sOut to a string.

string results = sOut.ReadToEnd().Trim(); 

// Close the io Streams;sIn.Close();

sOut.Close();
0
Rejoignez-nous