Tag Info

Hot answers tagged

30

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


20

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


16

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


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


14

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


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

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

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.


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


9

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


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

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

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

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


7

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.


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

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

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

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


6

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.


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.


6

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


6

You could try using PsExec. If the batch file is present in all machines at same location, then you could mention the list of machines in a text file and give it as an argument to this.Something like, psexec @<machines_list_file> <location to batch file on remote machines> If you dont have it on remote machine, you need to copy the batch file ...


6

i suggest you use robocopy since it has really nice features such as auto retry when the diskspace is full or when there is a network outage. in your case assuming you have network connection between those 2 machines. robocopy "source" "destination" /(any switch you might add) robocopy \22.22.222.222\c$\2003\folder \11.11.111.111\c$\2008\folder /E /Z you ...


5

You need to update the "userWorkstations" AD attribute for the users. In VBS it would be something Like: On Error Resume Next Const ADS_SCOPE_SUBTREE = 2 Set ObjRootDSE = GetObject("LDAP://RootDSE") strOU = "OU=SCRIPT,DC=Company,DC=local" Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") ...


5

Create a text file named COMPUTERS.TXT and put all the computer names in it, one per line. Then, create a .CMD file with the following code: EDIT I added %%i\ in front of *username to specify the remote machine admin user. EDIT 2 I fixed a typo in the code...changed psexec \\%%1 to psexec \\%%i. @ECHO OFF FOR /F "tokens=1" %%i IN (COMPUTERS.TXT) DO ( ...


5

You can hide the window with a VB script: Set objArgs = WScript.Arguments For Each strArg in objArgs Set WshShell = CreateObject("WScript.Shell") cmds=WshShell.RUN(strArg, 0, False) Set WshShell = Nothing Next start c:\runHidden.vbs "C:\wamp\bin\php\php5.4.3\php.exe -f 'C:\wamp\www\tst\index.php'"


5

I think WMIC commands can be run from a single line which should make it easier to add to a batch file. And by adding /nointeractive then it should disable prompting as well. Try something like this: wmic product where name="software" call uninstall /nointeractive



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