Windows 10: Run User Program As Administrator

Discus and support Run User Program As Administrator in Windows 10 Software and Apps to solve the problem; I want to create a small program (bat, exe, PowerShell, whatever) to delete all Event logs. I want to put this on the C drive (not a shortcut on the... Discussion in 'Windows 10 Software and Apps' started by vanp, Feb 23, 2017.

  1. vanp Win User

    Run User Program As Administrator


    I want to create a small program (bat, exe, PowerShell, whatever) to delete all Event logs. I want to put this on the C drive (not a shortcut on the desktop), double-click it, and it runs. I don't want to have to right-click and choose Run as administrator. Approving the UAC prompt is OK. I'm not a programmer, so I have to go with what I see on the Internet.

    I have a shortcut on the desktop (again, not what I want), but it does exactly what I want. The code is: C:\Windows\System32\cmd.exe /k for /F "tokens=*" %1 in ('wevtutil.exe el') DO wevtutil.exe cl "%1".

    I also have a bat file created by Brink that I put on the C drive (where I want it) that requires me to click on Run as administrator (again, not what I want). The code is: for /F "tokens=*" %%a in ('wevtutil.exe el') DO wevtutil.exe cl "%%a". Plus, I put a PAUSE in there at the end.

    I've tried various methods I've seen to try to get something to run automatically as administrator, but nothing has worked. I also tried IExpress, but that didn't work.

    Why is this so complicated, and why does something have to be a shortcut to have the Run as administrator checkbox?

    Can anybody make this happen? Is it even possible? Thanks.

    (And please, no lectures about the advisability of deleting the Event logs. Thanks.)

    :)
     

  2. Program needs "run as administrator" rights in windows 10

    Thanks for response.

    Actually program was supported in XP, Vista and win & also.

    I tried changing compatibility to all this but didnt work.

    What I wonder is that even though I choose "run as administrator" option or I use administrator login, still I receive this error that program needs administrator priviledges.
     
    NirajParikh, Feb 23, 2017
    #2
  3. Program needs "run as administrator" rights in windows 10

    I had used Radar 10 software in windows vista earlier.

    When I installed radar 10 in new laptop with windows 10, I am not able to open it.

    The error comes that "to use this program, you must have administrative privileges. Try to open with "run as administrator"."

    I had tried the same but didn't worked.

    I also tired changing windows user to administrator, started windows in administrator but also cant open it and same error is received.

    Please help me.

    One more thing.

    When I try to change the "type of account" of my user account from standard to administrator, I am not able to do that.
     
    NirajParikh, Feb 23, 2017
    #3
  4. lx07 Win User

    Run User Program As Administrator

    You can use the code from here to auto-elevate your batch file. It will check if you are running as administrator and if not relauch (you'll get the UAC prompt).

    windows - How can I auto-elevate my batch file, so that it requests from UAC administrator rights if required? - Stack Overflow

    Just put what your want after ::START. I put for /f %%a in ('WEVTUTIL EL') do WEVTUTIL CL "%%a" to clear event logs but you can put what you want. Save it as "ClearLogs.bat" or whatever name you like with .bat on the end.

    Code: :::::::::::::::::::::::::::::::::::::::::::: :: Elevate.cmd - Version 4 :: Automatically check & get admin rights :::::::::::::::::::::::::::::::::::::::::::: @echo off CLS ECHO. ECHO ============================= ECHO Running Admin shell ECHO ============================= :init setlocal DisableDelayedExpansion set cmdInvoke=1 set winSysFolder=System32 set "batchPath=%~0" for %%k in (%0) do set batchName=%%~nk set "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs" setlocal EnableDelayedExpansion :checkPrivileges NET FILE 1>NUL 2>NUL if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges ) :getPrivileges if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges) ECHO. ECHO ************************************** ECHO Invoking UAC for Privilege Escalation ECHO ************************************** ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%" ECHO args = "ELEV " >> "%vbsGetPrivileges%" ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%" ECHO args = args ^& strArg ^& " " >> "%vbsGetPrivileges%" ECHO Next >> "%vbsGetPrivileges%" if '%cmdInvoke%'=='1' goto InvokeCmd ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%" goto ExecElevation :InvokeCmd ECHO args = "/c """ + "!batchPath!" + """ " + args >> "%vbsGetPrivileges%" ECHO UAC.ShellExecute "%SystemRoot%\%winSysFolder%\cmd.exe", args, "", "runas", 1 >> "%vbsGetPrivileges%" :ExecElevation "%SystemRoot%\%winSysFolder%\WScript.exe" "%vbsGetPrivileges%" %* exit /B :gotPrivileges setlocal & cd /d %~dp0 if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul & shift /1) :::::::::::::::::::::::::::: ::START :::::::::::::::::::::::::::: for /f %%a in ('WEVTUTIL EL') do WEVTUTIL CL "%%a" pause[/quote]
     
  5. vanp Win User
    Ix07, thanks for your reply.

    Four things:

    1. Since I already know I'm not running as administrator (even though my user ID is set as administrator--M$ sucks), can we simplify your code by removing whatever lines constitute the check?

    2. I went to the link you gave. There are a lot of comments/answers following the basic question at least implying things can be done more simply. Can any of that stuff be used to slim down the code you provided?

    3. Isn't there just a one-line command of some sort, like 'runas', that can say to run the code as administrator?

    4. As far as I'm concerned, this doesn't have to be a .bat file. Can something else like PowerShell, .exe, whatever be used to produce a simpler solution?

    Thanks again for your response.
     
  6. D4ni3l Win User
    Code: %SystemRoot%\System32\runas.exe /user:YOUR-PC-NAME\Administrator /savecred "%SystemRoot%\System32\cmd.exe" %SystemRoot%\System32\runas.exe /user:YOUR-PC-NAME\Administrator /savecred %SystemRoot%\regedit.exe %SystemRoot%\System32\runas.exe /user:YOUR-PC-NAME\Administrator /savecred %SystemRoot%\System32\CompMgmtLauncher.exe[/quote]
    Run User Program As Administrator [​IMG]


    i have created many shortcuts as above to run any program as Administrator
    Administrator password is only asked one time

    Create a shorcut pointing your batch file and that's it
    may be this will help you *Biggrin
     
    D4ni3l, Feb 23, 2017
    #6
  7. Pyprohly Win User
    Don’t use the code that’s going around as demonstrated in lx07’s post. It’s unfortunately very poorly programmed.

    I have a couple of my own solutions to this, including one-liners, in the thread How to run Batch File as Admin?

    See post #21 for one-line solutions.
    See post #22 for a stable solution.
    See post #26 for a bypass UAC solution.

    @vanp If you need assistance implementing any of theses, just give the word.
     
    Pyprohly, Feb 24, 2017
    #7
  8. vanp Win User

    Run User Program As Administrator

    D4ni3l, thanks for your help, but again, I already have a shortcut, and that's not how I want to implement this task.

    Pyprohly, you appear to be the MAN. All I ever wanted was the simplest (hopefully, one-line) solution, and you seem to have it.

    First, I tried the 2nd PowerShell line from post 21. It displayed the black Command Prompt screen for a few seconds, and I thought it was hung there. Then it displayed the UAC prompt, in focus, and I chose Yes. Then it started running the command to delete the logs. That worked.

    Then I tried the VBScript line from post 21. It displayed the black Command Prompt screen but for a much shorter time. Then everything progressed as above.

    Then I went back to the 2nd PowerShell line again. It displayed the black Command Prompt screen but for a much shorter time than at first. Then everything worked again as it should.

    As I stated in my OP, dealing with the UAC prompt is acceptable. I guess ideally it wouldn't be there, but I don't want to add a lot of extra code to suppress it. Also, who knows, in the future M$ might do something that would cause it not to work, or worse.

    I'll experiment with these two lines of code. If they seem about equal I guess I'll settle on the shortest line.

    So, unless somebody comes up with an alternate solution that is somehow better than one line of code, I'll consider this the solution. When I make a final decision, I'll mark the thread as solved.

    Thanks to everybody who responded, including Brink, who apparently deleted his (the first) response and my reply.
     
  9. lx07 Win User
    Those are really quite clever especially the event viewer one.

    Proves you should not run as a user that is part of Administrators group. I thought before it didn't matter if you ran as Standard or Admin user as UAC would take care of it. I was wrong apparently.

    I'd hope MS close down that loophole though to be honest.
     
    lx07, Apr 5, 2018
    #9
Thema:

Run User Program As Administrator

Loading...
  1. Run User Program As Administrator - Similar Threads - Run User Program

  2. Allow specific program to run under non administrator user

    in Windows 10 Gaming
    Allow specific program to run under non administrator user: Hello,On windows 10 PC connected to a domain, with a non administrator user, we get for a specific program this message :"do you want to allow this app from an unknown publisher to make changes to your device."We d like to permanently allow this program.Is there a way to do...
  3. Allow specific program to run under non administrator user

    in Windows 10 Software and Apps
    Allow specific program to run under non administrator user: Hello,On windows 10 PC connected to a domain, with a non administrator user, we get for a specific program this message :"do you want to allow this app from an unknown publisher to make changes to your device."We d like to permanently allow this program.Is there a way to do...
  4. Allow specific program to run under non administrator user

    in AntiVirus, Firewalls and System Security
    Allow specific program to run under non administrator user: Hello,On windows 10 PC connected to a domain, with a non administrator user, we get for a specific program this message :"do you want to allow this app from an unknown publisher to make changes to your device."We d like to permanently allow this program.Is there a way to do...
  5. Can't run programs as an administrator

    in Windows 10 BSOD Crashes and Debugging
    Can't run programs as an administrator: Hey, so recently I posted a question related to an issue with the windows installer. After looking into it, and encountering similar issues with other programs, I managed to figure out the fix would be to run the sfc. And that's when another problem emerged, I try to run...
  6. Can't run programs as an administrator

    in Windows 10 Performance & Maintenance
    Can't run programs as an administrator: Hey, so recently I posted a question related to an issue with the windows installer. After looking into it, and encountering similar issues with other programs, I managed to figure out the fix would be to run the sfc. And that's when another problem emerged, I try to run...
  7. Programs always run as administrator without checking "Run this program as an administrator"

    in Windows 10 Network and Sharing
    Programs always run as administrator without checking "Run this program as an administrator": Hello as the title says random things have an administrator icon shield thing and when I open it, it says Do you want to allow this program, etc normal run as administrator stuff and when I go in properties then compatibility I don't have checked "Run this program as an...
  8. Unable to run Programs as Administrator

    in Windows 10 Customization
    Unable to run Programs as Administrator: I have recently noticed that, although I am shown as Administrator in my Profile and "netplwiz" confirms this, I am unable to run Programs as Administrator. They all open and run OK on double click. Anyone know what might be causing this? Cheers. Ken...
  9. Run Administrator Programs in Startup of Standard User

    in User Accounts and Family Safety
    Run Administrator Programs in Startup of Standard User: I have both an administrator and standard account on my laptop. I use the standard account for every general task and do not use the administrator account unless absolutely needed. There are two pieces of software I want to run at startup every time either my standard account...
  10. Issue with running programs as administrator

    in Windows 10 Customization
    Issue with running programs as administrator: Hi there. Couple days ago I formatted my SSD drive and reinstalled Windows 10 on it. Since that moment I have issues with account I use(lets call it ABC) even though I granted admin permission on every layer is known to me. I can't run some .exe files like CITRIX Workspace...