ambad4u Posted December 9, 2019 Posted December 9, 2019 Hello and Good Day to All! I am trying to install .NET 3.5 on Windows 10 x64bit via autoit (via ShellExecuteWait + PowerShell). If I run this line, it will runs without issues: ShellExecuteWait('PowerShell.exe', '-executionpolicy Bypass -File "' & @ScriptDir & '\OJP83BU523.ps1' & '"') "OJP83BU523.ps1" contains: DISM /Online /Enable-Feature /FeatureName:NetFX3 /All /Source:D:\Sources\sxs /LimitAccess However, since I won't know in advance the drive letter of the "sources" folder, I created a script to generate a PowerShell Script to give a correct path for it. With the modified script below, PowerShell only blinks and nothing happens ShellExecuteWait('PowerShell.exe', '-executionpolicy Bypass -File "' & @ScriptDir & '\' & $filename & '"') or ShellExecuteWait('PowerShell.exe', '-executionpolicy Bypass -File "' & $filename & '"') I wish I know the difference with "$filename" and "\OJP83BU523.ps1" usage, as for me, it should be the same. Attached is my entire autoit script. any help is appreciated!, many thanks in advance! test.au3
seadoggie01 Posted December 9, 2019 Posted December 9, 2019 You left the handle to the file open without closing it. The easiest solution would be to ditch the FileOpen line. FileOpen returns a handle to a file. FileWrite will put the data in the file, but it won't be able to be read until the file handle is closed with FileClose. Instead, you can directly open, write, and close the file all with FileWrite. All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
ambad4u Posted December 9, 2019 Author Posted December 9, 2019 That makes sense, My apologies, let me check that one out.
Subz Posted December 9, 2019 Posted December 9, 2019 Can you try Local $hFilePath = FileOpen(@ScriptDir & "\" & $filename, 2) FileWrite($hFilePath, 'DISM /Online /Enable-Feature /FeatureName:NetFX3 /All /Source:' & $dDrive & 'Sources\sxs /LimitAccess') FileClose($hFilePath) Or something like RunWait(@ComSpec & ' /c DISM /Online /Enable-Feature /FeatureName:NetFX3 /All /Source:' & $dDrive & 'Sources\sxs /LimitAccess') Or PowerShell -Command from cmd.
Subz Posted December 9, 2019 Posted December 9, 2019 Also you could just use _TempFile function for creating a random file name.
ambad4u Posted December 9, 2019 Author Posted December 9, 2019 @seadoggie01 Thank you for pointing out my issues with FileOpen/FileWrite..., it works now. @Subz Thank you for the heads-up on _TempFile Also, I have settled with a long one liner you posted RunWait(@ComSpec & ' /c DISM /Online /Enable-Feature /FeatureName:NetFX3 /All /Source:' & StringLeft(@ScriptDir, 3) & 'Sources\sxs /LimitAccess') seadoggie01 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now