Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3284020
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:06:27+00:00 2026-05-17T20:06:27+00:00

I am using the following code to change the ‘Run As:’ username and password

  • 0

I am using the following code to change the ‘Run As:’ username and password for a scheduled task on a remote host.

Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "SCHTASKS.exe";
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

//p.StartInfo.Arguments = String.Format("/Change /TN {0} /RU {1} /RP {2}",ScheduledTaskName,userName,password);
p.StartInfo.Arguments = String.Format(
    "/Change /S {0} /TN {1} /TR {2} /RU {3}\\{4} /RP {5}", 
    MachineName, ScheduledTaskName, taskPath, activeDirectoryDomainName, userName, password);

p.Start();
// Read the error stream first and then wait.
string error = p.StandardError.ReadToEnd();
p.WaitForExit();

I have a couple of questions:

  1. How can I check if the specified service exists at all, so that if it does not exist, I can just quit the program.
  2. How can i check to see if the scheduled task is running or disabled?
  3. If the scheduled task is disabled, can I still change the credentials, or is it like a Windows service where credentials cannot be changed if it is disabled?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:06:28+00:00Added an answer on May 17, 2026 at 8:06 pm

    Look at the link I gave you in my last answer. The link for SCHTASKS.exe.

    Look at the section called Querying for Task Information.

    Here is my code to check the current running status. You can play with the output to modify this for your needs.

    Process p = new Process();
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.FileName = "SCHTASKS.exe";
    p.StartInfo.RedirectStandardError = true;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.CreateNoWindow = true;
    p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    
    p.StartInfo.Arguments = String.Format("/Query /S {0} /TN {1} /FO TABLE /NH", MachineName, ScheduledTaskName);
    
    p.Start();
    // Read the error stream
    string error = p.StandardError.ReadToEnd();
    
    //Read the output string
    p.StandardOutput.ReadLine();
    string tbl = p.StandardOutput.ReadToEnd();
    
    //Then wait for it to finish
    p.WaitForExit();
    
    //Check for an error
    if (!String.IsNullOrWhiteSpace(error))
    {
        throw new Exception(error);
    }
    
    //Parse output
    return tbl.Split(new String[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries)[1].Trim().EndsWith("Running");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following code fragment to change the account and password credentials
I am using the following code, UIManager.put(JFrame.activeTitleBackground, Color.red); for change the toolbar color in
I'm using the following code. The code works, but I want to change it
I'm using following code to display some text and it won't change the font
I'm using the following code to draw an SVG text box, and then change
I am using following code to populate DropDown: $(document).ready(function(){ $('#inDistrict').sSelect(); $(#inDistrict).change(function(){ $.getJSON(filldistricts.php,{id: $(this).val(), ajax:
I am using the following code to change the id of a div to
i am fetching data using following code _.each(cardIds, function(id){ var mdc = new MdlCard({cardId:
I am using the following VBA code to change the color of the rows
I want to change the width of elements rendered using following code. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.