Page 1 sur 1
[..] Exporter infos de la console dans un fichier texte
Posté : lun. 12 oct. 2015 16:56
par jcaspar
B
onjour à tous !
Je souhaiterais récupérer les informations de la console dans un fichier texte
mon idée était d'utiliser StdoutRead et StdinWrite mais bon cela n'as pas l'air de fonctionner ...
Pouvez vous svp m'indiquer comment procéder
En vous remerciant pour vos conseils et idées.
Code : Tout sélectionner
ocal $hFile="infos.txt"
$CMD = 'arp -a '
$foo = Run('"' & @ComSpec & '" /k ' & $CMD, @SystemDir,@SW_HIDE)
$Text = StdoutRead($foo)
FileWrite($hFile, StdinWrite($Text))
FileClose($hFile)
ShellExecuteWait($hFile)
Re: [..] Exporter infos de la console dans un fichier texte
Posté : lun. 12 oct. 2015 19:08
par Tlem
Votre ligne Run est pas correct.
Regardez l'exemple de la doc de StdoutRead.
Envoyé de mon appareil mobile avec Tapatalk.
Re: [..] Exporter infos de la console dans un fichier texte
Posté : lun. 12 oct. 2015 19:10
par orax
Il manquait $STDOUT_CHILD et ProcessWaitClose (à moins de mettre une boucle à la place de ProcessWaitClose ; voir l'exemple de StderrRead).
Le /k va laisser l'invite de commande ouverte après la commande et on ne le verra même pas à cause de @SW_HIDE. C'est /c qu'il convient plutôt d'utiliser.
FileClose n'est pas nécessaire puisqu'il n'y a pas eu de FileOpen.
Code : Tout sélectionner
#include <AutoItConstants.au3>
local $hFile="infos.txt"
$CMD = 'arp -a'
$foo = Run($CMD, @SystemDir,@SW_HIDE, $STDOUT_CHILD)
; ou...
;~ $foo = Run(@ComSpec & " /c " & $CMD, @SystemDir,@SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($foo)
$Text = StdoutRead($foo)
FileWrite($hFile, $Text)
ShellExecuteWait($hFile)
Re: [..] Exporter infos de la console dans un fichier texte
Posté : mar. 13 oct. 2015 09:53
par jcaspar
Merci beaucoup pour votre réponse !
J'aurais besoin de petites précisions complémentaires car je souhaiterais exécuter plusieurs commandes à la suite
je pensais faire cela de la manière suivante .. mais la syntaxe n'a pas l'air bonne car par exemple pour arp-a
la commande ne s'excute pas normalement mais l'aide s'affiche ....et autre petit soucis comment échapper
le caractère /
En vous remerciant pour vos conseils
Jean-Marc
► Afficher le texte
local $hFile="infos.txt"
$CMD = 'arp -a && '& _
'net view &&' & 'route print &&'& _
'net share &&' & 'net localgroup &&'& _
'net use &&' & ' tasklist &'/'&svc'& _
'wmic useraccount list &&'& ' gpresult &'/'& SCOPE COMPUTER /Z'
$foo = Run($CMD, @SystemDir,@SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($foo)
$Text = StdoutRead($foo)
FileWrite($hFile, $Text)
ShellExecuteWait($hFile)
[/spoiler]
Re: [..] Exporter infos de la console dans un fichier texte
Posté : mar. 13 oct. 2015 12:02
par jchd
Tu t'es compliqué la vie avec tes chaînes. C'est pas plutôt ça que tu veux :
Code : Tout sélectionner
local $hFile="infos.txt"
$CMD = _
'arp -a && ' & _
'net view && ' & _
'route print && ' & _
'net share && ' & _
'net localgroup && ' & _
'net use && ' & _
'tasklist /svc && ' & _
'wmic useraccount list && ' & _
'gpresult /SCOPE COMPUTER /Z'
$foo = Run(@ComSpec & " /c " & $CMD, @SystemDir, @SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($foo)
$Text = StdoutRead($foo)
FileWrite($hFile, $Text)
ShellExecuteWait($hFile)
Tu aurais même intérêt à convertir le texte capturé si la console DOS est paramétrée comme par défaut (jeu OEM) :
Code : Tout sélectionner
...
$Text = StdoutRead($foo)
$Text = _CodepageToStr($Text)
FileDelete($hFile) ; si on ne veut pas risquer l'accumulation de texte.
FileWrite($hFile, $Text)
ShellExecuteWait($hFile)
Func _CodepageToStr($sCP, $iCodepage = Default)
If $iCodepage = Default Then $iCodepage = Int(RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Nls\Codepage", "OEMCP"))
Local $tText = DllStructCreate("byte[" & StringLen($sCP) & "]")
DllStructSetData($tText, 1, $sCP)
Local $aResult = DllCall("kernel32.dll", "int", "MultiByteToWideChar", "uint", $iCodepage, "dword", 0, "struct*", $tText, "int", StringLen($sCP), _
"ptr", 0, "int", 0)
Local $tWstr = DllStructCreate("wchar[" & $aResult[0] & "]")
$aResult = DllCall("kernel32.dll", "int", "MultiByteToWideChar", "uint", $iCodepage, "dword", 0, "struct*", $tText, "int", StringLen($sCP), _
"struct*", $tWstr, "int", $aResult[0])
Return DllStructGetData($tWstr, 1)
EndFunc ;==>_CodepageToStr
Re: [..] Exporter infos de la console dans un fichier texte
Posté : mer. 14 oct. 2015 14:31
par jcaspar
Merci
beaucoup pour vos conseils
Ai pensé à une solution un peu différente ...
► Afficher le texte
Code : Tout sélectionner
#include <Constants.au3>
Local $foo = Run("cmd.exe ", @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
; Write string to be sorted to child sort.exe's STDIN
StdinWrite($foo, "arp -a" & @CRLF & "ipconfig /all" & _
@CRLF & "route print" & _
@CRLF & "net view" & _
@CRLF & " net time" & _
@CRLF & " net accounts" & _
@CRLF & " net localgroup" & _
@CRLF & " net stat -nao"& _
@CRLF & " net stat" & _
@CRLF & " netstat -vb" & _
@CRLF & " netstat -ns" & _
@CRLF & " net share " & _
@CRLF & " net use" & _
@CRLF & " tasklist /SVC " & _
@CRLF & " wmic useraccount list" & _
@CRLF & " gpresult /SCOPE COMPUTER /Z" & _
@CRLF & " net session" & _
@CRLF & " net share " & _
@CRLF & " net group " & _
@CRLF & " net user" & _
@CRLF & " net localgroup administrators" & _
@CRLF & " net view /domain" & _
@CRLF & " netsh /firewall show config" & _
@CRLF & " tasklist /SVC" & _
@CRLF & " tasklist /m" & _
@CRLF & " gpresult /SCOPE USER /Z" & _
@CRLF & " tasklist /SVC" & _
@CRLF & " wmic computersystem list brief" & _
@CRLF & " wmic useraccount list" & _
@CRLF & " wmic useraccount group list" & _
@CRLF & " wmic useraccount service list brief" & _
@CRLF & " wmic volume list brief" & _
@CRLF & " wmic logicaldisk get descriptionfilesystem,name,size" & _
@CRLF & " wmic volume list brief" & _
@CRLF & " wmic netlogin get name,lastlogon,badpasswordcount" & _
@CRLF & " wmic netclient list brief " & _
@CRLF & " wmic netuse get name,username,connectiontype,localname" & _
@CRLF & " wmic ntevenlog get path, filename,writeable" & _
@CRLF & " wmic process list brief" & _
@CRLF & " wmic startup list full" & _
@CRLF & " wmic rdtogle list" & _
@CRLF & " wmic process list brief" & _
@CRLF & " wmic qfe " & _
@CRLF & " wmic environnement list " & _
@CRLF & " wmic share list" & _
@CRLF & " wmic nicconfig list " & _
@CRLF & " wmic computersystem list" & _
@CRLF & " wmic useraccount list " & _
@CRLF & " wmic group list " & _
@CRLF & " wmic sysaccount list " & _
@CRLF & " wmic volume list brief " & _
@CRLF & " wmic logicaldisk get description,filesystem,name,size " & _
@CRLF & " wmic netlogin get name,lastlogon,badpasswordcount " & _
@CRLF & " wmic netclient list brief " & _
@CRLF & " wmic netuse get name,username,connectiontype,localname " & _
@CRLF & " wmic share get name,path " & _
@CRLF & " wmic nteventlog get path , filename ,writeable " & _
@CRLF & " wmic service list brief " & _
@CRLF & " wmic process list brief " & _
@CRLF & " wmic rdtoggle list " & _
@CRLF & " wmic product get name,version " & _
@CRLF & " wmic qfe list " & _
@CRLF & " wmic startup list full ")
StdinWrite($foo)
Local $data
While True
$data &= StdoutRead($foo)
If @error Then ExitLoop
ConsoleWrite($data)
FileDelete("test.txt")
filewrite("test.txt",$data)
Sleep(25)
WEnd
MsgBox(0, "Informations Réseaux ", $data)