通过自动热键脚本运行powershell命令
我希望能够通过自动热键脚本运行以下PowerShell命令:通过自动热键脚本运行powershell命令,powershell,scripting,autohotkey,Powershell,Scripting,Autohotkey,我希望能够通过自动热键脚本运行以下PowerShell命令: new-item -path c:\ -name logfiles -itemtype directory 我找不到完成这项任务的方法。请帮忙 试试看: Run, PowerShell "new-item -path c:\ -name logfiles -itemtype" 似乎对我有用 根据新提供的信息进行编辑: 找到命令@ 尝试: PowerShell不是解决此特定问题所必需的 AutoHotKey具有创建目录的内置功能:
new-item -path c:\ -name logfiles -itemtype directory
我找不到完成这项任务的方法。请帮忙 试试看:
Run, PowerShell "new-item -path c:\ -name logfiles -itemtype"
似乎对我有用
根据新提供的信息进行编辑:
找到命令@
尝试:
PowerShell不是解决此特定问题所必需的 AutoHotKey具有创建目录的内置功能: 例如:
FileCreateDir, C:\logfiles
如果您希望从ahk运行PowerShell脚本,并且该脚本包含多行代码,并且不希望使用外部文件,则以下是一个示例: 自动热键代码:
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%'
@乍得。。我提供的命令只是一个例子。实际上,我想运行以下文章中的“AddWindowsFeature”命令:但我无法运行它,因为有一个错误显示变量名太长。请推荐。你提供的那个也适合我。但是,当我使用“AddWindowsFeature”命令而不是示例中的命令时,会出现一个错误,即变量名太长。请提供任何建议。我编辑了代码,将添加Windowsfeature代码添加到其中,但您尚未报告它是否正常工作?运行此操作后,我收到相同的错误。你还能想到别的办法吗?非常感谢。请使用PowerShell提示符中的
获取有关_PowerShell | exe |更多
的帮助,以了解使用调用运算符的原因。
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%'