Issue using The Task Scheduler with cmd - windows-10

Can Windows 10 The Task Scheduler run Reg.exe commands from command prompt?
When I past this command to make changes in reg.exe in CMD -- its works! But not works at Task Scheduler!
Reg.exe add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize" /v "SystemUsesLightTheme" /t REG_DWORD /d "0" /f"
able to scheduler but not work command line (trying scheduler work at 18 PM)
schtasks /create /sc daily /tn "Tema" /tr "Reg.exe add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize" /v "SystemUsesLightTheme" /t REG_DWORD /d "0" /st {hora} /f
deleting command thas works too
schtasks /delete /tn "Tema" /f
I able to Create and Delete it as well, but I can't make it runs appropriately from Task Scheduler -- nothing happens!

Related

WVD outlook prompts for unlicensed/ non-commercial product

We are delivering outlook, word and excel as remote apps to our users, however whenever the users launch the remote application they are being prompted to recreate profile, suggesting it can't find the previous days OST file.
the prompt states "sign in to set up office", however if you go through the sign-in process, you are confronted with the same the next morning.
We are running Windows 10 multi-session with Office Pro-Plus.
I've confirmed the image is correct and the reg keys are for the shared computer setting. As outlined in the doc below:
https://learn.microsoft.com/en-us/deployoffice/troubleshoot-shared-computer-activation
Is there something I've missed?
Thanks in advance :)
Looks like you just need to Reset Microsoft 365 Apps for an enterprise activation state please refer to this link: https://learn.microsoft.com/en-us/office/troubleshoot/activation/reset-office-365-proplus-activation-state#step-2-remove-cached-identities-in-hkcu-registry to Clear Office credentials and activation state for managed devices
I have summarized the required code for you below, but you have to download the vbs files for link above 1st:
taskkill /IM WinWord.exe /F
taskkill /IM Excel.exe /F
taskkill /IM Outlook.exe /F
taskkill /IM PowerPoint.exe /F
taskkill /IM Lync.exe /F
taskkill /IM MSACCESS.EXE /F
taskkill /IM Teams.exe /F
taskkill /IM MSPub.exe /F
taskkill /IM OneNote.exe /F
taskkill /IM OneNoteM.exe /F
taskkill /IM iexplore.exe /F
taskkill /IM OfficeClickToRun.exe /F
taskkill /IM OneDrive.exe /F
cscript 1-HKLM-O365-no-prompt.vbs
cscript OLicenseCleanup.vbs
del /F /Q %localappdata%\Microsoft\Office\16.0\Licensing\
REG DELETE HKCU\Software\Microsoft\Office\16.0\Common\Identity /f
REG DELETE HKCU\Software\Microsoft\Office\16.0\Registration /f
REG ADD HKCU\Software\Microsoft\Office\16.0\Common\Identity /v EnableADAL /t REG_DWORD /d 00000000 /f
REG ADD HKCU\Software\Microsoft\Office\16.0\Common\Identity /v DisableADALatopWAMOverride /t REG_DWORD /d 00000001 /f
I come across this issue all the time at work, especially when users switch devices. It seems that sometimes Windows retains Office license info and when a new user tries to activate it doesnt update. Its relatively easy to fix and this site has a quick guide on how to remove the old license info
http://itwalkthroughs.com/knowledge-base/office-apps-show-unlicensed-product/

Stopping a program/application using a python script

Is there any way to terminate an application, for instance Google Chrome, using a python script or command?
Additionally, is there any python script/command to stop an application from starting.
You can use Windows taskkill from os.system() inside a Python script like that:
import os
os.system("taskkill /f /im process_im_goes_here.exe"")
Where /f means forcefully kill the process & /im is the process itself (ImageProcess) which means after that you get to specify the full path to the ImageProcess.
You can also use tasklist to find what processes are currently running.
Here are some taskkill usage examples:
taskkill /pid 1230 /pid 1241 /pid 1253
taskkill /f /fi "USERNAME eq NT AUTHORITY\SYSTEM" /im notepad.exe
taskkill /s srvmain /f /im notepad.exe
taskkill /s srvmain /u maindom\hiropln /p p#ssW23 /fi "IMAGENAME eq note*" /im \*
taskkill /s srvmain /u maindom\hiropln /fi "USERNAME ne NT*" /im \*
taskkill /f /fi "PID ge 1000" /im \*
Alternatively, you can use psutil.
You can learn more about taskkill here and/or python os.system.
Also, this has been answered before
Hope this helped!

How to quote this raw command in Ansible YAML?

I am using Ansible to manage the configurations of a bunch of Windows clients. For the record, Ansible playbooks (i.e. recipes) are written in YAML.
I need to run this command on every client, and I could test it successfully in a Powershell prompt on a client machine:
> CMD /C 'control intl.cpl,, /f:"C:\Temp\intlsettings.xml"'
(note the single quotes, required because of the double quotes around the filename)
Now I "just" need to write a YAML playbook and use the raw module from Ansible to send this command to a remote Powershell session. And this is where I am stuck. My command contains :, ' and " symbols so I have no idea how to quote it properly.
I have tried a million variations, with no success so far:
CMD /C 'control intl.cpl,, /f:"C:\Temp\intlsettings.xml"'
"CMD /C 'control intl.cpl,, /f:"C:\\Temp\\intlsettings.xml"'"
"CMD /C 'control intl.cpl,, /f:\"C:\\Temp\\intlsettings.xml\"'"
"CMD /C 'control intl.cpl,, /f\:\"C\:\\Temp\\intlsettings.xml\"'"
For information, the final playbook will look something like:
---
- name: Configure keyboard mappings
hosts: windows
tasks:
- name: apply keyboard mappings config
raw: CMD /C 'control intl.cpl,, /f:"C:\Temp\intlsettings.xml"'
If you execute this powershell command
CMD /C 'control intl.cpl,, /f:"C:\Temp\intlsettings.xml"'
powershell creates this CommandLine:
"C:\Windows\system32\cmd.exe" /C "control intl.cpl,, /f:"C:\Temp\intlsettings.xml""
Note, that no ' are used in the CommandLine.
However, you don't need to go through cmd as no cmd functionality is used in your command.
control.exe intl.cpl,, /f:"C:\Temp\intlsettings.xml"
should be enough.
I don't know ansible, but if I understand the documentation correctly, all text after raw is sent as a command via ssh. This means, it is interpreded by some shell. If this shell is cmd.exe, this should work:
tasks:
- name: apply keyboard mappings config
raw: control.exe intl.cpl,, /f:"C:\Temp\intlsettings.xml"
If the shell is powershell (v3 and above (default for win8 and above, installable for win7)), this should work:
tasks:
- name: apply keyboard mappings config
raw: control.exe --% intl.cpl,, /f:"C:\Temp\intlsettings.xml"

How to use the 'at' command on cygwin?

How can we schedule processes using the 'at command on cygwin'? 'The at command has been deprecated on cygwin'is the error I got on trying out the 'at command.' Are there any equivalent commands in Cygwin for at and batch?
Here is an example of how I used schtasks.exe in the same way I'd use at
schtasks /create /tn "Run Meter" /ru System /tr "nssm.exe restart Meter" /sc once /st 12:00
is functionally identical to
at 12:00 <<<"nssm.exe restart Meter"
AT isn't a Cygwin-specific program, it's part of Windows. The complete message says:
The AT command has been deprecated. Please use schtasks.exe instead.
You can run schtasks from cygwin, too. For immediate help with schtasks, from cygwin you can type:
schtasks /?
Otherwise, Google is your friend. :)

CMD Batch file: How to use a text file to input commands

I am creating a batch file to siliently install nodejs on a Windows XP machine.
I am trying to automate the installation of node module dependencies (npm install).
I would normally issue npm install from the cmd prompt in the target installation directory.
I am struggling to automate the interaction with the command prompt from a batch file.
The following line in my batch script seems to make it possible for me to pipe a text file of commands to cmd:
for /F "usebackq delims=," %%i in ("c:\foo\source\npm_install.txt") do echo %%i | "c:\windows\system32\cmd.exe"
The batch file is located in c:\foo\source. I need to issue 'npm install' from c:\foo\bin.
If my npm_install.txt file is such:
cd /d c:\foo\bin,
npm install
The cmd prompt will perform the first command changing the directory from c:\ to c:\foo\bin.
It will then perform the second command but starting from c:\ again. The previous command to change directories doesn't persist. It seems every command in the text file will be issued from c:\ .
I next tried to issue both commands from a combined statment:
cd /d c:\foo\bin && npm install
It seems this approach will allow me to overcome the prior path problem but I then have an issue with the space between npm and install.
The cmd prompt performs c:\foo\bin>npm and causes npm to trip on the space.
I have tried enclosing the command without success: 'npm install', "npm install", (npm install).
Can anyone tell me what I am doing wrong?
Thanks.
The problem is that your batch-processing script is creating a new subshell to handle each line in your install file. Thus your cd command is executed in a subshell, changing its working directory, but then the subshell exits and you're back in the parent shell's working directory.
Can your main script simply call your install script (whose extension would have to be changed to ".bat")? call lets you run another batch file in the same shell and then continue running your original script.
You do not need this:
do echo %%i | "c:\windows\system32\cmd.exe". Simply put your commands in a block.
do (
command
command
...
)
With your previous statement, you start new cmd interpreter, ask it to execute a command for you and exit - that's why you loose effect of that cd.
If you do not specify tokens in for loop, only 1st is read. Plus, all tokens must be on same line (I'm not sure if what you show is not a byproduct of formatting)
Use "delims=" to read full line.
Do not mix commands with arguments if you do not have to: put only directories in your file:
c:\foo\bin
c:\bar\bin
so finally it becomes (I replaced cd with pushd/popd so you'll end up in the same dir you started from):
for /F "usebackq delims=" %%i in ("c:\foo\source\npm_install.txt") do (
pushd %%i
npm install
popd
)
Edit: if npm install is batch itself, you will need to use call, as ebohlman noted
NOTE: These three examples do not require you to put CALL in front of any batch files, that functionality is built-into each.
The smallest and simplest, it just executes the commands with their arguments:
#echo off
for /f "tokens=*" %%x in (c:\foo\source\npm_install.txt) do (
call %%x
)
To mimic a person typing the commands at the keyboard:
#echo off
for /f "tokens=*" %%x in (c:\foo\source\npm_install.txt) do (
setlocal enabledelayedexpansion
:: Mimic commandline
call set "cmd=%%cd%%"
echo !cmd!^>%%x
endlocal
:: Preform command
call %%x
echo.
)
To end up in the same directory you started in, no matter where the script ends:
#echo off
setlocal enabledelayedexpansion
for /f "tokens=*" %%x in (c:\foo\source\npm_install.txt) do (
:: Mimic commandline
call set "cmd=%%cd%%"
echo !cmd!^>%%x
:: Preform command
call %%x
echo.
)
endlocal

Resources