Launch Elevated CMD - how?
-
SkyFrontier
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Launch Elevated CMD - how?
Hi, there.
How could I launch an elevated CMD prompt with, say, "netsh wlan start hostednetwork" ready to be ENTER'ed?
How could I launch an elevated CMD prompt with, say, "netsh wlan start hostednetwork" ready to be ENTER'ed?
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
-
highend
- Posts: 14993
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Launch Elevated CMD - how?
You mean: Dos box open, and you still need to press enter to execute that specific command?
If you want to write that string after the prompt of the dos box you probably could do it with an .ahk script (untested)...
Code: Select all
$comspec = ("%osbitness%" == 64) ? "%windir%\System32\cmd.exe" : "%windir%\SysWOW64\cmd.exe";
$cscript = ("%osbitness%" == 64) ? "%windir%\System32\cscript.exe" : "%windir%\SysWOW64\cscript.exe";
$vbsFile = "%TEMP%\~OpenElevatedCMD.vbs";
$vbsContent = <<<>>>
Set UAC = CreateObject("Shell.Application")
UAC.ShellExecute "$comspec", "/k ECHO netsh wlan start hostednetwork & PAUSE >NUL & netsh wlan start hostednetwork", "", "runas", 1
>>>;
writefile($vbsFile, trim($vbsContent));
run """$cscript"" ""$vbsFile"" //nologo", , 0, 0;One of my scripts helped you out? Please donate via Paypal
-
highend
- Posts: 14993
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Launch Elevated CMD - how?
If the command needs to be editable...
Code: Select all
#NoEnv
#SingleInstance, Force
#NoTrayIcon
if not A_IsAdmin
{
Run, *RunAs "%A_ScriptFullPath%"
ExitApp
}
Run, %comspec% /k, , , pid
WinWaitActive, %comspec% ahk_pid %pid%
ControlSend, , netsh wlan start hostednetwork, ahk_pid %pid%
One of my scripts helped you out? Please donate via Paypal
-
SkyFrontier
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Re: Launch Elevated CMD - how?
I was afraid that it was no direct way which would avoid bat files creation. That's why I thought at least a "open elevated, sendkeys(<parameters>), wait for user to hit enter" operation would be possible.
Thanks again... nice day there!
Thanks again... nice day there!
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
-
highend
- Posts: 14993
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Launch Elevated CMD - how?
Open a command prompt and using sendkeys would work but...
1. XY needs to be started with admin permissions to be able to open a command prompt with the necessary rights
2. What happens if you're working while you execute that script? The sendkeys can fail (send keys to the wrong window)
3. XY has no internal way to make sure a specific window is active before executing the sendkeys command
The .ahk way is the easiest and it doesn't create temporary files. Con: big (compiled) file size
1. XY needs to be started with admin permissions to be able to open a command prompt with the necessary rights
2. What happens if you're working while you execute that script? The sendkeys can fail (send keys to the wrong window)
3. XY has no internal way to make sure a specific window is active before executing the sendkeys command
The .ahk way is the easiest and it doesn't create temporary files. Con: big (compiled) file size
One of my scripts helped you out? Please donate via Paypal
-
SkyFrontier
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Re: Launch Elevated CMD - how?
In this specific case I'm trying to automate the dumb operations themselves, no extra scripting intended.
I noticed there's no buffer for me to re-use the launched command by pressing up/down arrow keys, so sendkeys() could be a solution. I'll work later on this and report back if I stumble into dumbness.

I noticed there's no buffer for me to re-use the launched command by pressing up/down arrow keys, so sendkeys() could be a solution. I'll work later on this and report back if I stumble into dumbness.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
-
SkyFrontier
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Re: Launch Elevated CMD - how?
No other way I could keep the elevated CMD window opened, having the entered command at my disposal on arrow up, highend, thus avoiding future extra typing for reuse or edit?
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
-
totmad1
- Posts: 131
- Joined: 24 Jun 2013 12:37
Re: Launch Elevated CMD - how?
I was wondering if you had looked at nircmd from nirsoft it has two commands,
which might be relevant , elevate and elevatecmd the last one elevates its own commands.
The use of this utilty/cli does not require elevating XY.
which might be relevant , elevate and elevatecmd the last one elevates its own commands.
The use of this utilty/cli does not require elevating XY.
totmad1 (totally mad one)
-
yusef88
- Posts: 1148
- Joined: 28 Jan 2013 03:50
- Location: Windows 8.1 32-bit
Re: Launch Elevated CMD - how?
I use it like thistotmad1 wrote:I was wondering if you had looked at nircmd from nirsoft it has two commands,
which might be relevant , elevate and elevatecmd the last one elevates its own commands.
The use of this utilty/cli does not require elevating XY.
Code: Select all
run "nircmd elevate net user %username% *"-
highend
- Posts: 14993
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Launch Elevated CMD - how?
Mh? You want a cmd window which has it's history included?having the entered command at my disposal on arrow up, highend, thus avoiding future extra typing for reuse or edit
One of my scripts helped you out? Please donate via Paypal
-
SFmob
- Posts: 2
- Joined: 01 Aug 2015 09:10
Re: Launch Elevated CMD - how?
if by history you mean the first (auto) entered command, 'netsh wlan...', in case, then yes, because it's base for further actions.
__
mob profile, sorry
__
mob profile, sorry
-
highend
- Posts: 14993
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Launch Elevated CMD - how?
From your first post:if by history you mean the first (auto) entered command
You didn't want it "auto-entered"...How could I launch an elevated CMD prompt with, say, "netsh wlan start hostednetwork" ready to be ENTER'ed?
If that has changed:
Code: Select all
#NoEnv
#SingleInstance, Force
#NoTrayIcon
if not A_IsAdmin
{
Run, *RunAs "%A_ScriptFullPath%"
ExitApp
}
SetKeyDelay, 0
Run, %comspec% /k, , , pid
WinWaitActive, %comspec% ahk_pid %pid%
ControlSend, , netsh wlan start hostednetwork{Enter}, ahk_pid %pid%
One of my scripts helped you out? Please donate via Paypal
-
SkyFrontier
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Re: Launch Elevated CMD - how?
Sorry, now I see I wasn't clear on that sentence.
Thanks much!
Is there a way to
, no prompt, no window flash?
Thanks much!
Is there a way to
Code: Select all
run """cmd.exe -netsh wlan start hostednetwork""";New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
-
highend
- Posts: 14993
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Launch Elevated CMD - how?
run - show = 0?
One of my scripts helped you out? Please donate via Paypal
-
SkyFrontier
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Re: Launch Elevated CMD - how?
Forgot that one, thanks!
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
XYplorer Beta Club