Deactivate admin privileges

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Potatismoose
Posts: 1
Joined: 14 Oct 2018 15:45

Deactivate admin privileges

#1 Post by Potatismoose » 14 Oct 2018 16:05

I'm having some problems with a script i'm making. Here is a short background. At my work (a computer store) we do alot of installations for the customers. Until now we have done most of the installations manually wich have been a pain in the ass. So I started to write a script. The script contains alot of tools for our daily work and it has a total of 20 something batch files for different purposes. So the main bat file is called start and I run that with admin privileges (thru a shortcut). The admin rights is nessecery for the whole script to work properly. What I´ve noticed is that the admin rights seem to be inherited to other bat files that you use the call or start command on. Here comes the problem. One of the bat files downloads the spotify installer, starts the installer and should install the program. BUT... spotify installer does not allow you to run it with admin rights. It just pops up a messagebox that says something like "Run this program as a standard user, not as an administrator".

I find this very strange. Is there a work around for this? I have not found anything when I googled if there is a command for temporarily removing the inherited admin rights for a bat file.

If I run the spotify bat file directly without starting the elevated start.bat file first, it works perfectly. But f I run it thru the main file (start.bat) it won´t work.

Anyone who sits on a solution for this?

The, not so good, solution I´ve managed to create so far is this:
Starting start.bat
Automatically copying spotify.bat to autostart
Automatically restarting computer with shutdown.exe -r -t 0
spotify.bat runs thru autostart, downloads spotify and installs the program. It then deletes the downloaded installation file and the .bat in autostart and restarts the start.bat again so the user can continue the installation.

Is there another, more convinient way so you dont need to restart the computer?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Deactivate admin privileges

#2 Post by aGerman » 15 Oct 2018 14:03

a.bat

Code: Select all

@echo off &setlocal
:: If you run a batch script via "Run as administrator" then the working directory gets automatically changed to %SystemRoot%.
cd /d "%~dp0"

:: Test
echo %~nx0
>nul 2>&1 net session &&(echo Elevated.)||(echo Not elevated.)

:: Once the explorer already runs without elevation, another thread can't be run elevated.
:: Thus, passing the other batch script to explorer.exe will lead in a cmd.exe process without elevation.
start "" "explorer.exe" "b.bat"

pause

b.bat

Code: Select all

@echo off &setlocal

:: Test
echo %~nx0
>nul 2>&1 net session &&(echo Elevated.)||(echo Not elevated.)

pause
Put both scripts in the same folder and run a.bat as admin via right click.

However, I don't know if that will work for you. If you're logged on with an admin account then explorer.exe might be elevevated already. Also keep in mind that the account will not change that way. If you need the program to be installed under the user account then your current workarount might not be too bad.

Steffen

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Re: Deactivate admin privileges

#3 Post by miskox » 16 Oct 2018 04:55

Is scheduled task a solution?

Maybe you can create a scheduled task, run it and then delete it when it is done?

Saso

Post Reply