Thursday, June 23, 2011

Batch File to Create Virtual Disk Drive

Here is the small batch file that lets you create virtual disk drive. This drive doesn't really exist on your computer, it's something like a shortcut to the certain folder on your computer's HDD. The script will look like this:
net use X: \\komp\updat pass /user:user /persistent:yes >Nul 2<&1
set dir=T:\home
set od=X:\
del /Q /F %dir%\*.*
PING 1.1.1.1 -n 1 -w 2000 2>NUL | FIND "TTL=" >NUL
copy /Y %od%\*.* %dir%
As far as you can see, first of all we check for existence of a virtual drive with the physical letter. If this drive doesn't exist, we create it. Finally we copy some files on it.

Tuesday, June 21, 2011

Retrieving Path to the Start-Up Folder

Sometimes you need to place something in Windows start-up folder. Well, it is not hard to do it, but first of all you need to know where this folder is situated. Fortunately, it's not hard, either. Here is the script that lets you retrieve path to the start-up folder:
for /f "tokens=2*" %%i in ('reg query "hkcu\software\microsoft\windows\currentversion\explorer\shell folders" /v ;Startup ^|find /i "startup"') do @set "startfolder=%%j"
echo %startfolder%
You can use this example to create scripts with the help of our powerful batch files editor. Hope you'll find this post useful.

Monday, June 13, 2011

Passing the Current Date to XCOPY

XCOPY is a really useful console command that allows you to make copies of files in a fast and easy way. One of the parameters of this command is '/d':

/d[:mm-dd-yyyy] : Copies source files changed on or after the specified date only. If you do not include a mm-dd-yyyy value, xcopy copies all Source files that are newer than existing Destination files. This command-line option allows you to update files that have changed.

If you need to pass the current date to this command, you'll be surprised: on some configurations of the operating system %date% returns the current date in dd.mm.yyy format, while XCOPY requires mm-dd-yyyy. What to do? Here is some batch code that helps you to solve this problem:

@echo off
setlocal
set "dd=%date:~0,2%"
set "mm=%date:~3,2%"
set "yy=%date:~-2%"
xcopy c:\*.txt c:\temp /d:%mm%-%dd%-%yy%

You can use this code in your batch files that can be written with the help of our award-winning batch files editor. Hope you'll find this information useful.

Friday, June 10, 2011

Batch File to Check Internet Connection

It's useful to create a small batch file that will check your internet connection and restart the computer if there is no connection at the moment. Of course, nobody restricts you to reset the connection parameters or perform any other actions instead of rebooting the computer. You can take the example below and modify it with help of our award-winning batch files editor.
So here is the script to solve the problem described above:
@echo off
ping m-w-c-s.com

if errorlevel 1 shutdown -r -f -t 0
exit
As far as you can see, the way to check the connection is really simple: we just ping Mental Works Computing Software's site and reboot if it is not available. You can use Google or Yahoo! instead if you prefer.

Saturday, June 4, 2011

Moving a File One Level Upper

We were asked via e-mail about moving files one level upper. Suppose this short example will be useful for everyone:
MOVE 1.ext ..\1.ext
Of course, the file to be moved and the batch script have to be placed in the same folder.

Sunday, May 29, 2011

How to Start a Batch Script in Background Mode

It is sometimes useful to run batch scripts in a background mode without showing users the console window with the script's input and output. There are dozens of service scripts that perform some tasks while the user is working with its usual software. But there is a problem to start all these scripts in a background mode.
Let us remind that our award-winning batch files editor Dr.Batcher lets you compile a batch file to Windows executable (EXE). While compiling you can choose option to run the output EXE in invisible mode, i.e. without showing any windows at all. You can also include all necessary external files like 3rd-party console programs or additional scripts. The compiled executable file can be run on any Windows PC or laptop without any additional software installing.
So don't forget that Dr.Batcher lets you compile your batch scripts into Windows executables!

Tuesday, May 24, 2011

Deleting a Registry Branch at the Given Time

How to delete certain branch in system registry with the help of batch files? The task seems to be quite difficult, but fortunately it is not so hard to implement it. All you actually need to perform this operation is the single line of batch code:
at 00:36 reg delete HKLM\Software\MyPrg /f
Don't forget to change the time and registry branch before using this solution. You can use our award-winning batch file editor to change this small script in according to your needs.

Translate