
garbb
Active Members-
Posts
61 -
Joined
-
Last visited
Everything posted by garbb
-
Strangely I was unable to get the correct OTP code to be generated until I uncommented the _b32toh() code and replaced $key = _Base32ToHex($key, True) with $key = Binary('0x'&_b32toh($key)) in GenerateTOTP(). EDIT: The problem appears to be that but _b32toh("JBSWY3DPEHPK3PXP") = 0x48656C6C6F21DEADBEEF, but _Base32ToHex("JBSWY3DPEHPK3PXP") = 0x48656C6C6F21DEADBE8145. I do not know why...
-
Here is my goofy workaround for a try catch type block: And yes I know this thread is ancient...but it is the first google search result for me for autoit try catch so I though others searching might find it useful. Global $_TRY = False Global $_CATCH = False func myfunc1() If $_TRY And $_CATCH Then Return SetError(1) ConsoleWrite('run func1 stuff here...' & @CRLF) Local $error_condition = True If $error_condition Then SetError(1) If $_TRY Then $_CATCH = True EndIf EndFunc func myfunc2() If $_TRY And $_CATCH Then Return SetError(1) ConsoleWrite('run func2 stuff here...' & @CRLF) Local $error_condition = False If $error_condition Then SetError(1) If $_TRY Then $_CATCH = True EndIf EndFunc $_TRY = True ; try block start myfunc1() myfunc2() $_TRY = False ; try block end ; catch If $_CATCH Then ConsoleWrite('handle error' & @CRLF) EndIf $_CATCH = False ; reset flag for use in next try-catch block Output: run func1 stuff here... handle error I am sure someone could improve upon this.
-
I have found that this seems to sort of work in current windows 10 when running with autoit 32 bit, however when you attempt to open a file open dialog (either with autoit via FileOpenDialog() or the open/save dialog of a child process) then it will cause the process to crash. However it will still sort of work: for example I can run cmd.exe as a child process and was able to read and write to virtual files. But they did not appear in a directory listing for some reason. Example modified from Sample.AnotherProcess^.au3: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Include <WinAPI.au3> #include <VirtualFlex.Memory.au3> #include <Constants.au3> Virtual_FileA(@ScriptDir & '\text.txt', 'This file virtually exist!') ConsoleWrite(FileRead(@ScriptDir & '\text.txt') & @LF) $pid = Run(@ComSpec, @ScriptDir, @SW_SHOW) Virtual_AttachToProcess($pid) ; to detach use: Virtual_DetachFromProcess($pid) Virtual_ProcessOption($pid, $FLEX_ALL_CHANGES_ARE_VIRTUAL, 1) $Form1 = GUICreate("Form1", 257, 147, 192, 124) GUISetState(@SW_SHOW) Do $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch Until False Then in cmd.exe box that appears you can read and write to virtual files: C:\test_dir>type text.txt This file virtually exist! C:\test_dir>dir text.txt Volume in drive C is Windows Volume Serial Number is ECD1-59CD Directory of C:\test_dir File Not Found C:\test_dir>echo test_TEXT>test_virtual_file.txt C:\test_dir>type test_virtual_file.txt test_TEXT C:\test_dir>dir test_virtual_file.txt Volume in drive C is Windows Volume Serial Number is ECD1-59CD Directory of C:\test_dir File Not Found
- 39 replies
-
- Virtual File
- Virtual Registry
-
(and 1 more)
Tagged with:
-
Since the part of the code that was crashing was only used for decompressing some other code, I rewrote it to use the method from here instead and it is a bit bigger but it seems to work ok with 64 bit now. ZLIB.au3
-
I found that the 64 bit version works for me in windows 7 but crashes in windows 10 unless i turn off high entropy ASLR for some reason. If i turn off high entropy ASLR then it works ok. This dll call is what is causing the crash: Local $Ret = DllCall("user32.dll", "uint", "CallWindowProc", "ptr", $CodeBufferPtr + $AP_Decompress, _ "ptr", DllStructGetPtr($Output) + 4, _ "ptr", DllStructGetPtr($Result), _ "int", 0, _ "int", 0) I believe the posts on these pages may be discussing a similar crash and maybe a solution but it is beyond my understanding. https://social.msdn.microsoft.com/Forums/en-US/97256987-157e-4601-b22b-f77f43e33926/getting-crash-when-calling-callwindowproc-function-in-migration-from-vs60-to-vs2015 https://social.msdn.microsoft.com/Forums/en-US/7820bf8c-0540-49b6-bf86-2a39db09add1/getting-crash-when-calling-callwindowproc-function-in-migration-from-vs60-to-vs2015
-
From https://learn.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptbinarytostringa If you want, you can add CRYPT_STRING_NOCRLF (0x40000000) to the flags parameter to prevent the CRLF's in the output. Like this: Func _Base64Encode($input) $input = Binary($input) Local $struct = DllStructCreate("byte[" & BinaryLen($input) & "]") DllStructSetData($struct, 1, $input) Local $strc = DllStructCreate("int") Local $a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _ "ptr", DllStructGetPtr($struct), _ "int", DllStructGetSize($struct), _ "int", 1 + 0x40000000, _ "ptr", 0, _ "ptr", DllStructGetPtr($strc)) If @error Or Not $a_Call[0] Then Return SetError(1, 0, "") ; error calculating the length of the buffer needed EndIf Local $a = DllStructCreate("char[" & DllStructGetData($strc, 1) & "]") $a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _ "ptr", DllStructGetPtr($struct), _ "int", DllStructGetSize($struct), _ "int", 1 + 0x40000000, _ "ptr", DllStructGetPtr($a), _ "ptr", DllStructGetPtr($strc)) If @error Or Not $a_Call[0] Then Return SetError(2, 0, ""); error encoding EndIf Return DllStructGetData($a, 1) EndFunc ;==>_Base64Encode
-
An easter egg type thing I made for a program that is based on other snow animation scripts I found on these forums that I thought I would share here in case anyone found it interesting. It is just moving around a bunch of label controls on top of everything else without interfering with usage of other controls. #NoTrayIcon #include <GUIConstants.au3> Global $runTimer = TimerInit() Const $GUIWIDTH = 500, $GUIHEIGHT = 200 $hGui = GUICreate("TEST", $GUIWIDTH, $GUIHEIGHT, -1, -1, -1, BitOR($WS_EX_LAYERED, $WS_EX_COMPOSITED)) $aSnow = snowInit() $hbut = GUICtrlCreateButton('test', 100,20,50,30) GUICtrlCreateEdit('test', 100,100,200,50) GUICtrlCreateGroup("Group 1", 350, 40, 90, 140) GUICtrlCreateRadio("Radio 1", 370, 80, 60, 15) GUICtrlCreateRadio("Radio 2", 370, 120, 60, 15) GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group GUISetState(@SW_SHOW, $hGui) AdlibRegister(snowAnimate, 40) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hbut ConsoleWrite('button' & @CRLF) EndSwitch WEnd Func snowInit() Local Const $isnowflakes = 50 ; number of snowflakes Local $aSnow[$isnowflakes][5] ; 0=length/width, 1=left (x pos), 2=top (y pos), 3=handle, 4=fall speed ; create snowflakes For $i = 0 To UBound($aSnow) - 1 $aSnow[$i][3] = GUICtrlCreateLabel("*", 0, 0, 0, 0) GUICtrlSetState(-1, $GUI_DISABLE + $GUI_HIDE) ; $GUI_DISABLE allows click thru snow but changes to grey color, $GUI_HIDE so we can show it later GUICtrlSetStyle(-1, 0) ; removes grey color but still disabled, and prevent double-clicking copying text to clipboard GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) ; for transparent label control over non-transparent window GUICtrlSetColor(-1, 0) ; snow color Next Return $aSnow EndFunc Func snowAnimate() Local Const $iMinR = 5 ; minimum length of the snowflake's side Local Const $iMaxR = 15; max length Local Const $creation_interval = 500 ; spawn new snowflake every X ms Local Static $lastCreationTime = 0 Local $now = TimerDiff($runTimer) For $i = 0 To UBound($aSnow) - 1 ; if this snowflake not visible yet If BitAND(GUICtrlGetState($aSnow[$i][3]), $GUI_HIDE) And ($now - $lastCreationTime > $creation_interval) Then snowRandomize($aSnow, $i, $iMinR, $iMaxR) GUICtrlSetState($aSnow[$i][3], $GUI_SHOW) $lastCreationTime = $now Else $aSnow[$i][2] += $aSnow[$i][4] ; increment y pos If Random(1,20,1) = 20 Then $aSnow[$i][1] += Random(-2, 2, 0) ; x randomness GUICtrlSetPos($aSnow[$i][3], $aSnow[$i][1], $aSnow[$i][2]) ; when it gets to bottom of screen, change to random size and x pos and move to top of screen again If $aSnow[$i][2] > $GUIHEIGHT Then snowRandomize($aSnow, $i, $iMinR, $iMaxR) EndIf EndIf Next EndFunc Func snowRandomize(ByRef $aSnow, $i, $iMinR, $iMaxR) $aSnow[$i][0] = Random($iMinR, $iMaxR, 0) ; dimension of snow $aSnow[$i][1] = Random(0 - $iMaxR, $GUIWIDTH + $iMaxR, 0) ; x position $aSnow[$i][2] = 0 - $iMaxR ; y position (out of screen at startup) $aSnow[$i][4] = Random(0.05, 2) GUICtrlSetPos($aSnow[$i][3], $aSnow[$i][1], $aSnow[$i][2], $aSnow[$i][0], $aSnow[$i][0]) GUICtrlSetFont($aSnow[$i][3] , Floor(0.25 + $aSnow[$i][0]*1.25), 800, 0, '', 4) EndFunc ;==>_Randomize
-
Check if workstation is locked on Windows 10
garbb replied to Kerl's topic in AutoIt General Help and Support
This seems to work for me on win10 x64: #include <WinAPISys.au3> Func _isWindowsLocked() If _WinAPI_OpenInputDesktop() Then Return False Return True EndFunc Never mind, I had my win 10 pc settings set to disable the welcome screen/clock/picture thing and go directly to the user selection screen when locked so this only worked on my pc, tested on emulator with default win10 settings and it does not work... -
I am trying to use _WinNet_AddConnection2(). The options for the $iOptions parameter are: I want to use the "32" flag to save the credentials and for some reason the documentation says that in order to use the "32" flag, you also need to use the "16" flag which prompts for the username and password via the command line instead of a GUI. So I tried this, but unfortunately I cannot enter the username and password via the command line. Here is my test code: #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Change2CUI=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <WinNet.au3> _WinNet_AddConnection2(Null, '\\server\share', 0, 0, 1, 2+4+16+32) ; keep script alive While True sleep(100) WEnd I compiled this as a command line exe and ran it and I get this in the console: The password or user name is invalid for \\server\share. Enter the user name for 'server': But when I type, the letters do not appear in the console so I cannot enter the username or password. I have tested this with a real, valid server address that I know works and have gotten the same result. I have also tested this without using the "16" or "32" flag and a windows GUI appears which allows me to enter a username and password and this works fine. Is there anyway for autoit to allow entering information in via the console with a winapi function like this or is it not supported?
-
ControlClick() fails for button in a Hidden GUI
garbb replied to CraigA's topic in AutoIt GUI Help and Support
I realize that this is an extremely old thread but maybe someone will find this from searching. Anyways I found a sort-of workaround to this problem which is to create the GUI like this GUICreate('', 0, 0, -100, -100, -1, $WS_EX_TOOLWINDOW) GUISetState(@SW_SHOWNOACTIVATE) This creates a GUI that is not actually hidden but appears offscreen and does not appear in the taskbar or alt-tab list and also does not take focus when it appears, so effectively it is hidden but the events still fire. -
method for interaction with hidden window(s)
garbb replied to garbb's topic in AutoIt Example Scripts
Thanks for testing it on windows 10. I have updated the script and tested it successfully on windows 10 now. Also for some reason the windows calculator app won't work with this on windows 10 so I changed the example script to use notepad and cmd.exe as examples. Let me know if it works for you now. -
Here is a method for running a windows application (that may create any number of windows) completely hidden while still being able to interact with it with autoit (controlsend(), controlclick(), etc...) and get a screencap of any of the windows. Basically this is accomplished by running the application on a hidden desktop (credit to Decipher) and then running a separate instance of autoit also on the hidden desktop to interact with the application. This is kind of a goofy hack, but it seems to work. hiddenDesktopInteract.au3: #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseUpx=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <WinAPI.au3> #include <WinAPIEx.au3> #include <GDIPlus.au3> ;1st command line param that will launch seperate instance Const $hdiParam = 'hiddenDesktopInteract' ;######DO NOT PUT ANY OTHER CODE ABOVE THIS THAT CALLS A 2ND INSTANCE OF THE SCRIPT OR ELSE YOU MAY END UP CALLING INFINITE INSTANCES AND CRASHING WINDOWS!!!!!! ;seperate process for hidden desktop interaction ;1st param should be 'hiddenDesktopInteract' and 2nd param is name of func to call for interaction code ;ex: "autoit.exe script.au3 hiddenDesktopInteract interactionfunc" or "compiledscript.exe hiddenDesktopInteract interactionfunc" if $CmdLine[0] = 2 AND $CmdLine[1] = $hdiParam Then EXIT Call($CmdLine[2]) ;credit to Decipher in thread https://www.autoitscript.com/forum/topic/152515-start-a-process-hidden/#comment-1095173 for code for running process on a hidden desktop Func _hiddenDesktopInteract_run($sProgram, $sInteractionFunc, $sCommand = '') ;if the interaction function does not exist then don't do anything If Not IsFunc(Execute($sInteractionFunc)) Then ConsoleWrite('error: interaction function "' & $sInteractionFunc & '" for "' & $sProgram & '" does not exist' & @CRLF) Return EndIf ;create structs Local $tStartupInfo = DllStructCreate($tagStartupInfo) DllStructSetData($tStartupInfo, "Size", DllStructGetSize($tStartupInfo)) Local $tProcessInfo_targetApp = DllStructCreate($tagPROCESS_INFORMATION) Local $tProcessInfo_interactionScript = DllStructCreate($tagPROCESS_INFORMATION) ; Create Desktop Local $hDesktop = _WinAPI_CreateDesktop('AutoItHidden', BitOR($DESKTOP_CREATEWINDOW, $DESKTOP_SWITCHDESKTOP)) If Not $hDesktop Then MsgBox(0, 'Error', 'Unable to create desktop.') Exit EndIf ; Prep Process Info Local $nSuccess = DllStructSetData($tStartupInfo, "Desktop", _WinAPI_CreateString("AutoItHidden")) ;run target program on hidden desktop and get PID _WinAPI_CreateProcess('', '"' & $sProgram & '"' & ($sCommand ? ' ' & $sCommand : ''), 0, 0, 0, 0x00000200, 0, 0, DllStructGetPtr($tStartupInfo), DllStructGetPtr($tProcessInfo_targetApp)) Local $aPID_targetApp = DllStructGetData($tProcessInfo_targetApp, 'ProcessID') ConsoleWrite('!>target app PID:' & $aPID_targetApp & @CRLF) ;run instance of this script on hidden desktop to interact with target program Local $sParams = '"' & @ScriptFullPath & '" ' & $hdiParam & ' ' & $sInteractionFunc Switch @Compiled case True Local $sAppName = @ScriptFullPath Local $sCommandLine = $sParams case False Local $sAppName = @AutoItExe Local $sCommandLine = '"' & @AutoItExe & '" ' & $sParams EndSwitch _WinAPI_CreateProcess('', $sCommandLine, 0, 0, 0, 0x00000200, 0, 0, DllStructGetPtr($tStartupInfo), DllStructGetPtr($tProcessInfo_interactionScript)) ;and get PID of interaction instance so we can wait until it is finished Local $iPID_interactionScript = DllStructGetData($tProcessInfo_interactionScript, 'ProcessID') ConsoleWrite('!>Interaction Script PID: ' & $iPID_interactionScript & @CRLF) ;wait until interaction script instance is finished and get exit code (which is return value from interaction function) ProcessWaitClose($iPID_interactionScript) Local $exitcode_interactionScript = @extended ConsoleWrite("!>Interaction Script Exit Code: " & $exitcode_interactionScript & @CRLF) Local $sOutput = StdoutRead($iPID_interactionScript) ConsoleWrite("!>Interaction Script Stdout: " & $sOutput & @CRLF) ;close hidden desktop Local $aRet = DllCall("User32.dll", "int", "CloseDesktop", "handle", $hDesktop) ConsoleWrite("!>Close Desktop: " & $aRet[0] & @CRLF) ; Non-Zero is successfull! Return $exitcode_interactionScript EndFunc Func _hiddenDesktopInteract_cap($title, $imgfile, $Left = 0, $Top = 0, $Right = -1, $Bottom = -1) _GDIPlus_Startup() $hWnd = WinGetHandle($title) $iWidth = _WinAPI_GetWindowWidth($hWnd) $iHeight = _WinAPI_GetWindowHeight($hWnd) $hDDC = _WinAPI_GetDC($hWnd) $hCDC = _WinAPI_CreateCompatibleDC($hDDC) $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iWidth, $iHeight) _WinAPI_SelectObject($hCDC, $hBMP) DllCall("User32.dll", "int", "PrintWindow", "hwnd", $hWnd, "hwnd", $hCDC, "int", 0) _WinAPI_ReleaseDC($hWnd, $hDDC) _WinAPI_DeleteDC($hCDC) $hBMPclone = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) if $Right = -1 then $iX = _GDIPlus_ImageGetWidth($hBMPclone) - $Left Else $iX = $Right - $Left EndIf if $Bottom = -1 then $iY = _GDIPlus_ImageGetHeight($hBMPclone) - $Top Else $iY = $Bottom - $Top EndIf ;convert from 32bit bitmap to 24bit bitmap b/c 32bit bitmap cannot display correctly in autoit GUI for some reason $hClone = _GDIPlus_BitmapCloneArea($hBMPclone, $Left, $Top, $iX, $iY, $GDIP_PXF24RGB) _GDIPlus_ImageSaveToFile($hClone, $imgfile) _WinAPI_DeleteObject($hBMP) _WinAPI_DeleteObject($hBMPclone) _WinAPI_DeleteObject($hClone) _GDIPlus_Shutdown() EndFunc hiddenDesktopInteract_EXAMPLES.au3: #include "hiddenDesktopInteract.au3" ;test function for interacting with notepad app on hidden desktop func notepadtest() opt('winwaitdelay', 0) ;to make it run a little bit faster WinWait('[CLASS:Notepad]') $hwin = WinGetHandle('[CLASS:Notepad]') ControlSend($hwin, '', '[CLASS:Edit; INSTANCE:1]', 'hello{ENTER}') WinMenuSelectItem($hwin, '', '&Edit', 'Time/&Date') _hiddenDesktopInteract_cap($hwin, @DesktopDir & '\notepad_cap.jpg') ControlSend($hwin, '', '[CLASS:Edit; INSTANCE:1]', '^a') ControlSend($hwin, '', '[CLASS:Edit; INSTANCE:1]', '{DELETE}') WinClose($hwin) EndFunc ;test function for interacting with cmd.exe on hidden desktop func cmdtest() opt('winwaitdelay', 0) ;to make it run a little bit faster WinWait('[CLASS:ConsoleWindowClass]') $hwin = WinGetHandle('[CLASS:ConsoleWindowClass]') ControlSend($hwin, '', '', 'dir{ENTER}') sleep(500) _hiddenDesktopInteract_cap($hwin, @DesktopDir & '\cmd_cap.jpg') ControlSend($hwin, '', '', 'exit{ENTER}') EndFunc _hiddenDesktopInteract_run("notepad.exe", 'notepadtest') _hiddenDesktopInteract_run("cmd.exe", 'cmdtest') The example script demonstrates running a hidden instance of notepad and cmd.exe and interacting with it via controlclick() and controlsend() and then capturing a screencap of the window before closing it. I made this because some applications ignore the @SW_HIDE parameter when launching them and show a window anyways, and also because I wanted to be able to screencap windows while making them hidden so they wouldn't steal focus. To use this you must first write a function that will interact with the target application/window and then call _hiddenDesktopInteract_run() with the name of the application as the first parameter and the name of the function as the second parameter. You can also use _hiddenDesktopInteract_cap() within your function to store an image of the hidden window to a file. Because the way that this works is that ONLY the function that you specify will be run on the hidden desktop, you must make sure that your function does not depend on any variables/code that is outside of the function or it will fail. I was also trying to find some way to transfer information from the autoit instance that runs on the hidden desktop to the main instance of the script using consolewrite() and getting the stdout stream of the other instance but I couldn't figure it out. (I was looking at the code here but I couldn't get it to work) Maybe someone knows how to get it working... Right now the exit code of the hidden desktop autoit instance is used to transfer the return code of the function but this only works with integers and so isn't really a good method. Anyways, I hope this will be useful for someone. Or maybe someone knows a better/less hacky way to achieve the same thing... Tested with autoit 3.3.14.2 on Windows 7 64bit SP1 and Windows 10 64bit 1511 (OS Build 10586.164) hiddenDesktopInteract.au3 hiddenDesktopInteract_EXAMPLES.au3
-
I know this is a really old thread but I thought I would post how I got the OnLoginComplete event to work in case anyone finds this from google. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $oRDP = ObjCreate("MsTscAx.MsTscAx") GUICreate("Embedded RDP control Test", 640, 480, -1 , -1, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $GUIActiveX = GUICtrlCreateObj($oRDP, 10, 10, 620, 460) GUISetState() ObjEvent($oRDP, 'rdpevent_') func rdpevent_OnLoginComplete() ConsoleWrite('login event' &@CRLF) EndFunc $oRDP.Server = "SERVER.ADDRESS" $oRDP.AdvancedSettings.RDPPort = 3389 $oRDP.Connect() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd GUIDelete()
-
random "Illegal text at the end of statement"
garbb replied to garbb's topic in AutoIt General Help and Support
Welp,fixed it myself. Turns out that there was a really stupid typo on one of the lines that was calling this function and was not called very often and that was the problem. The error was not pointing me in the right direction. Hopefully someone else someday will have a similar problem and this will help them... -
I have a script with a logging function that simply outputs to the console in Scite with a date/time stamp: func logoutput($msg) $systime = _Date_Time_GetSystemTime() $systime = _Date_Time_SystemTimeToTzSpecificLocalTime(DllStructGetPtr($systime)) $darray = _Date_Time_SystemTimeToArray($systime) $datetime = StringFormat("%04d/%02d/%02d %02d:%02d:%02d.%03d", $darray[2], $darray[0], $darray[1], $darray[3], $darray[4], $darray[5], $darray[6]) $msg = $datetime & ' ' & $msg ConsoleWrite($msg) EndFunc The script will run and call this function many, many times and output to the console fine. But after running for about 45 minutes it will crash with the following error: "C:\Users\XXXXXXX\Desktop\autoit\test.au3" (538) : ==> Illegal text at the end of statement (one statement per line).: func logoutput($msg) func logoutput($msg)^ ERROR This makes no sense because how could it call the function so many times successfully and then all of a sudden have a syntax error with the same code?! I figure this must be a bogus error or some sort of bug or maybe the console is filling up too much? I checked and I am filling the console with around 6200 lines and about 344kb of text. I swear that I have made scripts that output more though... I made a test script that just outputs lines to the console by calling my logoutput() and it got to over 7000 lines without crashing so somehow the error must have something to do with the rest of my script... Does anyone have any idea what could be going on here? This is autoit v3.3.10.2 if it matters.
-
It looks like a pointer to a pointer to an array of ENCRYPTED_CREDENTIALW structures and each one of those has as its first member a pointer to a CREDENTIAL structure which is the same as I was using in my credread() above to pull out the username and password: Local $structCREDENTIAL= "" & .... etc But then you may have a problem because it says on the MSDN page for the CREDENTIAL structure that And if you google for more info about this you will find that: And so I think in order to read stored domain passwords you must do a bit more hackery. There is other software that exists (of varying legitimacy) that will get you the information that you want... ...of course I am assuming that whatever you are trying to do is all for legitimate purposes...
- 16 replies
-
- Need help creating a function
- CredWrite
-
(and 1 more)
Tagged with:
-
Thank you! I didn't realize that I could specify a ptr* as a parameter type or that I could create a struct and tell it to use a pointer. I finally made it work. Here's the working CredRead function: Func CredRead($Target) Local $FuncRet[3] Local $targetName = DllStructCreate("wchar[100]") DllStructSetData($targetName,1,$Target) Local $hAdvapi32 = DllOpen("Advapi32.dll") Local $Ret = DllCall($hAdvapi32, 'bool', 'CredReadW', 'ptr', DllStructGetPtr($targetName), 'dword', 1, 'dword', 0, 'ptr*', 0) if $ret[0]=0 then Return SetError(1,0,$FuncRet) 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, $Ret[4]) Local $userName = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'Username')) Local $User = DllStructGetData($userName, 1) Local $CredentialBlobSize = DllStructGetData($tdata, 'CredintialBlobSize') Local $credentialBlob = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'CredentialBlob')) Local $Password = StringLeft(DllStructGetData($credentialBlob, 1), $CredentialBlobSize/2) Local $Comment = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'Comment')) Local $Comm = DllStructGetData($Comment, 1) Dim $FuncRet[] = [$User, $Password, $Comm] Return $FuncRet EndFunc It returns the username, password, and comment in an array.
- 16 replies
-
- Need help creating a function
- CredWrite
-
(and 1 more)
Tagged with:
-
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.
- 16 replies
-
- Need help creating a function
- CredWrite
-
(and 1 more)
Tagged with:
-
Thanks for this, I needed a very simple server for a project and had no experience with http servers and this was very useful for me. I think found a few random bugs? Your "Content-Length" header is misspelled as "Content-Lenght" in all three of your servers. Also for some reason when I corrected this misspelling and ran your server through fiddler web debugger I get a warning that the content length is always incorrectly under-reported by 4 bytes. I am not sure exactly why except that maybe the last 2 @CRLF's are supposed to be included in the length which would be the 4 missing bytes? In your basic server _HTTP_SendError() is not defined. Maybe it was supposed to be _HTTP_SendFileNotFoundError() ?
-
I have a script that creates a microsoft word document, opens it up in word to allow the user to edit it, and then after the user finishes editing it and closes it, the script creates an email, fills in the To,Cc,Subject,Body fields and adds the word document as an attachment. Then the word document file is deleted (because the attachment inside the email is a copy, so the original file is no longer needed). Currently the way I am doing this is that my script will open the word document and wait until the user closes it, at which point it will create the email, attach the document, and then delete the document file. The problem with this is that sometimes the user will close the script and break the rest of the process (creating the email, etc...) so I was trying to do it a different/better way. As it turns out, when you add an attachment to a new outlook email, the attachment is stored as a file in %userprofile%AppDataLocalMicrosoftWindowsTemporary Internet FilesContent.Outlook<RANDOM_STRING> and if you edit this file then you will be editing the actual email attachment. So what I was trying to do was have the script create the email and attach the file first, and then open the attachment file and allow the user to edit it. At this point the script could exit and everything that the user needs would already be open and ready to edit. The .GetTemporaryFilePath() method returns the path to the attachment file. TLDR: After creating an email and attaching a file to it, I want to open the file.
-
Thanks for the better error handler. It looks like the error is: test.au3 (16) : ==> COM Error intercepted ! err.number is: 0x80020009 err.windescription: Exception occurred. err.description is: Cannot access this attachment in the temporary files folder. Use this method in an attachment event to obtain the temporary file path. err.source is: Microsoft Outlook err.helpfile is: err.helpcontext is: 0 err.lastdllerror is: 0 err.scriptline is: 16 err.retcode is: 0x00001000 The MSDN page says that you will get an error if the .type is not 1 (olByValue), but in my script it is 1. It also says that you will get an error if you don't use .GetTemporaryFilePath() inside of an event callback, but I have done this. I tried to use .GetTemporaryFilePath() outside of an event function (i just tried $oMessage.attachments(1).GetTemporaryFilePath() ) and I got the exact same com error so it's almost like it doesn't think that it's getting called from inside of an event callback for some reason...
-
I am trying to interact with microsoft outlook through the COM interface. I want to use the GetTemporaryFilePath (msdn reference here) method to get information about an attachment to an email. For some reason I am getting a blank string from this method instead of the path I want. Here is my test code. It just creates a new email and adds an attachment and tries to get the temppath of it. (of course you will need to have outlook installed) (I am using outlook 2010): ;com error handler $oMyError = ObjEvent("AutoIt.Error", "ErrFunc") ;create new email item and display $oOutlook = ObjCreate("Outlook.Application") $oMessage = $oOutlook.CreateItem(0) $oMessage.display() ;register events for the new email item $oevent = ObjEvent($oMessage,"oMessage_") ;event for when attachment is added Func oMessage_AttachmentAdd($oAttachment) ConsoleWrite($oAttachment.filename & ' was added.' & @CR) ConsoleWrite('type=' & $oAttachment.type & @CR) ConsoleWrite('temp path=' & $oAttachment.GetTemporaryFilePath() & @CR) EndFunc ;add an attachment $oMessage.attachments.add("C:\windows\system32\calc.exe") ;keep script alive to receive events while 1 sleep(100) WEnd ; This is a custom error handler Func ErrFunc() $HexNumber = Hex($oMyError.number, 8) MsgBox(0, "", "We intercepted a COM Error !" & @CRLF & _ "Number is: " & $HexNumber & @CRLF & _ "WinDescription is: " & $oMyError.windescription) $iEventError = 1 ; Use to check when a COM Error occurs EndFunc ;==>ErrFunc The output I get is: calc.exe was added. type=1 temp path= I also get COM error 80020009 "Exception Occurred". Unfortunately I'm not finding anything helpful searching for this. I tried the equivalent code in VBA in outlook and it works fine: Public WithEvents newItem As Outlook.MailItem Private Sub newItem_AttachmentAdd(ByVal newAttachment As Attachment) If newAttachment.Type = olByValue Then Debug.Print newAttachment.FileName & " was added." Debug.Print "type=" & newAttachment.Type Debug.Print "temp path=" & newAttachment.GetTemporaryFilePath End If End Sub Public Sub TestAttachAdd() Set newItem = ThisOutlookSession.CreateItem(olMailItem) newItem.Attachments.Add ("C:\windows\system32\calc.exe") newItem.Display End Sub Output is: calc.exe was added. type=1 temp path=C:\Users\<USERNAME>\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.Outlook\GF7OKDY4\calc.exe Does anyone have any idea why GetTemporaryFilePath is not working in autoit or have any idea of anything I can try to get that information? Hopefully this is not just some limitation of autoit's COM interface?
-
I could be wrong as I am not very knowledgeable on this topic but i believe that the way that most modern browsers work is that they keep a persistent connection open to a server in case they are going to request more data in the near future and it is up to the server to determine when to close the connection; usually after a timeout period. See the section "Persistent Connections" here: http://odetocode.com/articles/743.aspx You also might want to have a look at the Session_server in the autoit server I linked above because I believe that it implements such timeouts. Also if I were you I might try creating a very simple client application in another autoit script and have it connect and disconnect to your server running autoit 3.3.10.2 so that you can see exactly what is going on and if it can detect when the client disconnects properly.
-
I am using an autoit-based webserver that is based on the "Basic server" from here: '?do=embed' frameborder='0' data-embedContent>>. If you change the following it works fine for me in 3.3.10.2: line 54 from If @error Then to If @error>0 Then and line 65 from _HTTP_SendError($aSocket[$x]) to _HTTP_SendFileNotFoundError($aSocket[$x]) (i think this is just a mistake because the _HTTP_SendError() function does not exist...) I think the reason that this server works is because it is always immediately closing the connection/socket after sending the data.