.bat run as admin but I need logon user
Moderator: DosItHelp
.bat run as admin but I need logon user
Hi,
I run .bat as admin, but in script I run programs (call) and I must run it as logon user. I know that exist command runas /user: but how can I get automaticlly username?
I run .bat as admin, but in script I run programs (call) and I must run it as logon user. I know that exist command runas /user: but how can I get automaticlly username?
Re: .bat run as admin but I need logon user
%username%
Re: .bat run as admin but I need logon user
When I run bat as admin, %username% is admin name not logged user.
Re: .bat run as admin but I need logon user
Krump wrote:When I run bat as admin, %username% is admin name not logged user.
How are you running the batch file as admin?
Are you logged in as admin?
Re: .bat run as admin but I need logon user
I'm logged on some one user for example pltomywar. then i copy batch file from server to desktop and right click -> run as administrator. Next windows want admin autorization, so I write my admin pass for example login: plaxgo pass: 123456.
Re: .bat run as admin but I need logon user
Krump wrote:I'm logged on some one user for example pltomywar. then i copy batch file from server to desktop and right click -> run as administrator. Next windows want admin autorization, so I write my admin pass for example login: plaxgo pass: 123456.
I'm not sure what you are doing at all.
Explain the task fully and someone will help you.
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: .bat run as admin but I need logon user
Krump wrote:I'm logged on some one user for example pltomywar. then i copy batch file from server to desktop and right click -> run as administrator. Next windows want admin autorization, so I write my admin pass for example login: plaxgo pass: 123456.
Are you logged in to the server or the desktop? Because right-click->Run as Administrator doesn't change the value of %username%... unless you're logged into the Desktop as Administrator.
Re: .bat run as admin but I need logon user
I'm logged on te desktop as someone user and in this account run aplication as admin. And this change the value.
Re: .bat run as admin but I need logon user
Parse the output of one of these commands.
or
All I did was Google search for the main points of your question.
It was the first link Google Found.
Second Link Google found.
Code: Select all
query sessions
or
Code: Select all
query user
All I did was Google search for the main points of your question.
It was the first link Google Found.
Second Link Google found.
Code: Select all
WMIC ComputerSystem Get UserName
Re: .bat run as admin but I need logon user
Ou! It's very helpful. Now I trying inport it to my bat file.
Re: .bat run as admin but I need logon user
Hi, Is't me again unfortunatly
I have two problems.
First... When I use function "runas /user:" in bat file, it don't wait for ending task as like as using call (problem is that I run next .bat, not .exe). How I can to force for waiting?
Second... I use "FOR /F "tokens=2 delims='='" %%A in ('wmic ComputerSystem Get username /value') do SET user=%%A" and I have domain first (example: mydomain\username). How I can cut domain and slash. I want only username.
I have two problems.
First... When I use function "runas /user:" in bat file, it don't wait for ending task as like as using call (problem is that I run next .bat, not .exe). How I can to force for waiting?
Second... I use "FOR /F "tokens=2 delims='='" %%A in ('wmic ComputerSystem Get username /value') do SET user=%%A" and I have domain first (example: mydomain\username). How I can cut domain and slash. I want only username.
Re: .bat run as admin but I need logon user
Set user=%user:*\=%
Re: .bat run as admin but I need logon user
Great! Second works perfectly
And now stay only first, what I can do with it? runas is very nice command but it don't wait for ending.
Or maybe are another better ways to run .bat in .bat as admin.
And now stay only first, what I can do with it? runas is very nice command but it don't wait for ending.
Or maybe are another better ways to run .bat in .bat as admin.
Re: .bat run as admin but I need logon user
I am not sure if you are being clear on what is happening.
You said in a previous post that you are using the Right Click Context Menu to launch that batch file as your admin user.
I don't want to sit here an pull teeth. So if you can show us the batch file and explain how you are running it, we may be able to help with more information.
You said in a previous post that you are using the Right Click Context Menu to launch that batch file as your admin user.
I don't want to sit here an pull teeth. So if you can show us the batch file and explain how you are running it, we may be able to help with more information.
Re: .bat run as admin but I need logon user
I change conception (when I Right-Click as Admin on bat and when I start outlook, Outlook don't automatically import data -> logon admin account) So in main bat (I start normaly) do somthing operations (among other things, run outlook) and in first bat start as admin second .bat.
So step by step.
1. First bat start as normal user (bat copy, open, install everything what don't need admin powers and I can normaly use %username% %localappdata% %localapp% etc)
2. In first .bat I open another bat, where are operations whose needs admin powers, and I use this script in first to run second:
:AUTORIZATION
echo.
echo ________________________________________________
set /p login_usera=Admin name:
echo.
runas /user:mydomain.net\%login_usera% "\\Tablety\asadmin.bat"
if "%ERRORLEVEL%"=="1" goto AUTORIZATION
3. And when second bat start and do what it must, my first bat go further. I want first bat wait until the second bat finish do everything and close. Some like as "call" or "start /wait" with admin powers.
So step by step.
1. First bat start as normal user (bat copy, open, install everything what don't need admin powers and I can normaly use %username% %localappdata% %localapp% etc)
2. In first .bat I open another bat, where are operations whose needs admin powers, and I use this script in first to run second:
:AUTORIZATION
echo.
echo ________________________________________________
set /p login_usera=Admin name:
echo.
runas /user:mydomain.net\%login_usera% "\\Tablety\asadmin.bat"
if "%ERRORLEVEL%"=="1" goto AUTORIZATION
3. And when second bat start and do what it must, my first bat go further. I want first bat wait until the second bat finish do everything and close. Some like as "call" or "start /wait" with admin powers.
Last edited by Krump on 17 Dec 2014 14:59, edited 1 time in total.