Trigger task on server from PC

I want to put an icon on the desktop of a PC which will trigger a task to start on a server 2012.
The server is an AD controller. The PC is a member of the domain.

I have a scheduled task on the server which runs every 24 hours. I want the user to be able to force the task to run sooner by clicking on an icon on their PC. The scheduled task runs a batch file so the icon can trigger the scheduled task or run the batch file.
LVL 13
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kanti PrasadCommented:

If the user of the PC have execute access for that server where your batch file is then you can execute it from the PC.
Just map the server to a drive of the PC and put that bat file shortcut on the pc's desktop and click it .
akbAuthor Commented:
Hi Kanti,
That won't work. The batch file must run on the server with full admin privileges. The user has only basic user privileges.
I just need the user to trigger the batch to start on the server.
Muhammad BurhanManager I.T.Commented:
have you tried schtasks /run /s <machine name> /tn <task name>.
make a bat file wih this cmd and place it on user's desktop then check what happens ?
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

akbAuthor Commented:
Hi Muhammad,
No. I haven't tried anything yet.
I'm looking for a solution to the problem.
I was hoping that someone would come up with a known solution without me having to try things.
Thanks for your input.
Scott CSenior EngineerCommented:
The problem you are facing is that you want a user to act as an admin in this one instance.  What you are trying to do is bypass the built in security.  

Since the batch file must be run with full admin privileges, I don't think there is a way for a user to kick it off.

I don't think I've ever heard of trying to do something like this.  You are most likely going to have to try things.

I would suggest setting up a small VM lab so you can experiment.
Muhammad BurhanManager I.T.Commented:
create a task on a server 'Server16' which just open CMD.
then try to trigger it from the client PC with cmd and bat, working both ways and triggers it but Access Denied on standard users.
also tried, make shortcut mark run as admin but standard users can't do it without admin credentials.

schtasks /run /s Server16 /tn \Microsoft\Windows\Test
Kanti PrasadCommented:

Below are some options. So you can put those commands in a bat file on your pc desktop and click it
akbAuthor Commented:
Thanks for the replies.
ScottCha - I really don't want the user to do anything as an admin or to bypass any security.
Muhammad - Thanks for the effort but this is a standard user so it won't work.
Kanti - Thanks for the link but that doesn't help for non-administrators.

I'm thinking along the lines of:
  User clicks icon.
  Icon runs a script which writes a flag/file to a folder on the server.
  A scheduled task on the server checks for flag/file every 60 seconds.
  If the file exists the flag/file is deleted and the batch file is executed.

This would require no special privileges for the user.
The flag/file will be written to a folder on the server which only the user has access to so no one else can write to the share.

I was hoping to come up with a neater solution to this. I'm not sure what impact running a scheduled task every 60 seconds would have on the server - probably none I'm guessing.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scott CSenior EngineerCommented:
Actually I think you might have figured out a solution.

You probably would see little to no impact on performance.

You might want to have the task check every 60 seconds during business hours.  No point it running after hours when a backup job could be running.
David Johnson, CD, MVPOwnerCommented:
so you need 2 scheduled tasks
task 1
your scheduled task

task 2 watcher.cmd
if exist d:\share\watchfolder\ runschtasks.cmd
timeout /t 60 /nobreak > NUL
goto start 

Open in new window

del d:\share\watchfilder\
schtasks /run /s Server16 /tn \Microsoft\Windows\Test 

Open in new window

Muhammad BurhanManager I.T.Commented:
@David, it works.

1. Create task and name it as 'Test' and in 'action' ask to do anything you want.

2. Create another task and name it Condition, set its repetition in 'triggers >  repeat task in every 1 min' and ask it to run condition.bat.

Two bat files should be in Server, and 3rd is optional.

1. condition.bat   (which check the existence of file)

if exist C:\Shares\new.txt runtask.bat else stoptask.bat
timeout /t 5 /nobreak > NUL
goto start

2. runtask.bat   (which runs the task and delete file for next run)

del c:\shares\new.txt
schtasks /run /tn \Microsoft\Windows\Test

3. stoptask.bat   (which stops the task if file dsn't there)

schtasks /run /tn \Microsoft\Windows\Test

Note: please remove 'else ' statement in condition.bat and don't create stoptask.bat as well if you don't want that operation.
akbAuthor Commented:
Thanks for all your help. I ended up going with my own solution as above. Am happy to divide up the points for all your input.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2012

From novice to tech pro — start learning today.