Question:
I want to be able to run a following PowerShell command through AutoHotKey script:
1 2 |
new-item -path c:\ -name logfiles -itemtype directory |
I am unable to find a way to achieve this task. Please help.
Answer:
If you want to run a PowerShell script from ahk and it contains several lines and you don’t want to use an external file, this is an example how do it:
AutoHotkey code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
psScript = ( param($param1, $param2) new-item -path $param1 -name logfiles -itemtype directory new-item -path $param2 -name logfiles -itemtype directory remove-item -path 'c:\temp' # etc, write any code, use this quotes for strings: ' # if you need ", then write: \": $import = '[DllImport(\"ntdll.dll\")] public static extern int RtlAdjustPrivilege(ulong a, bool b, bool c, ref bool d);' ) param1 = C:\temp param2 = D:\temp RunWait PowerShell.exe -Command &{%psScript%} '%param1%' '%param2%',, hide ; use this call if you want to see powershell output Run PowerShell.exe -NoExit -Command &{%psScript%} '%param1%' '%param2%' |