I'm designing a batch file to first check if a copy of windows is activated (using the slmgr /xpr command) and if it isn't input a key to activate it. I have everything done except for the checking for activation as when you run the slmgr /xpr command, it outputs to a windows host script dialogue box and I can't figure out how to have that box output its text into a text file to use as a variable. Does anyone know how to do this/ has a better way?
Thanks in advance!
Use cscript to output text from slmgr to the console.
cscript slmgr.vbs /xpr
Try this, you may just change slmgr.vbs /dli to slmgr.vbs /xpr.
It will automatically generate a text file saved to your C:\ drive:
cscript c:\Windows\System32\slmgr.vbs /dli > c:\slmgr_result.txt
Related
When I use slmgr /skms <URL> | cmd command in PowerShell it shows me a pop up that I must press the ok button after that I run slmgr /ato | cmd and again shows me another pop up that I press the ok button.
I don't want to press the ok button manually, can anybody help me if there is a solution for it, please?
I just disabled the uac in windows, but it does not help me.
What you are looking for is cscript. By just executing a vbs script file, output gets sent to dialog boxes, which need your interaction.
Using cscript, the desired output gets printed to your current stdout:
cscript C:\Windows\System32\slmgr.vbs /ato
That doesn't have anything to do with UAC and you might consider re-activating it.
But why is that?
slmgr is not a command nor is it an executable in windows. It's a script file written in VBScript. VBScript is a kind-of scripting version of VB, So it's good for your peace of mind not to deal with it too much.
If you type in slmgr /skms, what windows does is looking for a file named slmgr in its search paths (%PATH%), finding C:\Windows\System32\slmgr.vbs and deciding that, as its a .vbs file, executing wscript.exe with the file path and your arguments as parameter is the right thing to do.
WScript is the default interpreter for vbs files and just interprets the file and executes its code. On the other hand, there is cscript for console scripts.
If the author of the .vbs file decides to write a message to the user of their script, they usually use a statement like
Wscript.Echo "Hello, World!"
And thats where your confusion starts:
Executing this script in cscript means that Hello, World! is written to the console. (That's what you want to do)
Executing the same script using wscript renders a message box with a OK button. You can easily reproduce it yourself by creating a vbs file with the above statement.
The difference between cscript and wscript is also discussed in this question:
Difference between wscript and cscript
I am trying to open a .chm file from a batch file.
The batch file has only this text in it :
echo off
start "S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm"
If I run the batch file, the commandline opens but nothing further happens.
If I copy paste S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm in start menu/run then it does works.
If I make a shortcut with target "S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm" then it also works.
So the command works everywhere, except from a batch file.
What am I doing wrong here ?
It might also be important to know that when I start it from the shortcut, or start menu/runI always get a dialog
We can't verify who created this file. Are you sure you want to open this file ?
I am using Windows 7
EDIT
My problem is not the dialog, my problem is that nothing happens when I open the chm file from a batch file
The Start command is probably seeing your doublequoted string as a title, enter Start /? at the command prompt for its usage information.
Try adding an empty title first:
#Echo Off
Start "" "S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm"
I have an .exe that runs in command prompt, it then asks me to press a letter to perform a task. I want a batch file that runs the .exe file and presses y to perform the action. This is what I have so far:
start cmd.exe /k ""C:\Users\mayes\Documents\Utilities\Macros\Second Keyboard Macros\Intercept\intercept\intercept.exe""
All what it does is open the .exe file. I need it to press y also.
Demonstration of what I want the batch file to do:
https://media.giphy.com/media/Ujsia9OeUqJuo/giphy.gif
So there is another much easier way, the program has built in arguments,
C:\Stack\intercept>intercept.exe /help
*** Keyboard Remapper v. 1
*** Based on Oblitum Interception http://oblita.com/Interception.html
Use /help for help on command-line options
Command line parameters:
/ini path oile.ini specify alternate config file (optional)
/apply non-interactive, apply filters on startup (optional)
C:\Stack\intercept>
if you type /help so just make a shortcut with a /apply and you're GOLDEN! it's a useful tip to check console applications for built in arguments and options by typing /help.
you can send keys with vb script witch can be run from batch.
Try this:
set shell = CreateObject("WScript.Shell")
shell.run"C:\Users\mayes\Documents\Utilities\Macros\Second Keyboard Macros\Intercept\intercept\intercept.exe"
WScript.Sleep 1500
shell.SendKeys"{Y}"
shell.SendKeys"{ENTER}"
save it as .vbs, and it you want to run it from batch you can use:
cscipt "nameoffile".vbs
hope it works for you!
Ran into a problem today. I have a Windows Server 2003 with a bunch of .bat files that essentially start .vbs scripts. Every time an ECH is used in the script I get that annoying dialog box that contains content of an echo and requires to click ENTER all the time. How can I just disable the dialogs and keep ECHOs in the command prompt window only?
Force it to run under cscript instead of wscript
If you are running the script manually, just put cscript in front of it.
Otherwise, this might give you an approach:
http://www.robvanderwoude.com/vbstech_engine_force.php
Redirect the output somewhere else, i.e.
scriptname.vbs > textfile.txt
After installing the new server, I am facing an issue.
I have lot of .vbs files, all need to run in wscript, reason, I use all those command like WScript.Echo "hello"
I want to be able to see the output when I double click the VBScript file.
But when I right click on the vbs file, I see console, I want to change the default to Windows host, globally!
How can I do that?
You can change the default scripting host to wscript.exe like so:
wscript.exe //H:wscript
If you wish to set cscript as the default host, that works in the same way:
wscript.exe //H:cscript
You can execute cscript.exe with the same arguments for the same result.
You can switch the default script engine with:
wscript //H:Wscript
Good luck!
I was able to solve it by using the following steps:
selecting the VBScript file that I want to open,
right click to select default program for this,
browse to C:/windows/windows32/wscript.exe, and select this.
In command prompt (as administrator):
To set windows script host as default script host enter:
wscript.exe //H:WScript
To set command line based script host as default script host enter:
cscript.exe //H:cscript
Check the Windows Explorer settings for the filetype *.vbs (something like tools->options->file types etc.) and change the "open with" setting to cscript.
Edit: I now advise caution with the recommendations I give below. After continuing to toggle and test my settings, I find I am unable to re-establish cscript as my default script host. (Note that I also retried the procedures given by other answers to this question.)
In addition, I tried using Process Monitor (a.k.a., "ProcMon") to find the reason for my difficulties, but unfortunately have not been unsuccessful.
Finally, I also considered going back to an earlier Windows 7 restore point, but this was complicated by the fact that I just yesterday changed my domain password. So, for now, I'm going to have to put my investigation to rest as other tasks are pressing.
On last thought...I have also considered the possibility that there are network policy security settings that are thwarting my efforts.
Original Answer: Enter the following line in a Windows batch file:
ftype VBSFile="%%SystemRoot%%\System32\WScript.exe" "%%1" %%*
Then, run a Command Prompt as an Administrator and run the batch file.
I believe the above will make the change for all users on the system. To make the change for only the logged in user, do the following (on Windows 7):
Control Panel => Programs => Default Programs => Associate a file type or protocol with a program
Then, in the Name column, scroll down to .vbs and click Change program... in the upper right. Then choose one of the Recommended Programs. If you do not see Microsoft ® Windows Based Script Host, browse to the following file:
C:\Windows\System32\wscript.exe
The guy above who right-clicked to choose the default program was right, however the path should be: C:\Windows\System32\wscript.exe