Tag Info

Hot answers tagged

64

The correct way to sleep in a batch file is to use the timeout command, introduced in Windows 2000. To wait somewhere between 29 and 30 seconds: timeout /t 30 The timeout would get interrupted if the user hits any key; however, the command also accepts the optional switch /nobreak, which effectively ignores anything the user may press, except an explicit ...


26

This will get most of it: Net Use If you have any drives mapped via subst you would also need to get those: Subst For completeness, you would do it like this in Powershell (if you are on windows 7 or have installed it): gwmi win32_LogicalDisk -filter DriveType=4 You can also do it from the command prompt or a batch file using WMI like this: wmic ...


24

Try running START /WAIT Install.exe


20

Use NSSM to run a .BAT or any old .EXE file as a service. It is almost a replacement for SRVANY and is a no frill no fuss application. http://iain.cx/src/nssm/ I had the same problem as you, and NSSM was the only utility that worked.


18

The correct way to do this is to use the timeout command, introduced in Windows 2000. To wait 30 seconds: timeout /t 30 The timeout would get interrupted if the user hits any key; however, the command also accepts the optional switch /nobreak, which effectively ignores anything the user may press, except an explicit CTRL-C: timeout /t 30 /nobreak ...


15

The correct way to sleep in a batch file is to use the timeout command, introduced in Windows 2000. To wait 30 seconds: timeout /t 30 The timeout would get interrupted if the user hits any key; however, the command also accepts the optional switch /nobreak, which effectively ignores anything the user may press, except an explicit CTRL-C: timeout /t 30 ...


14

RAID is not meant to be a replacement for backups. It's a method for making your harddisks redundant. If one disk is failing, the information will still be available on the partition. But let's say you accidentally delete files or the folders on the RAID partition. In this case the deleted data will not be available on the other disks of the array. So, if ...


13

Use the CALL keyword: call foo.bat file1.txt call foo.bat file2.txt


12

forfiles -p c:\pathtofiles\ -m *.rar -d -5 -c "cmd /c del @path" Where -5 is the age of the files you want to delete (5 days or older in this case). This script is deleting .rar files - drop the -m *.rar if you want to delete any file type.


12

I.think you named your script ping.bat or ping.cmd and it is calling itself. This happens because of a design decision that was introduced in DOS 2.0. On MS-DOS, Windows, and MS-DOS clones and derivatives, the current directory is first in the search path. When DOS is searching for a command it first checks to see if it an internal command, built into ...


10

Either use one of many tee clones for Windows. Or if you're using PowerShell, you can use Tee-Object.


10

To use diskpart, there is no need to create an intermediate file. Try: echo list volume | diskpart


10

I'm using WOL, the interface is simple enough but you can do a lot with it. It's a freeware. It might be what's you're looking for.


10

This should work so long as the account you run the scheduled task using has correct access to the network share where the bat file is located. Depending on what the script does, I'd stagger the run times by department. You only need a minute or two of variance to minimize the odds of a staggering hit right at 12. Regarding the commenter above who mentions ...


9

You can use NTFS ACLs to protect the files from users who are not authorized to execute them. Users who are authorized to execute them, by definition, can read the passwords (in the obfuscated form, if you choose to obfuscate them). Access to execute implies access to read. If the script can de-obfuscate the password so can the user. Assuming you're trying ...


8

You can use the "default choice" and "timeout" options of the built-in choice command to create a delay. @echo off echo Hi, I'm doing some stuff echo OK, now I need to take a breather for 5 seconds... choice /d y /t 5 > nul echo Times up! Here I go again...


8

Of course you can't run a service like that. Did you try using srvany in server 2008? As far as I know there is no 'official' version of srvany for s2k8, but you can always try, can you not? EDIT: Oh, I forgot! We also use FireDaemon to run non-service applications as services. Though, it is not free and its functionality is a bit too much for your needs.


8

Windows Scheduler -- When my computer starts I'm pretty sure you can the built-in Windows Scheduler to execute your batch file on startup. Try this: Start > Programs > Accessories > System Tools > Scheduled Tasks Select the location of your batch file and on the next page select "When my computer starts". You may also want to move it to somewhere OTHER ...


8

http://technet.microsoft.com/en-us/magazine/2007.06.utilityspotlight.aspx EDIT: If you are giving the customer a single file to run, why not create a self extracting RAR with WinRAR and set the "Require Administrator" flag in SFX options? This absolves you of your limit of only 1 file, you can have all the resources you need. Alternatively make your SFX ...


8

It's possible, but... setlocal set _today=%date:.=% set _year=%_today:~0,4% set _month=%_today:~4,2% set _day=%_today:~6,2% :: leap year? set /a _yearm400=_year %% 400 set /a _yearm100=_year %% 100 set /a _yearm4=_year %% 4 if %_yearm400% equ 0 (set _leap=1) ^ else (if %_yearm100% equ 0 (set _leap=0) ^ else (if %_yearm4% equ 0 (set _leap=1) ^ else (set ...


8

If powershell is acceptable (should be, as its enabled by default on Server 2008+) try this: $numberOfDays = 3 $Now = Get-Date $TargetFolder = “C:\myoldfiles” $LastWrite = $Now.AddDays(-$numberOfDays) $Files = get-childitem $TargetFolder -include *.bak, *.x86 -recurse | Where {$_.LastWriteTime -le “$LastWrite”} foreach ($File in $Files) { write-host ...


7

Here's a little script I wrote that I keep on my USB utility drive... GREAT for citrix servers :) @echo off Echo Started %time% Echo Started %time% >> temps.txt Echo Running for XP... >> temps.txt Echo Running for XP... FOR /F "tokens=*" %%G IN ('DIR /B /AD') DO IF EXIST "%%G\Local Settings\Temp\" ( RMDIR /S /Q "%%G\Local Settings\Temp" ...


7

There are semantic differences in the command language used for each (.bat files get a compatibility version). Some of these can be illustrated by this script from over here: @echo off&setlocal ENABLEEXTENSIONS call :func&&echo/I'm a cmd||echo/I'm a bat goto :EOF :func md;2>nul set var=1 Basically, .cmd files get the current, sexier ...


7

A complete reference of environment variables can be found here, on the microsoft site, it can also be found in a registry key. HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders String value: Personal In the event the My Documents folder is not in the standard location, pulling the information out the registry key is ...


7

Windows batch files (since Windows XP, but possibly earlier) support the %* construct, which evaluates to all the parameters from %1 onwards. Unfortunately, this doesn't honour the SHIFT command, so the following won't work: @echo off set EATEN=%1 shift call other.bat %* It'll still pass the first parameter on to the second batch file.


7

@echo off cls setlocal enabledelayedexpansion set "_DRIVE.LETTERS.FREE=Z Y X W V U T S R Q P O N M L K J I H G F E D C B A " for /f "skip=1 tokens=1,2 delims=: " %%a in ('wmic logicaldisk get deviceid^,volumename') do ( set "_DRIVE.LETTERS.USED=!_DRIVE.LETTERS.USED!%%a,%%b@" set "_DRIVE.LETTERS.FREE=!_DRIVE.LETTERS.FREE:%%a =!" ) set ...


7

Try for /? on the command line. The help shows all kinds of useful filename substitutions, such as: %~I - expands %I removing any surrounding quotes (") %~fI - expands %I to a fully qualified path name %~dI - expands %I to a drive letter only %~pI - expands %I to a path only %~nI - expands %I to a file name only %~xI ...


7

Try using forfiles instead. It seems to be more restrictive on what it returns for the extension, plus it has the added benefit of a built in for loop. Should already be on the Win7 box, but you might have to install a 2003 Server Resource kit on the XP box to get it on there.


7

It's not ideal, but you could have a separate task that just writes the username to a log file at the same time, and correlate the logs later. For that matter, since the task runs at login, this information is already available in the event logs. If you're really desparate to not correlate these later, you could add code (or a step) to the existing task to ...


6

You could create a batch file to delete the files in the subfolder, then create a scheduled task to run the batch file every 4 hours. Since the windows scheduler doesn't allow for hourly tasks you would have to go into the advanced options and create multiple daily tasks that are offset by 4 hours from each other.



Only top voted, non community-wiki answers of a minimum length are eligible