How to change a file's permission through powershell or command prompt

  1.    #1

    How to change a file's permission through powershell or command prompt


    Is there a way to make a file get executed automatically as admin through command prompt or powershell?
    Lets say there is a file.exe and I want to tick that box that says "execute as administrator" without right clicking the file and doing it through the user interface.
    Which Windows binary does that?
    I'm new on windows. I've been using GNU systems since I was 13 and I'm totally lost now that I need Windows.

    HALP.
      My ComputerSystem Spec

  2.   My ComputerSystem Spec

  3.    #3

    It depends if your user is part of the administrators group or not and whether you are talking about one exe or all of them.

    You could :

    1. Turn off UAC so all prompts would be auto approved - see Enable or Disable User Account Control (UAC) in Windows
    2. Enable the Administrator account and run programs by using a shortcut using their authority - see Create Elevated Shortcut without UAC prompt in Windows 10
    3. Write a script to auto-elevate your job without prompting - there are may ways to do this but see here for powershell or here for batch.

    You could also look at this for a wider perspective : Run as Administrator in Windows 10

    There are many ways to do it and if you are new to Windows you should understand that running as part of Administrators group is a huge security risk. It is trivial to auto-elevate and bypass UAC. If you can do it - so can any process you invoke or program you run.

    For example a lot of batch files you download will put just one line like this at the top
    Code:
    net sess>NUL 2>&1||(powershell saps '%0'-Verb RunAs&exit)
    which will grant administrator authority to that process without telling you even if you have UAC turned on.

    It is safer to run as standard user really.
    Last edited by lx07; 20 Oct 2018 at 13:43. Reason: Updated with TairikuOkami new tutorial not Windows 7 one
      My ComputerSystem Spec

  4.    #4

    lx07 said: View Post
    It depends if your user is part of the administrators group or not and whether you are talking about one exe or all of them.

    You could :

    1. Turn off UAC so all prompts would be auto approved - see Enable or Disable User Account Control (UAC) in Windows
    2. Enable the Administrator account and run programs by using a shortcut using their authority - see Create Elevated Shortcut without UAC prompt in Windows 10
    3. Write a script to auto-elevate your job without prompting - there are may ways to do this but see here for powershell or here for batch.

    You could also look at this for a wider perspective : Run as Administrator in Windows 10

    There are many ways to do it and if you are new to Windows you should understand that running as part of Administrators group is a huge security risk. It is trivial to auto-elevate and bypass UAC. If you can do it - so can any process you invoke or program you run.

    For example a lot of batch files you download will put just one line like this at the top
    Code:
    net sess>NUL 2>&1||(powershell saps '%0'-Verb RunAs&exit)
    which will grant administrator authority to that process without telling you even if you have UAC turned on.

    It is safer to run as standard user really.
    The script I'm running requires admin privileges, and it needs to start by itself as admin after the user logs in.
    If UAC is left enabled, then the user would need to click "yes" to give permission to the script every time he logged in?
    I'm skeptical about turning UAC off, even though the user won't be downloading anything really.

    How come there are processes that start with SYSTEM and admin privileges when you log in and I can't do the same by changing something? There must be some way to hack my way in.
    I don't know if such thing exists, but in Linux its a matter of giving the file executing permission with a +x flag and putting it in a folder (depending wether you use upstart or systemD), and every time you log in it auto starts as a daemon and with root privileges. Is it possible on Windows?

    Thanks for the support. :)
      My ComputerSystem Spec

  5.    #5

    If your user is part of Administrators group you could trigger the script to start at logon using TaskScheduler. If you specify ''Run with highest privileges" it will run in Administrator context as described here : Create Elevated Shortcut without UAC prompt in Windows 10 | Windows 10 Tutorials

    If your user isn't part of Administrators group the only way I know to do it is to run it as a service (which is like a daemon). This is very easy using a program called nssm as described here : How do make programs run at startup on standard user account? - Windows 10 Forums

    You can chose the account to run the service under - by default it is SYSTEM.

    Neither method will invoke UAC prompt whether it is turned on or not.
      My ComputerSystem Spec

  6.    #6

    lx07 said: View Post
    If your user is part of Administrators group you could trigger the script to start at logon using TaskScheduler. If you specify ''Run with highest privileges" it will run in Administrator context as described here : Create Elevated Shortcut without UAC prompt in Windows 10 | Windows 10 Tutorials

    If your user isn't part of Administrators group the only way I know to do it is to run it as a service (which is like a daemon). This is very easy using a program called nssm as described here : How do make programs run at startup on standard user account? - Windows 10 Forums

    You can chose the account to run the service under - by default it is SYSTEM.

    Neither method will invoke UAC prompt whether it is turned on or not.
    I am, myself, the administrator of all machines, so privileges aren't a problem.
    Can I do that by command line? The idea is to code a very simple script that will authorize a file to start at login and as admin and pass it through all machines so I don't have to go one by one.

    I'm a volunteer at school. There is a program that the government made to help elders learn how to use the computer, its very basic stuff, but it requires admin privileges to run, and I don't know why since its very basic and would totally run with user privileges.
    By policy, I'm supposed to turn off the machines after they've been used, and also turn them on just before they get used. We do that to save money.
    There are 40 PCs in the room and going over each of them individually just to click yes at startup would be so frustrating. The same applies to the tutorials you linked here.

    The idea is to create a batch script that will move the binary file to the startup folder (if there is such a thing on windows) and give it permission (or flag) so Windows will see it at login and start it with admin privileges.
    I'll turn on the computer, windows will login automatically (since there is no password) and the program will show up on screen without the need to click yes. That saves a lot of time and power.

    I'm skeptical about disabling UAC since the computers are connected to the internet and there is no firewall.
      My ComputerSystem Spec

  7.    #7

    If you go the scheduled task route, once you get it working on one PC you can export the task from task scheduler. This will create an xml file with the task definition.

    Assuming your other PC have common user name you can either manually import it using Task Manager on each of your 40 PCs. This would only have to be done once. See : windows 7 - How to import a scheduled task from an XML file? - Super User

    Alternatively you should be able to apply it remotely using the built in schtasks.exe. Assuming you saved the xml as "task.xml" it would be something like
    Code:
    schtasks.exe /Create /XML "task.xml" /tn "Your Task Name" /S <PC name> /U <Domain\User Name> /P <Password>
    You would have to open up Remote Scheduled Tasks Management in each machines Firewall though so it may be quicker to just import it direct into each machines Task Manager.
      My ComputerSystem Spec


 

Related Threads
Don't these programs do essentially the same thing? Is there an advantage to use one over the other? Just curious.
How do you change from PowerShell to Command Prompt using file explorer ?
How to Show Command Prompt or Windows PowerShell on Win+X menu in Windows 10 The Win+X Quick Link menu is a pop-up menu from the Start button that includes shortcuts of common management, configuration, and other power user Windows tools. ...
Hello, I'm looking for a way to check PC's IP Geolocation by using command prompt or powershell (no scripts). I hope there are some experts here who can help me out. I have found a very easy to do it on UNIX systems but my main machines will be...
Show Command Prompt or PowerShell in Win+X Power User Tasks Menu in Windows 10 This tutorial will show you how to have either the Command Prompt or Windows PowerShell items show in your Win+X Power User Tasks menu in Windows 10 ...

Tags for this Thread

Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 13:55.
Find Us