Leaderboard
Popular Content
Showing content with the highest reputation on 01/31/2024 in all areas
-
Thank you for your diligent assistance, ioa747! I am over the hump with this script. Here is what is currently working for me: ; split RTF ;------------------------------------------------------------ SplitIt(@ScriptDir & "\test.rtf") Func SplitIt($sFilePath) ; Open the file for reading and store the handle to a variable Local $hFileOpen = FileOpen($sFilePath, $FO_READ) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.") Return False EndIf ; Read the contents of the file using the handle returned by FileOpen Local $sFileTxt = FileRead($hFileOpen) ; Close the handle returned by FileOpen. FileClose($hFileOpen) Local $sDelim, $aSplit, $sNewRtf, $iPageBr ; open rtf in Notepad++ and find formatting for delimiter line $sDelim = "\pard\qc\b Official: " $aSplit = StringSplit($sFileTxt, $sDelim, 1) $header = $aSplit[1] If UBound($aSplit) > 2 Then For $i = 2 To UBound($aSplit) - 1 $sNewRtf = $header & $sDelim & $aSplit[$i] ; find page breaks $iPageBr = StringInStr($sNewRtf, "\page", 0, -1) If $iPageBr = 0 Then ; no page break so this is the last iteration ; output normally $sNewRtf = $sNewRtf Else ; page breaks found so this is not the last iteration ; remove page break and close $sNewRtf = StringLeft($sNewRtf, $iPageBr) & "}}" EndIf Local $sNewFilePath = StringTrimRight($sFilePath, 4) & "_" & $i & ".rtf" If FileExists($sNewFilePath) Then FileDelete($sNewFilePath) FileWrite($sNewFilePath, $sNewRtf) Next EndIf EndFunc1 point
-
Intermittent problem running Powershell scripts
VeeDub reacted to argumentum for a topic
$VmNamed = "ALR_CyberX_DR3-4" $sRet = _RunWaitEx('powershell "Get-VM -name ' & $VmNamed & '"')1 point -
Intermittent problem running Powershell scripts
VeeDub reacted to argumentum for a topic
You've got the examples in my prior posts. All the if/then/else I did in AutoIt. I'd run a command, get the result and take it from there. The Local $Command = 'powershell "$VMName = " & $ALR_Host_VM & should be Local $Command = 'powershell "$VMName = ' & $ALR_Host_VM & ' " '. Pay attention to the " and ' characters. '"Get-VM -name ''$VMName''" the -ErrorAction SilentlyContinue I would not add. Because you'd handle the if/then/else in AutoIt, else just run PS1s. =/ Or explain what is that you'd like to have and I'll look at coding it on Thursday/Friday when I get some time to try out stuff.1 point -
Intermittent problem running Powershell scripts
argumentum reacted to VeeDub for a topic
I think I will try your suggestion instead. If nothing else I will be able to query the return code if the behaviour continues. Thanks!1 point -
Intermittent problem running Powershell scripts
VeeDub reacted to argumentum for a topic
;~ Local $sRet = _RunWaitEx('powershell "Get-VMHost | Select-Object * | ConvertTo-CSV"') ;~ Local $sRet = _RunWaitEx('powershell "Get-VMHost | Select-Object * | ConvertTo-JSON"') ;~ Local $sRet = _RunWaitEx('powershell "get-vm | Select-Object * | ConvertTo-CSV"') ; <<<< ;~ Local $sRet = _RunWaitEx('powershell "Get-VMDvdDrive -VmName * | Select-Object * | ConvertTo-CSV"') ; <<<< ;~ Local $sRet = _RunWaitEx('powershell "Get-VMHardDiskDrive -VmName * | Select-Object * | ConvertTo-CSV"') ; <<<< ;~ Local $sRet = _RunWaitEx('powershell "get-vm | Select-Object * | ConvertTo-JSON"') ;~ Local $sRet = _RunWaitEx('powershell "Get-VMSnapshot -VmName * | Select-Object * | ConvertTo-CSV"') ; <<<<< ;~ Local $sRet = _RunWaitEx('powershell ' & '"Get-VMHardDiskDrive -VMId ''a069108d-c6fd-4385-a817-c1c4cf4f5fa5'' | Select-Object * | ConvertTo-CSV"') ;~ Local $sRet = _RunWaitEx('powershell ' & '"Get-VMHardDiskDrive -VMName ''New Virtual Machine'' | Select-Object * | ConvertTo-CSV"') You can run things like this. No need to run PS1 files and actually I prefer to avoid them. The above is something I started some time ago and never continued but do remember that was better to skip the PS1s, if I was gonna use AutoIt for the logic anyway. My 2 cents1 point -
Intermittent problem running Powershell scripts
argumentum reacted to VeeDub for a topic
I have found this Start-Transcript -Path "Drive:\Folder\Transcript.txt" ## YOUR EXISTING CODE ## Stop Transcript Am going to try it.1 point -
Intermittent problem running Powershell scripts
argumentum reacted to VeeDub for a topic
Unfortunately the issue still exists. Ran the AutoIt program yesterday, 5 VM's were managed, so that means there were 15 Powershell script operations and all completed correctly. Ran the AutoIt program today, and on the 5th VM, the second Powershell script did not update correctly. The second Powershell script is supposed to update the VM boot device. In this instance this didn't happen. I call this Powershell script 5 times, because since I've become aware of this issue, I'm trying to work out a way to ensure that the script actions are performed. So the script was called 5 times, but didn't update the boot device. No errors were reported. 2024-01-31 Wed 11:12 Set VM boot device to DVD 2024-01-31 Wed 11:12 @error: 0 2024-01-31 Wed 11:12 Exitcode: 0 2024-01-31 Wed 11:12 Exitcode: 0 2024-01-31 Wed 11:12 Output: 2024-01-31 Wed 11:12 @error: 0 2024-01-31 Wed 11:12 Exitcode: 0 2024-01-31 Wed 11:12 Exitcode: 0 2024-01-31 Wed 11:12 Output: 2024-01-31 Wed 11:12 @error: 0 2024-01-31 Wed 11:12 Exitcode: 0 2024-01-31 Wed 11:12 Exitcode: 0 2024-01-31 Wed 11:12 Output: 2024-01-31 Wed 11:12 @error: 0 2024-01-31 Wed 11:12 Exitcode: 0 2024-01-31 Wed 11:12 Exitcode: 0 2024-01-31 Wed 11:12 Output: 2024-01-31 Wed 11:12 @error: 0 2024-01-31 Wed 11:12 Exitcode: 0 2024-01-31 Wed 11:12 Exitcode: 0 2024-01-31 Wed 11:12 Output: The logging above is identical to the logged entries when the boot device has been successfully updated for earlier VM's.1 point -
You can create a GUI with three read only edit controls and put there the result of Ping() function. For reference look in help file for GUICreate(), GUICtrlCreateEdit(), Ping() and GUICtrlSetData(). Something like this: #include <GuiIPAddress.au3> #include <EditConstants.au3> #include <GUIConstants.au3> #include <WindowsConstants.au3> Global $fPinging = False Global $sIP1, $sIP2, $sIP3 Global $iUpdateRate = 3000 ; ms Global $iTimer $hMain = GUICreate('Ping', 490, 340) $hIP1 = _GUICtrlIpAddress_Create($hMain, 10, 10, 150, 25) $hIP2 = _GUICtrlIpAddress_Create($hMain, 170, 10, 150, 25) $hIP3 = _GUICtrlIpAddress_Create($hMain, 330, 10, 150, 25) $cEdit1 = GUICtrlCreateEdit('', 10, 45, 150, 240, BitOR($WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY)) $cEdit2 = GUICtrlCreateEdit('', 170, 45, 150, 240, BitOR($WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY)) $cEdit3 = GUICtrlCreateEdit('', 330, 45, 150, 240, BitOR($WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY)) $cPingButton = GUICtrlCreateButton('Start pinging', 170, 295, 150, 35) GUICtrlSetBkColor($cEdit1, 0xFFFFFF) GUICtrlSetBkColor($cEdit2, 0xFFFFFF) GUICtrlSetBkColor($cEdit3, 0xFFFFFF) GUISetState(@SW_SHOW, $hMain) _GUICtrlIpAddress_Set($hIP1, '142.251.208.110') _GUICtrlIpAddress_Set($hIP2, '74.6.143.26') _GUICtrlIpAddress_Set($hIP3, '20.231.239.246') While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GUICtrlIpAddress_Destroy($hIP1) _GUICtrlIpAddress_Destroy($hIP2) _GUICtrlIpAddress_Destroy($hIP3) Exit Case $cPingButton $fPinging = Not $fPinging GUICtrlSetData($cPingButton, $fPinging ? 'Stop pinging' : 'Start pinging') $sIP1 = _GUICtrlIpAddress_Get($hIP1) $sIP2 = _GUICtrlIpAddress_Get($hIP2) $sIP3 = _GUICtrlIpAddress_Get($hIP3) If $fPinging Then PingIPs($cEdit1, $cEdit2, $cEdit3) EndSwitch If $fPinging And TimerDiff($iTimer) >= $iUpdateRate Then PingIPs($cEdit1, $cEdit2, $cEdit3) WEnd Func PingIPs($cEdit1, $cEdit2, $cEdit3) GUICtrlSetData($cEdit1, Ping($sIP1) & @CRLF, 1) GUICtrlSetData($cEdit2, Ping($sIP2) & @CRLF, 1) GUICtrlSetData($cEdit3, Ping($sIP3) & @CRLF, 1) $iTimer = TimerInit() EndFunc1 point
-
Hi ur, I prefer not to rely on external programs/tools so let me share an alternative approach to cmdkey.exe. I didn't write this, but I modified it to work for my needs. In my script I actually encrypt the password prior to storing it. Hopefully, this will make it easier for you. #include <Array.au3> $User = "user1" $Password = "password1" $AppName = "My App" $Comment = "Used For ABC" _Cred_Write($User, $Password) ; Write to Crediential Manager $aArray = _Cred_Read() ; Read from Crediential Manager _ArrayDisplay($aArray) _Cred_Delete() ; Delete Credientials Func _Cred_Write($User, $Password, $iPersist = 1, $Target = $AppName, $Comm = $Comment) ; iPersist ; SESSION = 1 ; LOCAL_MACHINE = 2 ; ENTERPRISE = 3 Local $Comment = DllStructCreate("wchar[100]") DllStructSetData($Comment, 1, $Comm) Local $targetName = DllStructCreate("wchar[100]") DllStructSetData($targetName, 1, $Target) Local $userName = DllStructCreate("wchar[100]") DllStructSetData($userName, 1, $User) Local $credentialBlob = DllStructCreate("wchar[100]") DllStructSetData($credentialBlob, 1, $Password) Local $structCREDENTIAL = "" & _ "DWORD Flags;" & _ "DWORD Type;" & _ "Ptr TargetName;" & _ "Ptr Comment;" & _ "UINT64 LastWritten;" & _ "DWORD CredintialBlobSize;" & _ "Ptr CredentialBlob;" & _ "DWORD Persist;" & _ "DWORD AttributeCount;" & _ "ptr Attributes;" & _ "Ptr TargetAlias;" & _ "Ptr Username" Local $NewCred = DllStructCreate($structCREDENTIAL) If @error Then MsgBox(0, "NewCred", "Error in DllStructCreate " & @error) ; Exit EndIf DllStructSetData($NewCred, "Flags", 0) DllStructSetData($NewCred, "Type", 1) DllStructSetData($NewCred, "TargetName", DllStructGetPtr($targetName)) DllStructSetData($NewCred, "Persist", $iPersist) DllStructSetData($NewCred, "AttributeCount", 0) DllStructSetData($NewCred, "UserName", DllStructGetPtr($userName)) DllStructSetData($NewCred, "CredentialBlob", DllStructGetPtr($credentialBlob)) DllStructSetData($NewCred, "CredintialBlobSize", StringLen($Password) * 2) DllStructSetData($NewCred, "Comment", DllStructGetPtr($Comment)) #comments-start MsgBox(0, "DllStruct", "Data:" & @CRLF & _ "Flags: " & DllStructGetData($NewCred, "Flags") & @CRLF & _ "Type: " & DllStructGetData($NewCred,"Type") & @CRLF & _ "TargetName: " & DllStructGetData($NewCred,"TargetName") & @CRLF & _ "Persist: " & DllStructGetData($NewCred,"Persist") & @CRLF & _ "AttributeCount: " & DllStructGetData($NewCred,"AttributeCount") & @CRLF & _ "UserName: " & DllStructGetData($NewCred,"UserName") & @CRLF & _ "CredentialBlob: " & DllStructGetData($NewCred,"CredentialBlob") & @CRLF & _ "CredintialBlobSize: " & DllStructGetData($NewCred,"CredintialBlobSize") & @CRLF & _ "Comment: " & DllStructGetData($NewCred,"Comment")) #comments-end Local $hAdvapi32 = DllOpen("Advapi32.dll") If @error Then MsgBox(0, "Error", "Cannot open Advapi32.dll") Exit EndIf Local $aRet = DllCall($hAdvapi32, 'bool', 'CredWriteW', 'ptr', DllStructGetPtr($NewCred), 'dword', 0) $NewCred = 0 EndFunc Func _Cred_Read($Target = $AppName) Local $aFuncRet[3] Local $iType = 1 ; 1 = Generic | 2 = Domain | 3 = Certificate Local $targetName = DllStructCreate("wchar[100]") DllStructSetData($targetName, 1, $Target) Local $hAdvapi32 = DllOpen("Advapi32.dll") Local $aRet = DllCall($hAdvapi32, 'bool', 'CredReadW', 'ptr', DllStructGetPtr($targetName), 'dword', $iType, 'dword', 0, 'ptr*', 0) If $aRet[0] = 0 Then Return SetError(1, 0) Local $structCREDENTIAL = "" & _ "DWORD Flags;" & _ "DWORD Type;" & _ "Ptr TargetName;" & _ "Ptr Comment;" & _ "UINT64 LastWritten;" & _ "DWORD CredintialBlobSize;" & _ "Ptr CredentialBlob;" & _ "DWORD Persist;" & _ "DWORD AttributeCount;" & _ "Ptr Attributes;" & _ "Ptr TargetAlias;" & _ "Ptr Username" Local $tdata = DllStructCreate($structCREDENTIAL, $aRet[4]) Local $userName = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'Username')) Local $sUser = DllStructGetData($userName, 1) Local $CredentialBlobSize = DllStructGetData($tdata, 'CredintialBlobSize') Local $credentialBlob = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'CredentialBlob')) Local $sPassword = StringLeft(DllStructGetData($credentialBlob, 1), $CredentialBlobSize / 2) Local $Comment = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'Comment')) Local $sComm = DllStructGetData($Comment, 1) Dim $aFuncRet[] = [$sUser, $sPassword, $sComm] Return $aFuncRet EndFunc Func _Cred_Delete($Target = $AppName) Local $aRet Local $targetName = DllStructCreate("wchar[100]") DllStructSetData($targetName, 1, $Target) Local $hAdvapi32 = DllOpen("Advapi32.dll") $aRet = DllCall($hAdvapi32, 'bool', 'CredDeleteW', 'ptr', DllStructGetPtr($targetName), 'dword', 1, 'dword', 0) EndFunc1 point
-
I really don't know why the structure has no the data(I just see a little bit), but if you do something like this can see that you want: Func CredRead($Target) Local $targetName = DllStructCreate("wchar[100]") DllStructSetData($targetName,1,$Target) Local $Comment = DllStructCreate("wchar[100]") Local $userName = DllStructCreate("wchar[100]") Local $credentialBlob = DllStructCreate("wchar[100]") Local $structCREDENTIAL= "" & _ "DWORD Flags;" & _ "DWORD Type;" & _ "Ptr TargetName;" & _ "Ptr Comment;" & _ "UINT64 LastWritten;" & _ "DWORD CredintialBlobSize;" & _ "Ptr CredentialBlob;" & _ "DWORD Persist;" & _ "DWORD AttributeCount;" & _ "ptr Attributes;" & _ "Ptr TargetAlias;" & _ "Ptr Username" ;~ Local $OutCred = DllStructCreate($structCREDENTIAL) ;~ DllStructSetData($OutCred,"TargetName",DllStructGetPtr($targetName)) ;~ DllStructSetData($OutCred,"UserName",DllStructGetPtr($userName)) ;~ DllStructSetData($OutCred,"CredentialBlob",DllStructGetPtr($credentialBlob)) ;~ DllStructSetData($OutCred,"Comment",DllStructGetPtr($Comment)) Local $hAdvapi32 = DllOpen("Advapi32.dll") $Ret = DllCall($hAdvapi32, 'bool', 'CredReadW', 'ptr', DllStructGetPtr($targetName), 'dword', 1, 'dword', 0, 'ptr*', 0) _ArrayDisplay($Ret) Local $tdata=DllStructCreate("byte[200]",$Ret[4]) FileWrite("data.txt",(DllStructGetData($tdata,1))) ShellExecute("data.txt") Return 0 EndFunc Saludos1 point
-
I was able to use that code to do CredWrite successfully and even got CredDelete to work, but I can't get CredRead to work. You can see the entry written appear in windows control panel->credential manager. Here is what I have so far: #include <array.au3> ;~ CredWrite("MeinServer", "MeineDomain\MeinUser", "MeinPWD", "mein Kommentar") ;~ CredDelete("MeinServer") CredRead("MeinServer") Func CredRead($Target) Local $targetName = DllStructCreate("wchar[100]") DllStructSetData($targetName,1,$Target) Local $Comment = DllStructCreate("wchar[100]") Local $userName = DllStructCreate("wchar[100]") Local $credentialBlob = DllStructCreate("wchar[100]") Local $structCREDENTIAL= "" & _ "DWORD Flags;" & _ "DWORD Type;" & _ "Ptr TargetName;" & _ "Ptr Comment;" & _ "UINT64 LastWritten;" & _ "DWORD CredintialBlobSize;" & _ "Ptr CredentialBlob;" & _ "DWORD Persist;" & _ "DWORD AttributeCount;" & _ "ptr Attributes;" & _ "Ptr TargetAlias;" & _ "Ptr Username" Local $OutCred = DllStructCreate($structCREDENTIAL) DllStructSetData($OutCred,"TargetName",DllStructGetPtr($targetName)) DllStructSetData($OutCred,"UserName",DllStructGetPtr($userName)) DllStructSetData($OutCred,"CredentialBlob",DllStructGetPtr($credentialBlob)) DllStructSetData($OutCred,"Comment",DllStructGetPtr($Comment)) Local $hAdvapi32 = DllOpen("Advapi32.dll") $Ret = DllCall($hAdvapi32, 'bool', 'CredReadW', 'ptr', DllStructGetPtr($targetName), 'dword', 1, 'dword', 0, 'ptr', DllStructGetPtr($OutCred)) _ArrayDisplay($Ret) $user = DllStructGetData($userName, 1) ConsoleWrite( $user & @CR) Return $user EndFunc func CredDelete($Target) Local $targetName = DllStructCreate("wchar[100]") DllStructSetData($targetName,1,$Target) Local $hAdvapi32 = DllOpen("Advapi32.dll") $Ret = DllCall($hAdvapi32, 'bool', 'CredDeleteW', 'ptr', DllStructGetPtr($targetName), 'dword', 1, 'dword', 0) EndFunc Func CredWrite($Target, $User, $Password, $Comm) Local $targetName = DllStructCreate("wchar[100]") DllStructSetData($targetName,1,$Target) Local $userName = DllStructCreate("wchar[100]") DllStructSetData($userName,1,$User) Local $credentialBlob = DllStructCreate("wchar[100]") DllStructSetData($credentialBlob,1,$Password) Local $Comment = DllStructCreate("wchar[100]") DllStructSetData($Comment,1,$Comm) Local $structCREDENTIAL= "" & _ "DWORD Flags;" & _ "DWORD Type;" & _ "Ptr TargetName;" & _ "Ptr Comment;" & _ "UINT64 LastWritten;" & _ "DWORD CredintialBlobSize;" & _ "Ptr CredentialBlob;" & _ "DWORD Persist;" & _ "DWORD AttributeCount;" & _ "ptr Attributes;" & _ "Ptr TargetAlias;" & _ "Ptr Username" Local $NewCred = DllStructCreate($structCREDENTIAL) If @error Then MsgBox(0, "NewCred", "Error in DllStructCreate " & @error); Exit EndIf DllStructSetData($NewCred,"Flags",0) DllStructSetData($NewCred,"Type",1) DllStructSetData($NewCred,"TargetName",DllStructGetPtr($targetName)) DllStructSetData($NewCred,"Persist",3) DllStructSetData($NewCred,"AttributeCount",0) DllStructSetData($NewCred,"UserName",DllStructGetPtr($userName)) DllStructSetData($NewCred,"CredentialBlob",DllStructGetPtr($credentialBlob)) DllStructSetData($NewCred,"CredintialBlobSize",StringLen($Password)*2) DllStructSetData($NewCred,"Comment",DllStructGetPtr($Comment)) Local $hAdvapi32 = DllOpen("Advapi32.dll") If @error Then Msgbox (0,"Error","Cannot open Advapi32.dll") Exit Endif $Ret = DllCall($hAdvapi32, 'bool', 'CredWriteW', 'ptr', DllStructGetPtr($NewCred), 'dword', 0) $NewCred = 0 EndFunc The DLL call to CredReadW will only return 1 if I call it with a Targetname for a credential that actually exists so I believe that it is working but I can't seem to get the data out of the output Credential struct. Or at least I think its a struct... For CredWrite MSDN says that the PCREDENTIAL parameter is pointer to a credential structure but for CredRead it says that PCREDENTIAL is a "Pointer to a single allocated block buffer to return the credential." Is this a pointer to a credential structure or something else? Does anyone know? Either that or it is a pointer to a struct and I just can't get the data out. What is confusing me is that the credential structure has pointers to other structures/data types. What I did is create the other datatypes (like strings) and put their pointers into a credential structure and then pass the pointer of that credential structure to the CredRead function. I expected that the data I was interested in would be in the first data structures I made after the dll call was successful, but they contain nothing or a null string. Is this the correct way to do this? Here is some code on stackoverflow that does credwrite and credread in C? or some other language.1 point