Tag Info

Hot answers tagged

80

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 ...


32

Try running START /WAIT Install.exe


27

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 ...


22

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.


19

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


13

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 ...


11

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 ...


10

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


10

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


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 ...


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.


9

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...


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

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

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

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 ...


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

Powershell: Get-WmiObject Win32_Process | Select Name, ProcessId, CommandLine


8

If the servers are on the domain. Local Administrator Password Solution Microsoft is offering the Local Administrator Password Solution (LAPS) that provides a solution to the issue of using a common local account with an identical password on every computer in a domain. LAPS resolves this issue by setting a different, random password for the common ...


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 ...


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

This line will uninstall all versions of JAVA: wmic product where "name like 'Java%% %%'" call uninstall /nointeractive


7

If I understand your question correctly, I think you want to separate commands on individual lines... @echo off command1 command2 Is this what you are looking for?


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 ...



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