DosTips.com

A Forum all about DOS Batch
It is currently 28 Jun 2016 10:47

All times are UTC-06:00




Post new topic  Reply to topic  [ 5 posts ] 
Author Message
PostPosted: 14 Jan 2012 02:03 
Offline
Expert

Joined: 04 Oct 2008 09:49
Posts: 357
I have a script which does things that UAC may object to.
It can detect a failure and suggest to the user to "Right Click and Run As Administrator".

Is it possible for the script to invoke itself by some sort of call / run / start / whatever /
and to thus run itself with elevated privileges, and if so how ?

I have tried and my password failed with
RUNAS /USER:Administrator D:\zz.BAT

I think I had success with that in the past, but that may have been whilst Windows login included the BuiltIn Administrator capability.

"Run As Administrator" does its job WITHOUT needing a password, is it a totally different animal from RUNAS ?

I am using Windows 7 Ultimate, but would like my script to be usable on "lower forms of life" which are also subject to UAC

Regards
Alan


Top
   
PostPosted: 14 Jan 2012 07:19 
Offline
Expert

Joined: 22 Jan 2010 18:01
Posts: 2046
Location: Germany
With the RUNAS command you can execute applications in another user account. Also for the user Administrator the UAC is enabled by default. Log in as Administrator and disable the UAC for this account. Now the RUNAS command would have probably the same effect as "Run As Administrator".

Regards
aGerman


Top
   
PostPosted: 14 Jan 2012 16:53 
Offline
Expert

Joined: 04 Oct 2008 09:49
Posts: 357
Sorry, I failed to explain my script is for myself and others with different abilities.
I cannot consider disabling Administator passwords or UAC.
Until today I had assumed RUNAS /USER:Administrator had a similar effect to
"Right Click and Run As Administrator".

All I wanted was that my BAT script should launch an executable with identical capability as "Right Click and Run As Administrator",
but that looks beyond reach.

I am now giving up and asking the user to "Right Click and Run As Administrator" when appropriate, as at
viewtopic.php?f=3&t=2797

Regards
Alan


Top
   
PostPosted: 06 Mar 2012 13:43 
Offline

Joined: 04 Oct 2011 14:01
Posts: 5
You can do it like this
Code:
@echo off
mkdir "%windir%\BatchGotAdmin"
if '%errorlevel%' == '0' (
  rmdir "%windir%\BatchGotAdmin" & goto gotAdmin
) else ( goto UACPrompt )
:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    echo UAC.ShellExecute %0, "", "", "runas", 1 >> "%temp%\getadmin.vbs"
    "%temp%\getadmin.vbs"
    exit /B
:gotAdmin
    if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
    pushd "%CD%"     
    CD /D "%~dp0"
"here you can put some stuff you want to execute"


The code detects if you got admin privileges, if not run the command as administrator, of course the user have to accept the pop up window.

Actually I use it to disable the user account control on a machine with Vista or 7


Top
   
PostPosted: 06 Mar 2012 15:34 
Offline
Expert

Joined: 13 Jan 2012 21:24
Posts: 469
alan_b wrote:
"Run As Administrator" does its job WITHOUT needing a password, is it a totally different animal from RUNAS ?
Yes, indeed. As confusing as MS chose to make UAC be, "run as administrator" does not mean "run under the administrator user account", but rather "run as the current user, but using its elevated token".

You may try something like...
Code:
psexec -accepteula -h cmd /c "%~0" 
using PsExec from PsTools http://technet.microsoft.com/en-us/sysinternals/bb897553.

Note that the "-h" switch is not documented on the PsExec page, yet shows up in its /? help:
'psexec /?' wrote:
-h If the target system is Vista or higher, has (sic) the process
run with the account's elevated token, if available.

Liviu


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 5 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], misol101, Yahoo [Bot] and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited