Jump to content

Search the Community

Showing results for tags '$stdout_child'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • Forum FAQ
  • AutoIt

Calendars

  • Community Calendar

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 3 results

  1. Hey fellow scripters! I wanted to create a script to change the bitlocker PIN of our Win7 machines for users without admin rights. While researching I found out, that this doesn't seem to be an easy task. I came up with a pretty dirty solution: $gui=GUICreate("Bitlocker PIN",180,180,-1,-1,$WS_SYSMENU,-1) GUICtrlCreateLabel("PIN eingeben (min. 6 Zeichen):",15,15,150,15,-1,-1) $bit1=GUICtrlCreateInput("",15,30,150,20,$ES_PASSWORD,$WS_EX_CLIENTEDGE) GUICtrlCreateLabel("PIN bestätigen:",15,60,77,15,-1,-1) $bit2=GUICtrlCreateInput("",15,75,150,20,$ES_PASSWORD,$WS_EX_CLIENTEDGE) $button=GUICtrlCreateButton("Neue PIN Setzen",35,110,110,30, $BS_DEFPUSHBUTTON, -1) GUISetState(@SW_SHOW,$gui) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit ExitLoop Case $button $res1=GUICtrlRead($bit1) $res2=GUICtrlRead($bit2) If $res1 = $res2 And StringLen($res1) >= 6 Then GUISetState(@SW_HIDE,$gui) ClipPut ($res1) BlockInput(1) $proc=RunAs($o1acc, $domain, $o1pwd, 2, @ComSpec & " /c C:\Windows\System32\manage-bde.exe -changepin c:") WinWaitActive("C:\Windows\system32\cmd.exe","") Sleep(2000) Send ("!{Space}") Sleep(20) Send ("B") Sleep(20) Send ("E") Sleep(20) Send ("{ENTER}") Sleep(100) Send ("!{Space}") Sleep(20) Send ("B") Sleep(20) Send ("E") Sleep(20) Send ("{ENTER}") WinWaitClose("C:\Windows\system32\cmd.exe") Sleep(100) BlockInput(0) ExitLoop ElseIf StringLen($res1) < 6 Then MsgBox($MB_ICONERROR,"Fehler","PIN zu kurz. Minimum 6 Zeichen.") Else MsgBox($MB_ICONERROR,"Fehler","PINs sind nicht gleich."&@WindowsDir) EndIf EndSwitch Sleep(20) WEnd It works on my test system, but the problem here is, that a user could easily pause the script and have a nice cmd with elevated rights. So I wanted to give $STDIN_CHILD + $STDOUT_CHILD and StdoutRead + StdinWrite a try. The problem here was, that when I executed the command it would give me the following output: Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. Alle Rechte vorbehalten. C:\Windows\System32>manage-bde.exe -changepin c: BitLocker-Laufwerkverschlüsselung: Konfigurationstoolversion 6.1.7601 Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten. FEHLER: Ein Fehler ist aufgetreten (Code 0x80070006): Das Handle ist ungültig. ~ Error: An error occured (Code 0x80070006) Invalid handle . This is the code that I tried: $pid = RunAs($acc, $domain, $pwd, 2, @ComSpec, "C:\Windows\System32\", @SW_SHOW, BitOR($STDERR_CHILD, $STDIN_CHILD, $STDOUT_CHILD)) StdinWrite($pid, "manage-bde.exe -changepin c:" & @CRLF) While Sleep(50) $sOut = StdoutRead($pid) If @error Then ExitLoop If $sOut <> "" Then ConsoleWrite($sOut & @CRLF) WEnd Has anyone experienced errors like this (or has a better solution for changing the bitlocker PIN)? Regards ino
  2.  Whenever I try to run this simple command it does not work with the constants at the end. If I remove the $STDERR_CHILD and $STDOUT_CHILD, the command works but of course I can't capture the text. I've tried many ways. I have the autoconstants include declared also. I looked at other topics in the forum and many are very old but didn't seem to be this scenario. AutoIt ver 3.3.12 Local $get = Run(@ComSpec & " /c ipconfig","",@SW_SHOW,$STDERR_CHILD + $STDOUT_CHILD) While 1 $sOutput = StdoutRead($get) If @error Then ExitLoop EndIf MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $sOutput) WEnd
  3. Im trying to write a small backup program using rar.exe. I am using $STDOUT_CHILD to make a log of added/updated files. Ive looked around and googled the subject, but I cant find out why im getting trunicated data from $STDOUT_CHILD. Does anyone have any ideas as to why this is happening or another method to get the full text from rar.exe. Thanks. Im getting output like: Update Time: 0h0m4s Exit Code: 0 Log: Creating archive c:backuptest.rar Adding c:bun5120717_0001.jpg Adding c:bun5120717_0002.jpg Adding c:bun5banner.psd Adding c:bun5eula.3082 - Copy.txt Adding c:bun5eula.3082.txt Adding c:bun5PHP and MySQL by Example.pdf Adding c:bun5utorrent.exe Adding data recovery record STD STDO STDOUT: Done Update Time: 0h0m1s Exit Code: 0 Log: Updating archive c:backuptest.rar Updating c:bun5eula.1028.txt Adding data recovery rec STDO STDO STDO STD STD STDO STDO STD STDO STD STDO STDOUT: Done Other times, filenames will be missing and there will be no closing comments (ie adding data recovery ...) #include <Process.au3> #include <Timers.au3> #include <Constants.au3> Global $Pid $hour = 3600000 $Err = '' $Out = '' $EXE = 'C:Progra~1WinRARrar.exe' $SRC = 'c:bun5*.*' $DST = 'c:backuptest.rar' $OPT = ' u -r -rr5p -v4500000 -x*.bak -x*.dwl -xplot.log -xthumbs.db -x*0_Temp_Saves_0 ' & $DST & ' ' & $SRC $WRTime = 0 While 1 ;If @HOUR > 1 and @HOUR < 8 and _Timer_GetIdleTime() > 1.0*$hour and NOT ProcessExists("Rar.exe") then If not ProcessExists("Rar.exe") then $Pid = Run($EXE & ' ' & $OPT, "",@SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD) $hHandle = _ProcessGetHandle($Pid) $WRStart = _Timer_Init(); While ProcessExists("Rar.exe") $_StderrRead = StderrRead ( $Pid ) If Not @error And $_StderrRead <> '' Then $Err &= ( "STDERR: " & $_StderrRead & @Crlf ) $_StdoutRead = StdoutRead ( $Pid ) If Not @error And $_StdoutRead <> '' Then $Out &= ( "STDOUT: " & $_StdoutRead & @Crlf ) WEnd Local $WRTime = _Timer_Diff($WRStart) $iExitCode = _ProcessGetExitCode($Pid) _ProcessCloseHandle($hHandle) If $Out <> '' Then $TMP = StringReplace($Out,'',"") While StringInStr($TMP,"%") $PerLoc = StringInStr($TMP,"%") $TMP = StringReplace($TMP,StringMid($TMP,$PerLoc-4,5),"") ;removes xxx% WEnd $TMP = StringReplace($TMP, ' OK ','') $TMP = StringReplace($TMP, 'STDOUT:' & @CRLF,'') $TMP = StringReplace($TMP, 'STDOUT: ' & @CRLF,'') $TMP = StringReplace($TMP, 'STDOUT: ' & @CRLF,'') EndIf $LOG = FileOpen('c:backup' & @MDAY & '-' & @Mon & '-' & @Year & '.log',1) FileWrite($LOG, 'Update Time: ' & Time_Convert($WRTime) & @CRLF & 'Exit Code:' & @CRLF & $iExitCode & @CRLF & 'Log:' & @CRLF & $TMP & @CRLF & @CRLF ) FileClose($LOG) Sleep(12 * $hour) EndIf Sleep(0.5 * $hour) WEnd ; #FUNCTION# ==================================================================================================================== ; Name...........: _ProcessGetHandle() ; Description ...: Returns a handle from use of Run(). ; Syntax.........: _ProcessGetHandle($iPID) ; Parameters ....: $iPID - ProcessID returned from a Run() execution ; Return values .: On Success - Returns Process handle while Run() is executing (use above directly after Run() line with only PID parameter) ; On Failure - 0 ; Author ........: MHz (Thanks to DaveF for posting these DllCalls in Support Forum) ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _ProcessGetHandle($iPID) ;Return handle of given PID Local Const $PROCESS_QUERY_INFORMATION = 0x0400 Local $avRET = DllCall("kernel32.dll", "ptr", "OpenProcess", "int", $PROCESS_QUERY_INFORMATION, "int", 0, "int", $iPID) If @error Then Return SetError(1, 0, 0) Else Return $avRET[0] EndIf EndFunc ;==>_ProcessGetHandle ; #FUNCTION# ==================================================================================================================== ; Name...........: _ProcessCloseHandle() ; Description ...: Closes a handle from use of Run(). ; Syntax.........: _ProcessCloseHandle($hProc) ; Parameters ....: $hProc - Process handle ; Return values .: On Success - Closes Process handle after a Run() has executed.; ; On Failure - 0 ; Author ........: MHz (Thanks to DaveF for posting these DllCalls in Support Forum), PsaltyDS ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _ProcessCloseHandle($hProc) ;Close process handle Local $avRET = DllCall("kernel32.dll", "int", "CloseHandle", "ptr", $hProc) If @error Then Return SetError(1, 0, 0) Else Return 1 EndIf EndFunc ;==>_ProcessCloseHandle ; #FUNCTION# ==================================================================================================================== ; Name...........: _ProcessGetExitCode() ; Description ...: Returns a handle/exitcode from use of Run(). ; Syntax.........: _ProcessGetExitCode($hProc) ; Parameters ....: $hProc - Process handle ; Return values .: On Success - Returns Process Exitcode when Process does not exist. ; On Failure - 0 ; Author ........: MHz (Thanks to DaveF for posting these DllCalls in Support Forum), PsaltyDS ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _ProcessGetExitCode($hProc) ;Get process exit code from handle Local $t_ExitCode = DllStructCreate("int") Local $avRET = DllCall("kernel32.dll", "int", "GetExitCodeProcess", "ptr", $hProc, "ptr", DllStructGetPtr($t_ExitCode)) If @error Then Return SetError(1, 0, 0) Else Return DllStructGetData($t_ExitCode, 1) EndIf EndFunc ;==>_ProcessGetExitCode Func Time_Convert($TimeDiff) $hrs = 0 $min = 0 $sec= Round($TimeDiff/1000,0) if $sec>59 then $hrs = int($sec / 3600) $sec = $sec - $hrs * 3600 $min = int($sec / 60) $sec = $sec - $min * 60 EndIf return $hrs & "h" & $min & "m" & $sec & "s" EndFunc
×
×
  • Create New...