Windows task scheduler: save a text file - windows

Gist: I want a task scheduled that just saves an existing text file every 15 minutes.
I used the task scheduler to create a task and when I'm in the area where I add actions, I'm stuck. I know, this sounds stupid.
I chose start a program and set the program to "C:\Windows\System32\notepad.exe". I don't know what to put in the Arguments or Start in. I'm thinking I should put the path to the file, but that would just open it, right? I want it saved. I tried adding a -s /s or whatever but it doesn't seem to work.

Very interesting. Try moving file to itself by "cmd /c move file.txt file.txt". You are correct that opening file in notepad would need you to save it. however I would like to say no file, even if some changes being made to it, need to be saved. In my understanding if any application that is making change to the file is actually writing to it permanently.

Related

How to manage files with a batchscript via "Send To"?

I want to improve my file managent and need some help to get started.
For this specific script, my idea is the following:
while in Explorer
rightclick a file -> Send To -> "Apps[.bat]"
Then the script starts and does the following:
moves the whole directory (and subfolders) of the selected file to a specified location (in my case C:\Users\Name\Desktop\Apps\Files)
so sending Name\Downloads\Coolportableapplication\Coolapp.exe to the batch results in Name\Desktop\Apps\Files\Coolportableapplication\Coolapp.exe
creates a shortcut of C:\Users\Name\Desktop\Apps\Files\Coolportableapplication\Coolapp.exe in C:\Users\Name\Desktop\Apps
Is this generally possible with a batchscript?
This isn't my first batch but I've never dealt with unspecified files and English isn't my native language so I couldn't really find anything useful for my cause, though I am sure my little script won't be too much of a problem for you. Based on that batch, I want to create similar scripts but I just have no idea how to begin with that one.
Thanks a lot!
No need for a batch file but anyway.
1: Type shell:sendto into your explorer window and copy the shortcut to your directory "C:\Users\Name\Desktop\Apps\Files". This directory will now show as default in your Send To options.

Run a hidden cmd on click

This is driving me crazy. I have a pretty application that does.. well, things. To start it up, some start.cmd needs to be executed. What start.cmd does is to set up some environment variables, check a few things and then start my main GUI program.
Now, everything works fine: when I click on my start.cmd everything gets launched properly. However, clicking on start.cmd causes an ugly, ugly cmd.exe to appear for an instant and then disappear. This is unacceptable!
I started looking around and I found this. It suggests to use some wscript invisible.vbsto run my start.cmd. This, however, works fine from the terminal, but I can't click on invisible.vbs directly to get what I need.
This is where I thought that I could use shortcut with the wscript invisible.vbs start.cmd command in it. However, you cannot make relative path shortcuts in Windows, which means that if I use a shortcut I will never be able to move my folder again, which is pretty bad if I need to install it around my users' computers.
So I really have no clue on how to get this apparently trivial thing done: how can I get a start.cmd batch file executed without anything showing and without having to launch anything from the terminal, and in a way that will allow me to move my folder around?
Check the hidder.bat . You can use it to wrap a .bat or .exe file into iexpress executable file that will be ran in hidden mode.To use you need:
hidder.bat example.bat hiddenExample.exe
this line will create a hiddenExample.exe which clicked will start your bat in hidden/background mode.You can also take a look at this question

Can you run Windows batch file not in a command prompt?

My programming teacher is requiring that everyone participate in the science fair this year, and now they accept computer-related projects. So, knowing only one language (Windows batch), I asked if I could make some kind of text based game in batch code. She said that I can only write the code, but not execute it.
She said that if we're even caught on the command prompt, we apparently get in big trouble and never get access to a school computer for the rest of the time I'm at the high school, or something like that... Even if all the code contains is a bunch of echos and simple variables, she won't let me and my partner run it. She also said that we must work on the project during school in her class.
So to sum all that up, she's letting me write a game/program, but I'm not allowed to test it to make sure it works in school, which will be when I'm writing it most...
So is there any way to run/test a batch script with simple echo and set /p commands without the "dangerous, black command prompt" showing up?
I think she has no idea what she's talking about, because on the board, she wrote "back script" lol
A batch file runs like any other executable file by double-clicking the file within Windows. However, because a batch file runs in a command line it immediately exits when done, so you may only see a black box for a second.
If the batch file is closing too fast, or you want to read the output from the batch file you can edit the batch file and add a pause to the end of the file. The pause command waits for user input before continuing.
A .BAT file can be made into a .EXE or .COM file to keep the program's source hidden from a user. You could use the .BAT to .EXE converter file to convert the batch files to .EXE file. In this program you can point to the batch file you want to convert into an executable file, include additional files, change the icon of the file, and add file details.
For Information on Batch files, this is one of the best resource.
Try this:
#echo off
color F0
mode con lines=25 cols=60
cls
title "Notepad - MyProgram.bat"
set /P "name=What is your name? "
echo Hello %name%, glad to see you...
pause
Execute it via a double click or enter in files browser...

Running an .exe from within a .bat

I realize this might be a very basic question but I am slightly new to working with batch.
I am trying to use delprof to delete user profiles off multiple remote computers. I have Delprof.exe saved and can run it from a cmd window to put in different required arguments such as "/p /d:30". I can have my batch file run the application using the start command but it quickly closes the window.
I need to have delprof run from the batch but be interactive so it can prompt me with what profiles it has found and if I want to delete them. Basically Im trying to use this so I dont need to enter the arguments every time. I want it to be one click on the batch file and it will pop up with the profiles found and ask me which ones it should delete.
You are not clear on exactly what you want. But omitting start will probably do what you want. Which is run delprof as if you typed it at command line.
If not see the set /p command.
set /p remote=Enter Computer Name
delprof /c:\\%remote%

Execute a bat file when an image is viewed

I want to hide a bat file or its commands in a image file so when the image is opened the commands in the bat file is executed.
Assuming you're speaking specifically for the windows platform (what with "batch" files), you can't.
Batch files are parsed, not compiled, so an image file with batch in it would still be read as an image file.
I really can't sum it up more clearly than things just don't work like this.
However, assuming you're doing things ethically, you can re-associate, say, a .jpg extension to be opened with the command prompt and put your batch script in a text file with a .jpg extension.
Just a final note: Questions like these are often looked poorly upon by the StackOverflow members simply because you're hardly ever trying to achieve something like this with good intentions. I won't be the first to flame you, but I definitely won't be the last.
There are a number of ways in which a single file can contain two distinct streams of data which are independent of, and don't interfere with, each other. One commonly cited example of this is how it is possible to append a .zip file to a .jpg file and still have the combined file function as both types of files, depending on what sort of application is opening it. This trick takes advantage of the specific way jpeg and zip files are structured. These sorts of files are akin to polyglot program.
Another common method of embedding unrelated information into a file is steganography, which is the concealment of messages within mundane objects (like an image file.)
You might also consider using an Alternate Data Stream, though in such a case the batch file would arguably not be embedded in the image.
Once you have your batch file embedded, by whatever means, you must then find a way to cause the batch file to be run instead of--or in addition to--whichever image-viewing application the user has configured.
It can be safe to assume that the average user does not expect a file ending in .jpg (for example) to open a cmd.exe window and start executing unknown instructions. Windows Explorer, the application which under most circumstances decides what program to run when a certain file type is double clicked, has sane defaults (i.e. a .jpg file gets opened with an image viewing application) though these can be changed (though users generally don't change these sane defaults to insane customizations like cmd.exe.)
The simplest method would be to write your own handler program and cause it to become the default handler for image file types. I believe that all handler applications must be compiled PE application or library files (.exe, .dll, .scr, etc.) so another batch file won't work here. Your custom handler must reverse the embedding to retrieve the embedded batch file and then execute it with cmd.exe.
But if you've already managed to supplant the default handler with your own code then the embedded batch file is moot since you've already got your code running.
I have to echo what #Di-0xide said about this question. If you're trying to write a legitimate application and this is part of your design plan, then you need to go back to the drawing board because no legitimate application should ever do this sort of thing.
Although there are no doubt many more malace reasons why someone would want to embed a batch file within an image,
and have it execute when the image is opened. I can see at least one legitimate reason for wanting to perform the task.
What if you have a family computer, shared with your 2 kids, the wife, and yourself. Lets say you have some files you don't
want your children to come across, or a directory full of journal entries. It would be pretty neat if a simple batch file that would
change the attributes settings of the directory, containing the sensitive files. This way a parent could rest assure that their
kids wont stumble upon dads nudie pics. LOL
IE: Lets say someone wrote 2 simple batch files s.bat(to show the directory) and h.bat(to hide the directory)
hide.bat
#echo off
REM Show the directory containing sensitive info:
attrib +a +s +h +r C:\path\to\the\directory\to\hide
REM Hide this batch file(or image containing the batch file):
attrib +a +s +h +r C:\path\to\the\batch\files\hide.bat
REM Show a batch file(or image containing the batch file) that will allow for showing the directory:
attrib -a -s -h -r C:\path\to\the\batch\files\show.bat
show.bat
#echo off
REM Show the directory containing sensitive info:
attrib -a -s -h -r C:\path\to\the\directory\to\hide
REM Show the batch file(or image containing the batch file) that will allow user to hide directory:
attrib -a -s -h -r C:\path\to\the\batch\files\h.bat
REM Hide this batch file(or image containing the batch file):
attrib +a +s +h +r C:\path\to\the\batch\files\s.bat
I think it would work better having images that would execute the show.bat and hide.bat batch files, rather than just changing the icon on each batch file.
Perhaps writing a handler program that would change the attributes of the directory then open the image and associate the handler to some unused extension, would work.
Just a thought.
Simplest way to do this is to just create your batch file as normal and then create a desktop shortcut of the same batch file. Finally right-click on the shortcut and change the icon to what ever image you want. Once all changes are made then anytime the image is opened, the batch file will run.
This is easy just use winrar archive to embed bat file in image. This will run bat file before image or you can change settings to run image file before bat.
Follow this tutorial to do so:
https://www.youtube.com/watch?v=ytvKVYYrqEw

Resources