Sorry i still very new to script and Autohotkey. I searching a long period but i still can't get multi command to execute in admin power shell. Can anyone advice me is there any short cut ways to key these fixed command into powershell. As i need to keep repeating the command in quite a number of PC, is there any shortcut i can use in AHK? I try use Send command, but dont' work in powershell. I also use clipboard :- "", but dont' really work well in powershell.
First i use AHK to lauch my admin powershell
Run, powershell Start-Process powershell -Verb runAs
Then, i want to run several command in order and can key them all in the powershell with just press of shortcut key
- cd\
- cd users\ABC\123
- Test-NetConnection (example only, cause there is my company using other software to link)
Then i need to go another directory to run another command
- cd\
- cd users\XYZ\321
- Test firewall(example too)
Thanks
Powershell script or AHK
-
- Posts: 2
- Joined: 26 Dec 2021, 20:54
Re: Powershell script or AHK
Here are some tips. viewtopic.php?f=76&t=82830
Re: Powershell script or AHK
not sure , maybe can use DOS .. (?)
Code: Select all
;- example start 2 DOS window with commands
;- use F8 and F9
#warn
#singleinstance,force
setworkingdir,%a_scriptdir%
WA:=A_screenwidth,x:=(WA*50)/100
$F8::
e1=
(Ltrim join&&
@echo off
echo date=
date /t
echo time=
time /t
cd\
dir
ver
)
title2=DOS_TEST1
run, %comspec% /T:0A /k "title %title2%&mode con lines=4000 cols=120&%e1%,,,pid1
WinWait, ahk_pid %pid1%
WinMove, ahk_pid %pid1%, ,1,1,, ;- move DOS window to the defined position
return
$F9::
e1=
(Ltrim comments join&&
@echo off
dir
ver
charmap ;- start charmap
rem test2.ahk
)
title2=DOS_TEST2
run, %comspec% /T:06 /k "title %title2%&mode con lines=4000 cols=120&%e1%,,,pid2
WinWait, ahk_pid %pid2%
WinMove, ahk_pid %pid2%, ,x,1,, ;- move DOS window to the defined position
return
Re: Powershell script or AHK
Code: Select all
code =
(Join;
echo hello
pause
)
cmd = powershell Start-Process powershell -ArgumentList "``-Command,{%code%}" -Verb runAs
Run, %cmd%,, Hide
Code: Select all
code =
(
echo hello
pause
)
Run, *RunAs "powershell" -Command "&{%code%}"
Re: Powershell script or AHK
@tmplinshi
thank you for the powershell examples
never used yet ...
( in this example the command 'ver' not exist )
thank you for the powershell examples
never used yet ...
( in this example the command 'ver' not exist )
+ CategoryInfo : ObjectNotFound: (ver:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Code: Select all
code =
(Join;
cd\
dir
charmap
ver
C:\test.ahk
echo hello
pause
)
cmd = powershell Start-Process powershell -ArgumentList "``-Command,{%code%}" -Verb runAs
Run, %cmd%,, Hide
return
/*
code =
(
cd\
dir
echo hello
pause
)
Run, *RunAs "powershell" -Command "&{%code%}"
return
*/
Who is online
Users browsing this forum: Bing [Bot], VanVarden and 97 guests