Run my exe as admin without prompt?

Windows specific forum
User avatar
skywalk
Addict
Addict
Posts: 4003
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Run my exe as admin without prompt?

Post by skywalk »

"process" should appear once in the command.
Can you try the same command with notepad.exe?
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Run my exe as admin without prompt?

Post by Dude »

skywalk wrote:"process" should appear once in the command.
Can you try the same command with notepad.exe?
Yes, that double "process" was a typo that you made. ;) I removed it when trying the real thing. My post of your quote has been edited.

This does not launch Notepad either:

Code: Select all

wmic /node:localhost /user:Admin /password:*** process call create "C:\Windows\Notepad.exe"
And yes, wmic is present on my machine; I use it successfully for other tasks.
forumuser
User
User
Posts: 98
Joined: Wed Apr 18, 2018 8:24 am

Re: Run my exe as admin without prompt?

Post by forumuser »

The scheduled task gets created, and my exe is (apparently) run with admin rights at logon, but it seems to run "silently" in that no window is displayed, it doesn't respond to its hotkeys, its system tray icon doesn't appear
Because you're running it under a different user account (your "admin-user") with highest privileges and the logged in user has no access to it's gui...

Reduce the procedure to something like this:

Code: Select all

RunAtLogin(taskname$,exe$,elevated=0)
and remove the now unnecessary stuff for p$

This will create a task for the current logged in user

But I would be very careful about doing it this way. Why?
schtasks uses localized names. E.g. "ONLOGON" is NOT the same
on german, french or other localized installations.

A good way around that is to create a .xml file on the fly, save it and import that
through schtasks. The options in the .xml file can then use the normal english names
and don't need to be localized. In other words: This works fine on all languages...
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Run my exe as admin without prompt?

Post by Dude »

forumuser wrote:

Code: Select all

RunAtLogin(taskname$,exe$,elevated=0)
So I did that, and now the exe doesn't run with admin rights under a limited account, which is the whole idea.
forumuser
User
User
Posts: 98
Joined: Wed Apr 18, 2018 8:24 am

Re: Run my exe as admin without prompt?

Post by forumuser »

Export the task and show the full .xml content!
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Run my exe as admin without prompt?

Post by Dude »

forumuser wrote:Export the task and show the full .xml content!
Here. I changed the computer name, userid and exe details for my privacy.

Maybe if you could post some working code, instead of me just guessing all the time? ;) Because it's obvious that I have no idea what I'm doing here. :lol:

Code: Select all

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2018-12-31T19:16:44</Date>
    <Author>Computer Name\Admin</Author>
    <URI>\Product Name</URI>
  </RegistrationInfo>
  <Triggers>
    <LogonTrigger>
      <StartBoundary>2018-12-31T19:16:00</StartBoundary>
      <Enabled>true</Enabled>
    </LogonTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>S-1-5-21-2569149087-587176876-3879654987-1203</UserId>
      <LogonType>InteractiveToken</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
    <AllowHardTerminate>false</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>false</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>C:\Path\To\MyApp.exe</Command>
    </Exec>
  </Actions>
</Task>
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Run my exe as admin without prompt?

Post by Josh »

Dude wrote:Thanks for any advice.
My tip. As a reasonable provider of an app, you would advise your customers to do without these magic games to save themselves a few clicks. Microsoft didn't introduce the security guidelines for fun.

If I were a company and a software developer comes up with such suggestions, I would stick his app somewhere else and kick the vendor's ass out of the company premises.

Another tip for you. Please refrain from changing your entry threads all the time. Apart from a few exceptions (e.g. a further developed code in Tips & Tricks) this is not the purpose of a forum.
sorry for my bad english
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Run my exe as admin without prompt?

Post by Dude »

Josh wrote:As a reasonable provider of an app, you would advise your customers to do without these magic games to save themselves a few clicks.
So you're saying it's better that the customer works out how to do that themself, instead of my app providing a way to do it for them? Sounds logical, actually. Would solve a lot of hassle that I'm going through.
Josh wrote:Please refrain from changing your entry threads all the time.
You mean stop editing my posts? I was just doing that to clarify things, but I will stop in future. I didn't realise it was a problem. Sorry! :oops:
Post Reply