Looking for syntax to run shortcut as local admin RRS feed

  • Question

  • Hello,

              I'm looking for the proper syntax to run a shortcut as the local machine administrator, not the current user 'as administrator. I have a program that can ONLY run as the local admin, so I'd like a batch file to run it.

    My issue is, specifying the machine name, since all of them will be different, obviously. I was thinking something like:

    runas/user:domainname\administrator name.lnk

    The admin is not a domain account. So how do I write this to reflect the current pc, whatever it may be?
    Does .\ work somehow for a current pc name?


    Wednesday, July 10, 2019 3:37 PM

All replies

  • I guess I'm having trouble just running the shortcut at all with a batch file.

    I'm using

    runas /user:administrator "C:\users\public\desktop\shortcut.lnk" and after it prompts for a p/w, nothing opens.

    This seems rudimentary and I should know this but I'm not getting it. I'm hoping to bake in the p/w to the bat file. I know it's not secure but they gave the OK to do so.

    Wednesday, July 10, 2019 4:19 PM
  • .\ always refers to the local machine

    But what is the context of what you are trying to run? Is this a script or a task in your task sequence?

    Daniel Vega

    Wednesday, July 10, 2019 4:24 PM
  • Actually Dan, I'm just trying to get this to run outside of MDT, once the pc final boots to the OS.

    The program we have was written to ONLY run as admin, so I found that if you Shift+Rt-click and run as different user (inputting the local admin info) it will run as another user.

    I'm trying to launch the shortcut through a batch file that will run as the LOCAL admin, not Run As Administrator, as they are two different things.

    I'm looking for the syntax to make a batch file that runs a shortcut (from the Public Desktop so it affects all users) but I can't get it to run. All I can think of is:

    runas/user:administrator "C:\users\public\desktop\shortcut.lnk"

    this prompts for a p/w but nothing launches, so I'm lost on the syntax to get my shortcut to run. Once I do, I'd like to try to add a p/w to the batch file.

    Wednesday, July 10, 2019 4:35 PM
  • I don't think you can do what you want. If it's just something you need to run once after imaging, you could add a registry entry to "runonce" 


    It would run is as system.

    If you want non-admin users to be able to run the batch file at will, you can't. Windows is designed to not allow you just sidestep security like that in a batch file and you wouldn't want to provide plain text access to your admin password in a batch file anyway.

    Daniel Vega

    Wednesday, July 10, 2019 5:01 PM
  • If I run the shortcut as a local user, the registration is lost.

    If I right-click on the shortcut icon and choose Run as Admin, it's lost its registration.

    If I SHIFT + right-click and run as another user, and type in the local admin name & p/w, it opens with all of the registration as it should.

    I'm hoping to make a batch file that runs the shortcut as the local administrator regardless of who is signed on. Each time a user runs it.

    Wednesday, July 10, 2019 6:18 PM
  • Is this an issue where the "registration" can't be saved because it is in Program Files? If so you could change the folder permissions to all users to write to that folder. You could use icacls. Usage:

    There is a way to make a shortcut and save admin credentials, but it requires specifying the machine name and other steps that wouldn't make it ideal for mass usage.

    Daniel Vega

    Wednesday, July 10, 2019 6:43 PM
  • As I've said, just running the shortcut causes the program to lose its registration (which City and location the laptop is registered under, for Driver's testing). Right-clicking and running as admin also shows it lost its registration.
    Shift+right-click to run as another user, typing in the local admin and p/w, opens the program with its registration intact.
    My hope was to find a way to make a batch file that runs the shortcut as 'another user', being the local pc admin.
    I can do this, but then the user must type in the creds and we don't want to give that out. I thought about /savecred and setting it up once myself so it would remember the p/w but I haven't gotten that to work.
    Thursday, July 11, 2019 3:09 AM