Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/10/2015 in all areas

  1. So I think it's time to publish this little tutorial I have made on using DllCall() and DllStructs. It's not near completion but I think it's a good start at least This tutorial is mostly aimed for people who have never used DllCall() before or have very limited knowledge about it. In the future I will update it with more advanced topics so more advanced users can make use of it too. Well here goes. Dealing_with_Dll.pdf Previous downloads: 31 Suggestions, language corrections and errors in the tutorial is of course welcome.
    1 point
  2. I'm writing a set of PowerShell scripts/library for Windows 10 builds. One thing I often want to do is to browse to the location of a script that is part of a larger group of scripts and run it manually to do an install or make a one off change. So I like all my scripts to work well whether run from a task sequence or double-clicked in explorer. Most of my build scripts rely on having admin rights so I like to make them able to self-elevate if required - or at least give an error message. In PowerShell 4.0 (Windows 8.1) they added the #Requires -RunAsAdministrator statement but this won't do it for you - it just causes the script to abort if not admin. Below is a PowerShell script that does the following: Checks for admin rights using the Test-IsAdmin functionIf not admin:Get the full script path and working directory using the Get-UNCFromPath functionIf the paths are mapped drives then get the UNC version (drive mappings are lost when elevating from user to admin in most configurations)Execute PowerShell.exe with the UNC path of the script and the RunAs verb to trigger elevation. ExecutionPolicy is also set to Bypass on the command line. The working directory is also set to the UNC path version.Waits for the new process to finish, and captures its return codeExits using the same return codeScript is as follows: # Test if admin function Test-IsAdmin() { # Get the current ID and its security principal $windowsID = [System.Security.Principal.WindowsIdentity]::GetCurrent() $windowsPrincipal = new-object System.Security.Principal.WindowsPrincipal($windowsID) # Get the Admin role security principal $adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator # Are we an admin role? if ($windowsPrincipal.IsInRole($adminRole)) { $true } else { $false } } # Get UNC path from mapped drive function Get-UNCFromPath { Param( [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)] [String] $Path) if ($Path.Contains([io.path]::VolumeSeparatorChar)) { $psdrive = Get-PSDrive -Name $Path.Substring(0, 1) -PSProvider 'FileSystem' # Is it a mapped drive? if ($psdrive.DisplayRoot) { $Path = $Path.Replace($psdrive.Name + [io.path]::VolumeSeparatorChar, $psdrive.DisplayRoot) } } return $Path } # Relaunch the script if not admin function Invoke-RequireAdmin { Param( [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)] [System.Management.Automation.InvocationInfo] $MyInvocation) if (-not (Test-IsAdmin)) { # Get the script path $scriptPath = $MyInvocation.MyCommand.Path $scriptPath = Get-UNCFromPath -Path $scriptPath # Need to quote the paths in case of spaces $scriptPath = '"' + $scriptPath + '"' # Build base arguments for powershell.exe [string[]]$argList = @('-NoLogo -NoProfile', '-ExecutionPolicy Bypass', '-File', $scriptPath) # Add $argList += $MyInvocation.BoundParameters.GetEnumerator() | Foreach {"-$($_.Key)", "$($_.Value)"} $argList += $MyInvocation.UnboundArguments try { $process = Start-Process PowerShell.exe -PassThru -Verb Runas -Wait -WorkingDirectory $pwd -ArgumentList $argList exit $process.ExitCode } catch {} # Generic failure code exit 1 } } # Relaunch if not admin Invoke-RequireAdmin $script:MyInvocation # Running as admin if here $wshell = New-Object -ComObject Wscript.Shell $wshell.Popup("Script is running as admin", 0, "Done", 0x1) | Out-Null
    1 point
  3. @boththose I meant this. Saludos
    1 point
  4. @Danyfirex: Nice piece of code @CHIMP: It depends on your definition of drop on another window, if you now select the bottom one to become in foreground its dropped on the top window whereas probably thats not the definition of a drop (suggestion if mouse moves more then n pixels from starting point its a drag/drop operation whereas n>=5 but 5 is an arbitrary choice)
    1 point
  5. I'm sure you knew this, but doing it directly from AutoItwithout the PowerShell and using the same algo would be: PrintBoththosesThingInAutoItWithoutUsingPowerShell() ConsoleWrite("@error = " & @error & ", @extended = " & Hex(@extended) & @CRLF) Func PrintBoththosesThingInAutoItWithoutUsingPowerShell() Local $oErrorHandler = ObjEvent("AutoIt.Error", PrintBoththosesThingInAutoItWithoutUsingPowerShell) Local $oWMIService = ObjGet("winmgmts:\\.\root\cimv2\sms") ; dot means "this comp" If @error Then Return SetError(1, @error, "") Local $oItems = $oWMIService.ExecQuery("SELECT ProductName,InstallDate,InstalledLocation,ProductVersion,UninstallString FROM SMS_InstalledSoftware") If @error Then Return SetError(2, @error, "") For $oItem In $oItems ConsoleWrite($oItem.ProductName & @CRLF) ConsoleWrite(@TAB & $oItem.InstallDate & @CRLF) ConsoleWrite(@TAB & $oItem.InstalledLocation & @CRLF) ConsoleWrite(@TAB & $oItem.ProductVersion & @CRLF) ConsoleWrite(@TAB & $oItem.UninstallString & @CRLF) ConsoleWrite(@CRLF) Next EndFunc That's why it wasn't clear to me why you used PowerShell.
    1 point
  6. Hum regex need accuracy The pattern in post #3 was intended to work on your sample text 'File1' in post #1 So if you are currently using a different text, could you please post the exact copy of the current content of "test.txt" ? BTW the regex uses @crlf as a delimiter for the output, so if one or more @crlf already exist in the original text it must be removed first (reason why I replaced it by a tab)
    1 point
  7. @minxomat I've got a few question: Project: I made a couple of pull requests instead of merging the code myself because I used AutoIT's data types rather than DllStructCreate and I wasn't sure that's what we wanted to do; it was much cleaner and easier than I expected so I may go ahead and merge them.I am silently ignoring overflows to the Add[xxx] functions (a word value passed to a byte function, etc.); at minimum we'll need to output a debug message because this could cause some hard to find bugs when I accidentally call an xx_byte function thinking I'm calling an xx_word function. Because that's the kind of thing that I do.Will we be using GitHub's issue tracker? If so, I'm going to add a few issues that need to be looked at; they should definitely wait until the port is complete, but I don't want to forget about them.I have also nearly finished porting Linker.au3, but haven't pushed it yet (bad Ryan!).Perseus: Is there a way to dereference a pointer without using DirectByte? If not, that's my first feature request once the port is complete. I'm ultimately wanting to execute a function from a pointer.Long-term, it would be nice to be able to inline assembly as a supplement to DirectByte (I at least could do that more efficiently). Something like asm { mov eax, ebx }. If we don't want it in the language, I think we can easily do something like it in Perseus (using DirectByte) as part of the standard library.With DirectByte, I'm stuck writing assembly, assembling the code, then disassembling it so I can copy and paste the hex values. By the time I've done that, I forget what I was doing.
    1 point
  8. water

    Active Directory UDF

    I have added a link to MSDN in the wiki.
    1 point
  9. water, your impression is sooo correct GimK, The first String* funcs are easy to understand Explanations for the StringRegExpReplace : '(?i)(?<!^|\w)(?=' & $ref & ')|(?<=' & $ref & ')\h*:?' (?i) : case insensitive (?<! ) : negative lookbehind, means 'not preceded by' ^|\w : beginning of string OR a word char (?=' & $ref & ') : positive lookahead, means 'followed by' (by the content of the $ref variable) | : or (alternation) (?<=' & $ref & ') : positive lookbehind, means 'preceded by' (by the content of the $ref variable) \h*:? : 0 or more horizontal whitespace + an optional colon $ref = "Owned By|Name|Lastname|Age|Height|Hobbies" : This string contains the subpattern with the keywords alternation It means ("Owned By" OR "Name" OR "Lastname" ... etc ) So in usual language this regex says : " Find - positions (not preceded by the beginning of string OR by a word char) ; because "name" must not match in "Lastname" and (followed by a keyword) or - some horizontal spaces (or none) with a colon (or not) preceded by a keyword And replace them by a @crlf "
    1 point
  10. Regular Expressions aren't easy to understand until you work with them on a daily basis. That's at least my impression.
    1 point
  11. You want fries with that too?
    1 point
×
×
  • Create New...