0

I am facing error in win 8.1 64bit when i am running this command:

start "" "X:\Windows\System32\devmgmt.msc"
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "{TAP}"
pause

I am getting this error;

H:\Desktop>WshShell.SendKeys "{TAP}"

'WshShell.SendKeys' is not recognized as an internal or external command, operable program or batch file.

I have already installed Java environment.

user692942
  • 14,779
  • 6
  • 66
  • 157
KHALIL-VIT
  • 1
  • 1
  • 1
  • 1
    You can't run a WScript command directly from the command prompt, you use a VBS or a WSF file using [`wscript.exe`](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/wscript) or [`cscript.exe`](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/cscript). You don't seem to understand what WScript is or how to use it otherwise you wouldn't be mentioning Java Environments, that has absolutely no bearing on this what so ever. Suggest you go find a good tutorial on how to use the Windows Scripting Host. – user692942 Dec 01 '18 at 08:08

1 Answers1

1

VBScript code cannot be run directly from CMD. You need to run it with the proper interpreter, which normally is either wscript.exe (GUI-based, default) or cscript.exe (console-based) on Windows systems. Put your code in a .vbs file and then run that file with the respective interpreter:

wscript.exe //NoLogo "C:\path\to\script.vbs"

or

cscript.exe //NoLogo "C:\path\to\script.vbs"

If your question is how to run VBScript commands interactively at a prompt (like Python's or Ruby's interactive mode for example): the builtin interpreters don't provide that feature. Their "interactive" parameter (//i) has a different meaning. It allows interaction (error messages, input prompts, ...) between script and user as opposed to batch mode (//b) that suppresses all user interaction so that the script runs uninterrupted in the background.

However, it's pretty easy to write small wrapper scripts that allow running code directly from the commandline (like Perl) or provide an interactive prompt (like Python or Ruby).

Ansgar Wiechers
  • 175,025
  • 22
  • 204
  • 278
  • @Lankymart Maybe. But keep in mind that we're answering questions not just for the people who originally asked them, but primarily for everyone else who might be encountering similar problems. – Ansgar Wiechers Dec 01 '18 at 20:47
  • True, but wouldn’t expect this to come up very often. – user692942 Dec 01 '18 at 21:01