is it possible to make a file that when double clicked, it will run "ping 8.8.8.8 -t" to Windows Command Prompt automatically.
so dont need to "Windows+R > ping 8.8.8.8 -t > enter" to do that
do i need a compiler to do that?
Yes, make a .bat file with your text editor (the flat text one) and paste the command in that file. Such as:
ping 8.8.8.8 -t
Be sure to save it as .bat and not as .txt.
Related
I'm trying to use psexec.exe to fire up Excel and then use Excel to open a specific .xlsx file.
I've just started learning psexec and I have written commands that work 'incrementally' in order to be sure my initial building blocks were correct along the way. Decided to actually start with NOTEPAD and a specific TEXT FILE to start:
(Please note, my goal is to execute this process on the local machine, not a remote machine, and for it to be Interactive, thus the -i switch)
This Works (just opens a blank Notepad window)
"C:\Users\Username\OneDrive - OrgName\Desktop\RunAs Test\psexec.exe" -i -u domain\username -p Password C:\Windows\system32\notepad.exe
This does not work - and I am positive the exe path and the file path are correct, I've tried them separately
"C:\Users\Username\OneDrive - OrgName\Desktop\RunAs Test\psexec.exe" -i -u domain\username -p Password C:\Windows\system32\notepad.exe \\server\data\mpsc-users\UserName\Test\sadf.txt
(It just returns the boilerplate 3 lines copyright, but with no mention of Error Code or results at all. Nothing else happens)
PsTools.chm is very clear on why it wont work
"Arguments to pass (note that file paths must be absolute paths on the
target system)"
"psexec.exe" -i \\somewhere.... C:\Windows\system32\notepad.exe c:\users\Isaac\desktop\hello.txt
should work (if the file exists on the remote system)
i work as a network engineer and i would like to write some scripts to make my job more easy especially in situations where i cannot be on site and the client cannot connect to the internet so this is one script i made that would give me basic network test info
However my issue is i cant get it to output to a txt file after the script is ran, i want the user having the choice of weather to create the file or not. after i go through the prompt and click yes it will pause for a bit ( i assume its running the commands) however no file is made on my desktop where the file is stored.
At my work i am running windows 10, and at home xp but i need this to be able to run on either.
here is a copy of what i am having trouble with i have more questions but would first like to get this fixed
i have tried using >>output.txt (commands in here) i also tried command >> output.txt but either way there is no file on my desktop
>>output.txt (ipconfig /all ping google.com tracert google.com)
The file will be saved to your current directory. You'd need to use "%userprofile%\desktop\output.txt" as the file destination to put it on the desktop. You may need the quotes in case the resolution ofuserprofile` contains separators.
I think you have three (3) commands here and need to tell the shell to do them all.
>>"%USERPROFILE%\Desktop\output.txt" (ipconfig /all & ping google.com & tracert google.com)
Alternatively, the .bat script might look like:
>>"%USERPROFILE%\Desktop\output.txt" (
ipconfig /all
ping google.com
tracert google.com
)
So normally I can type this into the cmd window ping 216.52.241.254 -t and it tells me my ping to a certain server. How can I create a .bat file that automatically opens the cmd window and types it in so that I don't have to write it out every single time. I tried just putting in ping 216.52.241.254 -t and it just spams it over and over again.
Another way of doing this (potentially a lot easier for you) would be to create a shortcut:
Right Click in windows explorer and hover over "New"
Select "Shortcut"
A dialogue will pop-up. Enter the command you wish to utilize: ping 216.52.241.254 -t
Click Next and name the file.
Now whenever you open the shortcut, it will execute the command.
The advantage of this method over the other is its simpler and allows you to pin it to the Starmenu or Taskbar.
Mona.
It spammed it over and over because you called the batch file ping so it was launching itself.
Very simple:
#echo off
ping 216.52.241.254 -t
Echo.
pause
Open Notepad
Copy and paste this in.
Save as a .bat file, ensuring that you select "all files" option
Run the batch file any time you want to check your ping.
Done!
type the following:
cd\
ping -t 216.52.241.254
You must have keep the file name as 'ping.bat'.
Rename it to something else and it will definitely work.
ex : ping1.bat, something.bat etc., anything else but ping.
It spams it again and again because you used -t which "Pings the specified host until stopped." if you lose the -t it won't do that. Type Ping /? to look through all the options available when using ping and select what is appropriate for what you want it to do.
On a Windows 7, I have an executable, say immutableProg.exe, which I want to call 3 times with certain parameters. This is done by the batch file myBatch.bat.
Content of myBatch.bat:
immutableProg.exe -a
immutableProg.exe -b
immutableProg.exe -c
The executable immutableProg.exe does have a special --keep switch which stops the executable from returning until a user hits any key. Now I want to add the --keep switch if and only if my batch myBatch.bat got double clicked like:
immutableProg.exe -a
immutableProg.exe -b
immutableProg.exe -c --keep
It shall NOT be added if a user calls the batch from commandline.
The question: How can I find out (from inside my batch's view) if it was opened by a double click or from command line?
Changing the default behavior of the immutableProg.exe is unfortunatelly not an option, neither is to give the batch file an extra parameter from commandline.
%cmdcmdline% gives the exact command line used to start the current Cmd.exe.
When launched from a command console, this var is "%SystemRoot%\system32\cmd.exe".
When launched from explorer (double clicked) this var is cmd /c ""{full_path_to_the_bat_file}"
To actually use the info in haxtbh's answer, you can do the following. It is not fool proof, but it usually works fine. It would take an unusual scenario for it to give a false reading.
echo %cmdcmdline%|find /i """%~f0""">nul && echo doubleClick || echo console launch
I need to send some information from the command prompt to a text file but I would like to have it just continue adding to the text file.
For example
ipconfig >C:\Users\Desktop\File.TXT
and then
tasklist >C:\Users\Dekstop\File.TXT.
When the second command runs it overwrites the file. I would like it to just add on to the file.
Use
tasklist >> C:\Users\Desktop\File.TXT
for the second command
>> is used to append the changes to the old file:
ipconfig > C:\Users\Desktop\File.TXT
tasklist >> C:\Users\Dekstop\File.TXT