通过AutoHotKey脚本运行powershell命令

时间:2015-09-04 11:31:08

标签: powershell scripting autohotkey

我希望能够通过AutoHotKey脚本运行以下PowerShell命令:

new-item -path c:\ -name logfiles -itemtype directory

我无法找到实现此任务的方法。请帮忙。

3 个答案:

答案 0 :(得分:3)

如果你想从ahk运行PowerShell脚本并且它包含多行,而你不想使用外部文件,这是一个例子:

AutoHotkey代码:

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%'   

答案 1 :(得分:1)

尝试:

Run, PowerShell "new-item -path c:\ -name logfiles -itemtype"

似乎为我工作。

根据新提供的信息进行编辑:

命令找到@ http://exchangeserverpro.com/install-exchange-2013-pre-requisites-windows-server-2012/

尝试:

Run, PowerShell "Install-WindowsFeature AS-HTTP-Activation
                , Desktop-Experience
                , NET-Framework-45-Features
                , RPC-over-HTTP-proxy
                , RSAT-Clustering
                , Web-Mgmt-Console
                , WAS-Process-Model
                , Web-Asp-Net45
                , Web-Basic-Auth
                , Web-Client-Auth
                , Web-Digest-Auth
                , Web-Dir-Browsing
                , Web-Dyn-Compression
                , Web-Http-Errors
                , Web-Http-Logging
                , Web-Http-Redirect
                , Web-Http-Tracing
                , Web-ISAPI-Ext
                , Web-ISAPI-Filter
                , Web-Lgcy-Mgmt-Console
                , Web-Metabase
                , Web-Mgmt-Console
                , Web-Mgmt-Service
                , Web-Net-Ext45
                , Web-Request-Monitor
                , Web-Server
                , Web-Stat-Compression
                , Web-Static-Content
                , Web-Windows-Auth
                , Web-WMI
                , Windows-Identity-Foundation"

答案 2 :(得分:0)

PowerShell并不是解决这一特定问题所必需的。

AutoHotKey具有用于创建目录的内置功能:FileCreateDir

例如:

FileCreateDir, C:\logfiles