1

I created the following .bat file in order to shutdown onedrive service:

whoami
"C:\Program Files\Microsoft OneDrive\OneDrive.exe" /shutdown

If I double-click on the .bat icon file, this works. Also, this works when I run a command line shell and type "C:\Users\john\Desktop\onedrive-shutdown.bat".

Now, I am running a Jenkins service on the same windows server which is connected as john (logon properties) and I created a project which consists of the following build step:

enter image description here

Unfortunately, the /shutdown process hangs up/loops since I am getting the following output:

whoami
john
"C:\Program Files\Microsoft OneDrive\OneDrive.exe" /shutdown

(and ... icon. Also, OneDrive won't be shutdown).

What am I missing?

Note that:

  • Jenkins service logon properties is set as: john
  • I tried psexec64 -i 1 -u john -p PASSWORD "C:\Program Files\Microsoft OneDrive\OneDrive.exe" /shutdown, but this won't work (same results).
  • I cannot use runas since user john user has got a password.
  • Any other .bat file, such as echo "Hello World" works fine.

1 Answer 1

0

The issue arises because Jenkins runs as a system process (0), while OneDrive requires an interactive user session (1) to function correctly. To resolve this, I created two scheduled tasks to execute the batch files in the correct user contex.

Here's how I solved it:

  1. Created two batch files so that execute the following commands: "C:\Program Files\Microsoft OneDrive\OneDrive.exe" /shutdown and "C:\Program Files\Microsoft OneDrive\OneDrive.exe" /background.
  2. Created a task for /shutdown command: schtasks /create /tn "OneDriveShutdownTask" /tr "C:\Users\john\Desktop\onedrive-shutdown.bat" /sc onstart /ru john /rl HIGHEST
  3. Created a task for /background command: schtasks /create /tn "OneDriveBackgroundTask" /tr "C:\Users\john\Desktop\onedrive-background.bat" /sc onstart /ru john /rl LIMITED (note LIMITED here, since OneDrive can't be ran in HIGHEST mode).
  4. Launch schtasks /run /tn "OnedriveShutdownTask" or schtasks /run /tn "OnedriveBackgroundTask" either using Windows CMD or using Jenkins.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.