Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/11/2013 in all areas

  1. ptrex

    Powershell - COM

    Powershell - COM Many Windows Business Application are now only supporting Powershell, as a scripting environment. Like MS Exchange / SharePoint / Active Directory / MS SQL / etc. This makes Au3 a handicapped scripting environment for administrators to work with. But hold on ! Since 2008 Sapien Technologies has released a Powershell COM component named ActiveXPoSH, that makes the bridge between all Download here http://www.sapien.com/blog/2008/06/25/activexposh-is-now-a-free-download/ First register an account before getting the download access http://www.sapien.com/auth Why would you need Au3 to join PS1 ? Well it is a hell lot easier to create GUI's in AU3 than it is in PS1, so let's marry the 2. Here's an example script translated from there help file to AU3 ;************************************************************************** ; Copyright (c) SAPIEN Technologies, Inc. All rights reserved ; This file is part of the PrimalScript 2007 Code Samples. ; ; File: ActiveXposh.vbs ; ; Comments: ; ; Disclaimer: This source code is intended only as a supplement to ; SAPIEN Development Tools and/or on-line documentation. ; See these other materials for detailed information ; regarding SAPIEN code samples. ; ; THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY ; KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE ; IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A ; PARTICULAR PURPOSE. ;************************************************************************** #AutoIt3Wrapper_UseX64=N Dim $ActiveXPosh Const $OUTPUT_CONSOLE = 0 Const $OUTPUT_WINDOW = 1 Const $OUTPUT_BUFFER = 2 Func CreateActiveXPosh() Dim $success ; Create the PowerShell connector object $ActiveXPosh = ObjCreate("SAPIEN.ActiveXPoSH") $success = $ActiveXPosh.Init(False) ;Do not load profiles If $success <> 0 then Consolewrite( "Init failed" & @CR) endif If $ActiveXPosh.IsPowerShellInstalled Then Consolewrite( "Ready to run PowerShell commands" & @CR) Else Consolewrite( "PowerShell not installed" & @CR) EndIf ; Set the output mode $ActiveXPosh.OutputMode = $OUTPUT_CONSOLE EndFunc Func DownloadFile($URL,$Destination) Local $Return Dim $Command Dim $FSO ;Download a file with PowerShell $ActiveXPosh.Execute("$Client = new-object System.Net.WebClient") ;Note that variables are preserved between calls ; Construct a $Command $Command = "$Client.DownloadFile('" & $URL & "','" & $Destination & "')" ConsoleWrite ("Downloading ..." & @CR) $ActiveXPosh.Execute($Command) $FSO = ObjCreate("Scripting.FileSystemObject") If $FSO.FileExists($Destination) Then ConsoleWrite ("File transfer complete" & @CR) Else ConsoleWrite ("File Transfer failed" & @CR) EndIf Return $Return EndFunc Func ListServices() Dim $outtext ; Set the $OUTPUT mode to $BUFFER $ActiveXPosh.OutputMode = $OUTPUT_BUFFER $ActiveXPosh.Execute("Get-WmiObject -class Win32_Service | Format-Table -property Name, State") ; Get the $OUTPUT line by line and add it to a variable For $str In $ActiveXPosh.OUTPUT() $outtext = $outtext & $str $outtext = $outtext & @CRLF Next ; Alternatively you can get the $OUTPUT as a single String ; $outtext = $ActiveXPosh.OutputString ConsoleWrite ($outtext & @CR) $ActiveXPosh.ClearOutput() ; Empty the $OUTPUT $BUFFER EndFunc ; Create the actual Object CreateActiveXPosh() $Status = $ActiveXPosh.GetValue("(Get-Service UPS).Status") if($Status = "Stopped") then ConsoleWrite ("UPS Service is stopped" & @CR) else ConsoleWrite ("UPS Service is " & $Status & @CR) EndIf ; List all running processes using PowerShell $ActiveXPosh.Execute("Get-Process") ; Check if WinWord is running using PowerShell if $ActiveXPosh.Eval("get-process winword") = 1 Then ConsoleWrite ("Microsoft Word is running" & @CR) Else ConsoleWrite ("Microsoft Word is not running" & @CR) EndIf DownloadFile ("[url="http://izzy.org/scripts/PowerShell/activexposh.pdf","C:\Temp\activexposh.pdf"]http://izzy.org/scripts/PowerShell/activexposh.pdf","C:\Temp\activexposh.pdf[/url]") ; Use ListServices to show all services in this machine using PowerShell() ListServices() ConsoleWrite ("Version " & $ActiveXPosh.GetValue("$PSHOME") & @CR) $ActiveXPosh = "" Example how to load a PS1 command file #AutoIt3Wrapper_UseX64=N Dim $ActiveXPosh Const $OUTPUT_CONSOLE = 0 Const $OUTPUT_WINDOW = 1 Const $OUTPUT_BUFFER = 2 Func CreateActiveXPosh() Local $success ; Create the PowerShell connector object $ActiveXPosh = ObjCreate("SAPIEN.ActiveXPoSH") $success = $ActiveXPosh.Init(False) ;Do not load profiles If $success <> 0 then Consolewrite( "Init failed" & @CR) endif If $ActiveXPosh.IsPowerShellInstalled Then Consolewrite( "Ready to run PowerShell commands" & @CR & @CR) Else Consolewrite( "PowerShell not installed" & @CR & @CR) EndIf ; Set the output mode $ActiveXPosh.OutputMode = $OUTPUT_CONSOLE $ActiveXPosh.OutputWidth = 250 EndFunc ; Create the actual Object CreateActiveXPosh() $PS1 = FileOpenDialog("Open PS1 Script", @ScriptDir & "\", "PS Scripts (*.ps1)") PowerShell_Script($PS1) Func PowerShell_Script($hPSFile) $file = FileOpen($hPSFile, 0) ; Open read only If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf Local $sCmd While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $sCmd &= $line & @CRLF Wend ; ConsoleWrite("Line read: " & @CRLF & $sCmd & @CRLF) FileClose($file) ExecuteCMD($sCmd) EndFunc Func ExecuteCMD($sPSCmd) Dim $outtext ; Set the $OUTPUT mode to $BUFFER $ActiveXPosh.OutputMode = $OUTPUT_BUFFER $ActiveXPosh.Execute($sPSCmd) ; Get the $OUTPUT line by line and add it to a variable For $str In $ActiveXPosh.OUTPUT() $outtext = $outtext & $str $outtext = $outtext & @CRLF Next ; Alternatively you can get the $OUTPUT as a single String ; $outtext = $ActiveXPosh.OutputString ConsoleWrite ($outtext & @CR) $ActiveXPosh.ClearOutput() ; Empty the $OUTPUT $BUFFER EndFunc I am running this from component from my Windows 7 x64 bit Powershell 3.0 version, and it still is working fine. Enjoy ! ptrex
    1 point
  2. Melba23

    ProcessWaitClose

    douma2010, Why not read the Help file pages on the functions JohnOne suggested and try to code something yourself? That way you get to learn something new. We are here to help if you run into difficulties - but we will not write it for you. M23
    1 point
  3. Sure. here you go http://www.autoitscript.com/wiki/FAQ#When_should_I_bump_my_threads.3F
    1 point
  4. You already asked this on the GUI forum. Please don't open a second thread, just ask a Mod to move the thread if it's on the wrong forum.
    1 point
  5. ahmeddzcom, I don't do a lot in batch, but it appears you're trying to shut down a machine if it's computername matches "MiniXP" to a certain number of characters, is this correct? If so, I would suggest looking first in the help file for StringinStr: something like this (pseudocode) If part of the @COMPUTERNAME = "MiniXP" Then ... Once you have this piece down, take a look at Shutdown() in the help file. You can use this to mimic the shutdown command in your batch file.
    1 point
  6. glad to be of service regards
    1 point
  7. Try this Alt + Pause - Quit the script #include <BlockInputEx.au3> Global $Paused = False, $iBlocked = True, $iExit_Timeout = 11000 ;11secs HotKeySet("{PAUSE}", "TogglePause") HotKeySet("!{PAUSE}", "Quit") ;All keyboard keys and mouse clicks are blocked except these keys: 0x13 = {PAUSE} _BlockInputEx(1, "0xA4|0x13") AdlibRegister("Quit", $iExit_Timeout) ;~ MsgBox(64 , '', $ah_MouseKeyboard_WinHooks[5], 5 ) While 1 If $Paused Then While $Paused Sleep(10) If $iBlocked Then _BlockInputEx(0) $iBlocked = False ToolTip('Script is Paused', 1047, 0, " Warning", 0, 4) AdlibRegister("Tip", 4000) EndIf WEnd ElseIf Not $iBlocked Then _BlockInputEx(1, "0xA4|0x13") Tip() $iBlocked = True EndIf WEnd Func TogglePause() $Paused = Not $Paused EndFunc ;==>TogglePause Func Tip() ToolTip('') AdlibUnRegister("Tip") EndFunc ;==>Tip Func Quit() _BlockInputEx(0) Exit EndFunc ;==>QuitYou forgot one thing, when we press Ctrl+Pause ETX is posted not pause neither ctrl. the hex code for ETX is 0x03 but when you add it to the exclude list, the combination would be posted but the hotkey would not be triggered. Simultaneously Scite even uses Ctrl+Break to exit the script I therefore used Alt+Pause and the hex code for Alt is 0xA4 Hope this helps Regards Phoenix XL
    1 point
  8. #include<array.au3> global $aPerson[2][2] $aPerson[0][0] = 'name' $aPerson[0][1] = 'persons name' $aPerson[1][0] = 'address' $aPerson[1][1] = "My Adress" _ArrayDisplay($aPerson)
    1 point
  9. Try this: $String = '<Eq ID="DE1"><EqSource Format="TEX"><![CDATA[ $$\begin{array}{*{20}l} Kw+Pa &= V,\\ P^Tw &= 0, \end{array} $$ ]]></EqSource></Eq>' $String = StringReplace($String, '<EqSource Format="TEX">','<Source Format="LATEX">') $String = StringReplace($String, '</EqSource>', "</Source>") MsgBox(0, "New String", "Newstring is: " & $String) Hi!
    1 point
  10. Not sure I really understand, but have you looked at the function StringReplace()? Maybe this will get you started? $string = '<Eq ID="DE1"><EqSource Format="TEX"><![CDATA[ $$\begin{array}{*{20}l} Kw+Pa &= V,\\ P^Tw &= 0, \end{array} $$ ]]></EqSource></Eq>' $StringSearch = '<EqSource Format="TEX">' $StringReplace = '= <Source Format="LATEX">' StringReplace ( $string, $StringSearch, $StringReplace)
    1 point
  11. Disks not showing up in XP has been fixed. Have a few more things to finish up and test abefore I release version 0.4.
    1 point
  12. Use FileReadLine to read a line to a variable and then pass this variable to _IEFormElementSetValue.
    1 point
  13. Client-side image map links are part of the document links collection, so you can get the collection, loop through looking for what you want and click on it: $oLinks = _IELinkGetCollection($oIE) For $oLink in $oLinks If String($oLink.title) = "X" then _IEAction($oLink, "click") Next Dale p.s. you could also just figure out the href you want and use _IENavigate p.p.s.s. You can also use _IEPropertyGet to get the screen coordinates of the MAP element and then use MouseClick() to click on the correct screen coordinate
    1 point
×
×
  • Create New...