How do I make my batch file take input without using /p? - batch-file

I'm trying to make a batch file that allows me to search for something on wikipedia. But instead of using /p and it asks me for input, I want to to automatically search. For example, I would type search Example, and it would search for example on wikipedia. Thank you in advanced.
P.S. I do not have any code currently, but to clarify I dont want to use /p %input% in the code.

Save this to a file named search.bat and you're done:
#start "" "http://en.wikipedia.org/wiki/Special:Search?search=%*"
The %* means all command-line arguments. So if, on the command line, you enter
search Example
The script launches your default web browser and opens the Wikipedia search page for Example. Wikipedia then redirects you either to the corresponding article or the disambiguation page, whichever is more appropriate according to Wikipedia's algorithms.
If you:
search snow cream
you instantly get taken to the Wikipedia entry for snow cream.

Related

How to properly set up OEMInformation edit commands in a batch file?

I'm working on a program for my computing company that will allow me to run this program off of a USB drive, enter the desired information into command prompts and then have the program create and enter information for the registry keys. I'm just stuck on how the syntax / code for it would work.
I've been looking through different articles trying to find out how to do it but all of them are either too advanced for my understanding or are too vague for what my goal is.
REG ADD HKLM\Software\Windows\CurrentVersion\OEMInformation /v System Builder /t string /d Ryan Taylor /f
The intended result is to create a new registry key under HKLM\Software\Windows\CurrentVersion\OEMInformation and have the key named "System Builder" then have the value pulled from a variable that was provided earlier in the program to be set as the value for the key. The key should be a string data type, not require any authentication before making edits to the registry (as it will be running multiple edits/adds I can't be bothered clicking yes haha)
As this is messing with the registry I havn't ran a test on the code yet and was wanting someone who knows what they are doing to proof check my code before I mess up my computer.
Managed to sort it out after looking at more examples of code, Correct data type I was looking for is REG_SZ and I've worked out how the formatting works.

FINDSTR in batch file to search some directories and using a file to input the search strings

I can only use Windows command line commands for this as program is running forensics in a Windows batch file only to extract information.
I want the user to be able to populate a file with keywords (strings) as keywords.txt that they want to search for.
I only want to search some directories which will popular locations to store user items hence directorylist.txt.
I then want to output any findings into a text file Found_Keywords.txt.
I have been using
FINDSTR /R /I /M /G:C\Users\Admin1\Desktop\Keywords.txt /D:C:\Users\Admin1\Desktop\DirectoryList.txt >C:\Users\Admin1\Desktop\Found_Keywords.txt
Pause
This doesn't appear to work. I have tried sampling the code in other formats and running tests where I search for a string against a given file that contains that string and still no results.
Can anyone suggest where I am going wrong please.
In essence I want someone else to be able to perform keyword searches on a computer against user generated files such as word docs, text, docs and filenames.
Can anyone suggest where I am going wrong please.

Compiling LaTeX from notepad++ and opening with sumatra. ForwardSearch doesn't work if file path contains umlauts

I've had this small problem for quite some time now and I haven't been able to find a solution even after excessive googling.
In this guide it is described how LaTeX can be written and compiled using npp++ and nppExec together with SumatraPDF.
Through some clever scripts and the use of DDE commands (through CMCDDE.exe), it is even possible to use sumatra's ForwardSearch to jump back and forth from the .tex to the .pdf. Everything works great, unless the path to the .tex file contains a character that's not in the English alphabet (for example åäö).
The CMCDDE command then fails because the path sent to sumatra's ForwardSearch reads (for example) C:\†„” instead of C:\åäö. This has to be an encoding issue and I haven't been able to find a working solution.
So, if I have this .tex file C:\åäö\MWE.tex with
\documentclass{article}
\begin{document}
Hello World!
\end{document}
it won't open correctly when using the batch script described in the link above. These are the problematic batch file lines:
::Writes the commands that are to be executed using CMCDDE.exe (through cmcdde.tmp)
echo SUMATRA>"%~dp1build\cmcdde.tmp"
::%~dp1build transforms into C:\åäö\build for the MWE
echo control>>"%~dp1build\cmcdde.tmp"
echo [ForwardSearch("%~dp1build\%~n1.pdf", "%~f1", %2, 0, 0, 0)]>>"%~dp1build\cmcdde.tmp"
:: This gives the following line in cmcdde.tmp: [ForwardSearch("P:\Documents\†„”\build\MWE.pdf", "P:\Documents\†„”\MWE.tex", 3, 0, 0, 0)] (in ANSI encoding)
"P:\Documents\localtexmf\cmcdde.exe" #"%~dp1build\cmcdde.txt"
:: This fails because the path P:\Documents\†„”\build doesn't exist (P:\Documents\åäö\build does)
Ideas I've had and tried:
I tried changing the encoding by using chcp 65001 and chcp 865 but
haven't been able to get it to work.
I have also tried using a
search and replace
script to go through the cmcdde.tmp file before executing it but it didn't
succeed (I'm not sure which signs I should search for to exchange for
åäö, †„” or åäö or ├Ñ├ñ├ or other?)
I have also tried putting
cmd /c or cmd /a /c before the echo commands (as sort of described
here)
but it doesn't seem to make a difference.
Please let me know if something which parts of the question that are unclear.
I managed to find a solution. Turns out using the code page 1252 solves the problem.
So putting chcp 1252 at the beginning of the batch file is the solution. However, if you're using other none standard characters than me (other then the ones in the nordic alphabet), I'm guessing you might need another code page.
Experiment and test different ones until you get it working.

How do you code batch?

I want to create a batch file, but I can't find a way to select the coding language. If it is not there, is there another program I can use to code something for a school project in batch?
Go to Start>Programs>Accessories>Command Prompt and right-click; Send to desktop.
This will create a desktop "shortcut".
Right-click on the shortcut to set properties like text colour, size and font.
This will open what is commonly referred to as a "Dos session."
you can exit from that screen (It isn't DOS - it emulates DOS) by typing
QUIT
(and every command ends with the enter key (never shown)
Then just use a text-editor (Notepad at a pinch, I prefer Editplus to create the programs.
Just google "batch file programming tutorial" or something, I promise you will find something interesting. Go through this, for example: http://www.dreamincode.net/forums/topic/55203-batch-tutorial-part-1/ to get a basic understanding of batch and programming (although I wouldn't call batch programming; more likely to be called a scripting language).
(By the way, I find Notepad++ very good, but you don't need a special editor, as any text editor, for example Notepad.exe works fine, pre-installed with Windows.)

How do I make a batch file start at the top when run?

I've created a batch file, but when I run it and it loads, it goes down to where the user input is, cutting off part of my program.
Is there any way to make it start at the top and make the user have to manually scroll it down to look at what he's entering in?
If you mean you generate a lot of text to the console (more than one page worth) and then ask the user a question, like:
type bighonkintextfile
set /p answer=Yes?
I see only one quick solution. Don't just generate all that output. Pass it through a pager of some sort, something like:
type bighonkintextfile | more
set /p answer=Yes?
Then the user will be able to read it from the top and once more exits, the user will be asked for a response.
If you want something more robust or pretty-looking, I'd be looking at doing that with a well-crafted executable rather than a batch file.

Resources