How to Run Schedulled Task as current Logged In user without asking the password

Unanswered How to Run Schedulled Task as current Logged In user without asking the password

  • Monday, April 09, 2012 9:09 AM
     
      Has Code
    I have an application which needs to set a scheduled tasks in windows.
    for this i have used the ShellExecute functoin to call the schtasks.exe

    I have used the following code :

       
    ShellExecute(NULL, _T("open"), _T("schtasks.exe"), _T("/create /TN SampleSchedule /TR calc.exe /SC DAILY /ST 12:15:00 /SD 09/04/2012"),_T(""),0);



    but it has not created the scheduled task.

    But when I changed the last parameter of shellexecute function (display command prompt) to 1

       
    ShellExecute(NULL, _T("open"), _T("schtasks.exe"), _T("/create /TN SampleSchedule /TR calc.exe /SC DAILY /ST 12:15:00 /SD 09/04/2012"),_T(""),1);



    a command prompt displayed and it asked for the password of the current logged in user.

    The /RU SYSTEM is working..

    but I would like to run as the current logged in user itself without asking the password....

    Is it possible? if yes hat should I do for that.....
    any one please help....
    • Moved by Helen Zhao Wednesday, April 11, 2012 2:42 AM (From:Visual C++ General)
    •  

All Replies

  • Monday, April 09, 2012 4:03 PM
     
     


    Is it possible? if yes hat should I do for that.....
    any one please help....

    No, you can't do it directly. Think about it. Which currently logged in user are you talking about? (there could be more than one, or possibly none at all).

    What you need to do is to provide the username and password at the time you call schtasks as part of the /u parameter.

    Personally, I'd find it easier to simply scheduling part of the application you are trying to pass to schtasks.exe. It's pretty trivial to set up a timer and wait for it to expire before executing.

  • Tuesday, April 10, 2012 4:52 PM
     
     
  • Wednesday, April 11, 2012 2:41 AM
     
     

    Hi Jijesh,

    According to your description, I'd like to move this thread to "User Interface development for Windows Desktop Forum" for better support.

    Thanks for your understanding and active participation in the MSDN Forum.
    Have a nice day!


    Helen Zhao [MSFT]
    MSDN Community Support | Feedback to us