NDog Posted April 17, 2011 Share Posted April 17, 2011 (edited) I would like to retrieve a value from a comspec session and return it to autoit as $guid I use this command to set %guid% in .cmd batch file getguid.cmd for /f "tokens=2 delims={}" %%g in ('bcdedit.exe /create /application OSLOADER /d "WinGhoster"') do (set guid={%%g}) echo %guid% guid={06fb46ad-634c-11e0-bb15-d235e2a65117} I have tried reading the help file regarding stdread, however my syntax is wrong and it is not returning the whole guid to autoit. I dont know how it works, maybe someone can fix my code. Thanks. ; attempt 1 - wrong #include <Constants.au3> ;Local $foo = Run(@ComSpec & " /c dir foo.bar", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) $Win = "WinGhoster" Local $foo = Run(@ComSpec & ' " /c @for /f "tokens=2 delims={}" %1 in ( '' bcdedit.exe /create /application OSLOADER /d ' & $Win & "') do (echo {%1})" , @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Local $line While 1 $line = StdoutRead($foo) If @error Then ExitLoop MsgBox(0, "STDOUT read:", $line) Wend While 1 $line = StderrRead($foo) If @error Then ExitLoop MsgBox(0, "STDERR read:", $line) Wend ; attempt 2 - wrong $Win = "WinGhoster" Local $cmd1 = ' /c @for /f "tokens=2 delims={}" %1 in ( '' bcdedit.exe /create /application OSLOADER /d ' & $Win & "') do (echo {%1})" $PID = Run(@ComSpec & $cmd1, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) $guid = StdoutRead($PID) MsgBox(0, "STDERR read:", $guid) Edited April 17, 2011 by NDog Link to comment Share on other sites More sharing options...
Skitty Posted April 17, 2011 Share Posted April 17, 2011 (edited) $iPID = Run(@ComSpec & $cmd1, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ProcessWait($iPID) $sErrorMsg = "" While 1 $sErrorMsg &= StdoutRead($iPID) If @error Then ExitLoop WEnd If $sErrorMsg = "" Then Exit MsgBox(0,"",$sErrorMsg) Would something like this work out? Edited April 17, 2011 by System238 Link to comment Share on other sites More sharing options...
somdcomputerguy Posted April 17, 2011 Share Posted April 17, 2011 I use this command to set %guid% in .cmd batch file getguid.cmd for /f "tokens=2 delims={}" %%g in ('bcdedit.exe /create /application OSLOADER /d "WinGhoster"') do (set guid={%%g}) echo %guid% guid={06fb46ad-634c-11e0-bb15-d235e2a65117} Maybe you can use the EnvGet function to get it into what you want. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
NDog Posted April 17, 2011 Author Share Posted April 17, 2011 (edited) This is what I want. Also be warned if you are using a 64 bit operating system and a 32bit version of SciTE. Thanks System238 for your advice. My code below is good enough for my use. getguid.au3 #include <Constants.au3> $Win = "WinGhoster" Local $cmd1 = ' /c @for /f "tokens=2 delims={}" %1 in ( '' bcdedit.exe /create /application OSLOADER /d ' & $Win & "') do set guid={%1}" $iPID = Run(@ComSpec & $cmd1, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ProcessWait($iPID) $sErrorMsg = "" While 1 $sErrorMsg &= StdoutRead($iPID) If @error Then ExitLoop WEnd If $sErrorMsg = "" Then Exit MsgBox(0,"",$sErrorMsg) $sTxt = $sErrorMsg $sTxt = StringTrimLeft($sTxt, StringInStr($sTxt, "{")) $sTxt = StringLeft($sTxt, StringInStr($sTxt, "}") - 1) MsgBox(0,"","{"&$sTxt&"}") Edited April 17, 2011 by NDog Link to comment Share on other sites More sharing options...
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