write Administrator batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
wdegrandis
Posts: 2
Joined: 17 Dec 2012 18:32

write Administrator batch

#1 Post by wdegrandis » 17 Dec 2012 18:41

I am writing a batch file. Is there code I can add to have It run as Administrator? I know If I right click I can click on "run as Administrator". I would like to give this to a newbee for computers and let them run It by clicking on It.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: write Administrator batch

#2 Post by foxidrive » 18 Dec 2012 01:41

Try this: it will create a folder called c:\windows\system32\test123 and then echo the folder name to the screen if it has admin permissions.
Your code replaces the code after the :start label.

It will still generate a UAC prompt to confirm you want to run the code.


Code: Select all

@echo off
if "%~1"=="a" goto :start
:getfile
set "file=%temp%\%random%.file.vbs"
if exist "%file%" goto :getfile

>"%file%" echo Set UAC = CreateObject("Shell.Application")
>>"%file%" echo UAC.ShellExecute "%~f0", "a", "", "runas", 1
start "" "%file%"
goto :EOF

:start

md "%windir%\system32\test123"
cd "%windir%\system32\test123"
echo %cd%
cd..
rd "%windir%\system32\test123"
pause

wdegrandis
Posts: 2
Joined: 17 Dec 2012 18:32

Re: write Administrator batch

#3 Post by wdegrandis » 18 Dec 2012 07:29

What I wanted to sent It to someone who Is a normal user and let them run the batch file In Administrator. For example: If I write a batch file to change the user password (I know you can do that from Windows 7). You only can do that from Admin. So I want to change user In a batch file from a User to Admintrator?

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: write Administrator batch

#4 Post by Dos_Probie » 18 Dec 2012 17:30

Here u go.. :mrgreen:

Code: Select all

@echo off

:: Enable Hidden Administrator Account
net user administrator /active:yes

:: Disable
net user administrator /active:no

:: Or with WMIC
wmic useraccount where name='administrator' set disabled='false'
:: Disable
wmic useraccount where name='administrator' set disabled='true'

Post Reply