Comment utiliser schtask / requête et placer la sortie dans le fichier texte à l'aide de VBScript et CMD

StackOverflow https://stackoverflow.com/questions/19826530

Question

Voici le code que j'ai actuellement:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "SCHTASKS /QUERY > winning.txt"

Dans ma tête, cela devrait fonctionner correctement et cela s'exécute sans erreurs, mais le fichier texte n'est pas mis à jour.

Le fichier texte est déjà créé, donc je n'ai pas à me soucier de créer la variable WScript

ÉDITER:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd /c SCHTASKS /QUERY > winning.txt"

Merci David! Je regardais ces deux lignes pendant des heures!

Était-ce utile?

La solution

Ajoutant "cmd / c" à l'avant de la commande

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd /c SCHTASKS /QUERY > winning.txt"
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top