You know, what you normally get when typing ctrl-alt-del or ctrl-alt-end. Except in this scenario I can't press those keys, but I want to launch that box. Specifically I want to be able to pull up the change password dialog from the command line.
Thanks
Here is an extension of the answer given by Raymond Chen. I shows how to call the WindowsSecurity from a batch file. Note that it will only work properly when connected by a terminal session to Microsoft Terminal Server.
#if (#CodeSection == #Batch) #then
#echo off
:: See https://gist.github.com/DavidRuhmann/5199433 and
:: http://msdn.microsoft.com/en-us/library/windows/desktop/gg537748%28v=vs.85%29.aspx
:: for details.
CScript //E:JScript //Nologo "%~0" %*
exit /b
#end
try
{
var objShell = new ActiveXObject("shell.application");
objShell.WindowsSecurity();
WScript.Quit(0);
}
catch(e)
{
WScript.Quit(1);
}
You call the Shell.WindowsSecurity method. The documentation includes sample code.
OSK.exe will bring up an on screen keyboard. It should allow you to hit ctrl-alt-del
control.exe password.cpl - will launch the password Control Panel applet.
Related
I am troubleshooting a problem with a device keeping a Windows 10 PC awake using the powercfg -requests command. I have a BAT file containing the following so it can be run quickly via shortcut with run as admin properties:
cmd /k powercfg -requests
This works, but in addition to keeping the window open, I'd like to be able to keep sending powercfg -requests by hitting arrow up/enter when needed, as would normally happen if I opened a command prompt and typed it manually.
I've searched quite a bit here, and aside from making it repeat automatically,
I haven't found anything other than sending arrow keystrokes in a BAT file.
I did see something which implied it might be possible to print the command so it's entered at the prompt
after the command has executed, which would be fine too, but haven't had much luck.
Is this possible?
Sorry, there is not a simple way...
This works:
#if (#CodeSection == #Batch) #then
#echo off
start "" /B cmd /K
timeout /T 1
CScript //nologo //E:JScript "%~F0" "powercfg -requests{ENTER}"
goto :EOF
#end
WScript.CreateObject("WScript.Shell").SendKeys(WScript.Arguments(0));
For a further description on the method used, see this answer
Use PowerShell instead. You can right click on Desktop > New Shortcut and paste this then save
powershell -NoExit -Command "Add-Content -Path (Get-PSReadlineOption).HistorySavePath 'powercfg -requests'; Invoke-Expression 'powercfg -requests'"
It's better to create a new shortcut because you can set it to always run as admin although it's still possible to put it in a *.bat/*.ps1 file
You can also shorten it like this
powershell -NoE -C "$c = 'powercfg -requests'; ac (Get-PSReadlineOption).HistorySavePath $c; iex $c"
PowerShell is far more flexible and powerful than batch. It also has a persistent history so it's far more convenient to use PowerShell. You may not even need this and just press Ctrl+R to search through history for the powercfg command just like in bash/zsh
I have made a basic BAT script to download updates from Avast virus database and then apply them by running the downloaded file.
#ECHO OFF
set downloadFolder=C:\Users\myuser\Downloads\Avast_updates
set downloadUrl=https://install.avcdn.net/vps18/vpsupd.exe
bitsadmin /transfer myAvastUpdates /download /priority normal ^
"%downloadUrl%" "%downloadFolder%\vpsupd.exe"
start /min "Update..." "%downloadFolder%\vpsupd.exe"
exit
Also, I have created a Windows task to run BAT every x hours.
Everything works correctly, but I want to know if there is any way to automatically close the executable window after the update process is finished.
It occurred to me to use TASKILL after x seconds, but that doesn't assure me that the update process finished in x seconds, sometimes it can take longer and sometimes less, plus I don't want to use that command in an program security installer.
Then it occurred to me to send an "Enter" through WshShell.SendKeys:
set SendKeys=CScript //nologo //E:JScript "%~F0"
cls
timeout /t 5 >nul
%SendKeys% "{ENTER}"
#end
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
But it did not work because that window does not close with "Enter" nor "ALT F4", it closes only if we click on "Done" or on the cross "x" to close the window (if it worked it would have the problem of setting the time again).
Is there a way to automatically close that window once the update process finishes?
vpsupd.exe supports a /silent switch to suppress user interactions.
start /min isn't needed, as it just opens another cmd window, which in turn runs the executable. So just do:
vpsupd.exe /silent
With the help of #Stephan and #Gerhard, the code to download and update Avast was like this:
#ECHO OFF
set "downloadFolder=%userprofile%\Downloads\avast_updates"
set "downloadUrl=https://install.avcdn.net/vps18/vpsupd.exe"
bitsadmin /transfer myAvastUpdates /download /priority normal ^
"%downloadUrl%" "%downloadFolder%\vpsupd.exe"
"%downloadFolder%\vpsupd.exe" /silent
exit
I can print a txt file from command line using the following code:
rundll32.exe C:\WINDOWS\SYSTEM32\MSHTML.dll, PrintHTML "C:\Test.txt"
but every time a window pop up and ask me which printer to use...
I've read some threads about the possibility to do something like this:
rundll32.exe C:\WINDOWS\SYSTEM32\MSHTML.dll, PrintHTML "%1" "%2" "%3" "%4"
where %2 is the printer name.
I tried this
rundll32.exe C:\WINDOWS\SYSTEM32\MSHTML.dll, PrintHTML "c:\test.txt" "<printername>"
but had no luck.
Any suggestions?
thank you
As per below link it seems that for security reasons automatically running above command has been blocked.
http://blogs.msdn.com/b/fyuan/archive/2007/02/24/printing-documents-to-microsoft-xps-document-writer-without-user-interaction.aspx
Line from above blog:
"So you should be able to print any webpage to any printing device, to any printer/file, fully automatically. But this creates a security risk, so it has since been blocked. User confirmation is needed to print an HTML page through MSHTML.DLL."
Alternatively, as you are printing a text file you can use below command to print a text file from command prompt:
start /min notepad /P <filename>
I am running a sequence of applications from a batch script and I want to make sure, that the opened program will always be in focus.
We need to ensure this because it's an experimental setup and we want to minimise such hassles as having to change focus to a fullscreen window.
This problem already occurred infrequently when the earlier program exits and for a moment the desktop is visible and the user clicks on some icon on the desktop, and right after that, the next program in the sequence is being processed, the new window is not in focus.
The problem has become much more frequent now that I hid the command window from view.
Any way to force focus for the next program in the sequence, be it a batch command, some settings for the OS (we're on Win XP) or a helper app could be helpful.
If you want to focus another program you can do this.
call focus WindowTitle
exit /b
:focus
setlocal EnableDelayedExpansion
if ["%~1"] equ [""] (
echo Please give the window's title.
exit /b
)
set pr=%~1
set pr=!pr:"=!
echo CreateObject("wscript.shell").appactivate "!pr!" > "%tmp%\focus.vbs"
call "%tmp%\focus.vbs"
del "%tmp%\focus.vbs"
goto :eof
endlocal
I am using vbscript to focus the application.
You need to pass the window's title, not the window's name (whatever.bat).
To make sure you get the right window focused you can set its title.
example:
title WindowTitle
if i got it right, start /f yourapp.exe would start the application in foreground.
Yaron answer will work but would prefer not to create a temp file to execute the script but to embed the code in the batch directly. Or to use jscript which is also part of windows script host and is easier for embedding into batch
Here's a focusOn.batenter link description here that will set the focus on an application based on starting string of the title (will not create temp files which will make it a little bit faster):
#if (#X)==(#Y) #end /* JScript comment
#echo off
cscript //E:JScript //nologo "%~f0" %*
exit /b %errorlevel%
#if (#X)==(#Y) #end JScript comment */
var ARGS=WScript.Arguments;
if (ARGS.Length < 1 ) {
WScript.Echo("No window title passed");
WScript.Quit(1);
}
var sh=new ActiveXObject("WScript.Shell");
if(!sh.AppActivate(ARGS.Item(0))){
WScript.Echo("Cannot find an app with window name starting with: " + ARGS.Item(0));
}
Example usage:
call focusOn.bat Untitled
which should put on focus the notepad (it its title is still "Untitled - Notepad")
I'm trying to learn how to run Javascript (instead of VBScript) using CScript.exe, but when I try, I get an error:
cscript temp.js
Input Error: There is no script engine for file extension ".js".
I thought this is possible -- any idea what's wrong?
Setting the registry with regsvr32 did not work for me. Also, I don't want it, since I want my .js to be linked with a plain text editor.
But there is a command line option //E for cscript which makes the job:
cscript //E:jscript hello.js
A very simple fix: use assoc.
c:\>assoc .js=JSFile
(Mine had become associated with a text editor at some point.)
It's worth to mention that rplantiko's solution works even if the
extension of the filename is not .js. This allows for putting .js code
into a .cmd file and running as a batch, forming a single-file
solution that is fully portable without preliminary steps (like
assoc).
For example, if you create a test.cmd file with the following content,
you'll be able to run it by simply clicking on it in Explorer,
or by drag&drop another file over its icon:
#if (#CodeSection == #Batch) #then
#cscript //Nologo //E:jscript "%~f0" "test arg" %* & pause & goto :eof
#end
WScript.Echo("hello world");
for (var i = 0, n = WScript.Arguments.Length, args = []; i < n; ++i)
args.push(WScript.Arguments(i));
WScript.Echo("arguments: " + args.join(","));
The lines between #then ... #end are batch commands interpreted by cmd.exe. The last command is goto :eof to skip the rest of the file. The lines after #end are interpreted by cscript.exe.
It turns out that the .js extension wasn't associated with JSFile in the registry. Doing so fixed the problem.
assoc .js=JSfile
ftype jsfile=C:\Windows\System32\Cscript.exe "%1" %*
Had this problem, too, and I solved ...
1.- locate wsh.inf, the installation file for windows scripting host in %windir%\inf
2.- right-click on wsh.inf and choose install.
You should be able to run this command to fix the error:
regsvr32 %systemroot%\system32\vbscript.dll