ricky Posted October 26, 2015 Posted October 26, 2015 (edited) Hello,I have a lot of times to work with dos command, but it's very difficult to take only what we need.Example :Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\atis>cscript /nologo c:\windows\system32\slmgr.vbs /xpr Windows(R) 7, Professional edition: Initial grace period ends 11/20/2015 5:57:22 PM C:\Users\atis>What dos return, I just want the line : Initial grace period ends 11/20/2015 5:57:22 PMHow can I have it? more faster?My function to read : Func windowsActivation() Local $a_return Local $s_return = DosCommand('cscript /nologo c:\windows\system32\slmgr.vbs /xpr') $a_return = StringSplit( $s_return, ":") $s_return = StringReplace($s_return,$a_return[1] & ":","") Return RemoveNewLine($s_return) EndFunc Func RemoveNewLine($string) Local $OldString = "0D0A" ; '\r\n' Local $doubleSpace = "2020" ; ' ' $string = Hex(StringToBinary($string)) ; Function _StringToHex from string.au3 $string = StringReplace($string, $OldString, "") $string = StringReplace($string, $doubleSpace, "") Return _HexToString($string) EndFunc ;==>RemoveNewLine Func DosCommand($command) Local $foo, $line, $temp $foo = Run(@ComSpec & " /c " & $command, @ScriptDir, @SW_HIDE, 2); $STDOUT_CHILD = 2 De Constants.au3 While 1 $line = StdoutRead($foo) If @error Then ExitLoop If $line <> "" Then $temp &= _OemToStr($line) WEnd Return $temp EndFunc ;==>DosCommandThanks for your help Edited October 26, 2015 by ricky
mikell Posted October 26, 2015 Posted October 26, 2015 (edited) ?$s_return = "Microsoft Windows [Version 6.1.7601]" & @crlf & _ "Copyright (c) 2009 Microsoft Corporation. All rights reserved." & @crlf & @crlf & _ "C:\Users\atis>cscript /nologo c:\windows\system32\slmgr.vbs /xpr" & @crlf & _ "Windows(R) 7, Professional edition:" & @crlf & _ " Initial grace period ends 11/20/2015 5:57:22 PM" & @crlf & @crlf & @crlf & _ "C:\Users\atis>" $s_return = StringRegExpReplace($s_return, '(?s).*(Initial\V+).*', "$1") msgbox(0,"", $s_return) Edited October 26, 2015 by mikell
ricky Posted October 26, 2015 Author Posted October 26, 2015 (edited) In this case, it's correct, but the answer is different depending the os language and if the system is activated or not:FR :Microsoft Windows [version 6.1.7601]Copyright (c) 2009 Microsoft Corporation. Tous droits réservés.C:\Users\test>cscript /nologo c:\windows\system32\slmgr.vbs /xprWindows(R) 7, Professional edition: L'ordinateur est définitivement activé.C:\Users\test>Same message in EN:Microsoft Windows [Version 6.1.7601]Copyright (c) 2009 Microsoft Corporation. All rights reserved.C:\Users\test>cscript /nologo c:\windows\system32\slmgr.vbs /xprWindows(R) 7, Professional edition: The machine is permanently activated.C:\Users\test>And different depending the OS, Windows 8.1 and 10 Pro:Microsoft Windows [Version 6.3.9600](c) 2013 Microsoft Corporation. All rights reserved.C:\Users\test>cscript /nologo c:\windows\system32\slmgr.vbs /xprWindows(R), Professional edition: The machine is permanently activated.C:\Users\test>And different depending the OS, Windows server 2008:Microsoft Windows [Version 6.1.7601]Copyright (c) 2009 Microsoft Corporation. All rights reserved.C:\Users\test>cscript /nologo c:\windows\system32\slmgr.vbs /xprWindows Server(R), ServerStandard edition: The machine is permanently activated.C:\Users\test> Edited October 26, 2015 by ricky
mikell Posted October 26, 2015 Posted October 26, 2015 Slight regex adjustment $s_return1 = "Microsoft Windows [Version 6.1.7601]" & @crlf & _ "Copyright (c) 2009 Microsoft Corporation. All rights reserved." & @crlf & @crlf & _ "C:\Users\atis>cscript /nologo c:\windows\system32\slmgr.vbs /xpr" & @crlf & _ "Windows(R) 7, Professional edition:" & @crlf & _ " Initial grace period ends 11/20/2015 5:57:22 PM" & @crlf & @crlf & @crlf & _ "C:\Users\atis>" $s_return2 = "Microsoft Windows [version 6.1.7601]" & @crlf & _ "Copyright (c) 2009 Microsoft Corporation. Tous droits réservés." & @crlf & @crlf & _ "C:\Users\test>cscript /nologo c:\windows\system32\slmgr.vbs /xpr" & @crlf & _ "Windows(R) 7, Professional edition:" & @crlf & _ " L'ordinateur est définitivement activé." & @crlf & @crlf & @crlf & _ "C:\Users\test>" $s_return3 = "Microsoft Windows [Version 6.3.9600]" & @crlf & _ "(c) 2013 Microsoft Corporation. All rights reserved." & @crlf & @crlf & _ "C:\Users\test>cscript /nologo c:\windows\system32\slmgr.vbs /xpr" & @crlf & _ "Windows(R), Professional edition:" & @crlf & _ " The machine is permanently activated." & @crlf & @crlf & @crlf & _ "C:\Users\test" $s_return1 = StringRegExpReplace($s_return1, '(?s).*edition:\s+(\V+).*', "$1") msgbox(0,"1", $s_return1) $s_return2 = StringRegExpReplace($s_return2, '(?s).*edition:\s+(\V+).*', "$1") msgbox(0,"2", $s_return2) $s_return3 = StringRegExpReplace($s_return3, '(?s).*edition:\s+(\V+).*', "$1") msgbox(0,"3", $s_return3)
ricky Posted October 27, 2015 Author Posted October 27, 2015 Tanks for your help and regex adjustement. I know, there is a regex tutorial, where can I find it?I search in the wiki, but nothing found...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now