Tag Info

New answers tagged

0

I found the solution, thanks dano to let me think how to do this after I done searching about how to use it in for loop, I finally got the answer that I have to use ! instead of % and use "SETLOCAL ENABLEDELAYEDEXPANSION" too Many Thanks @echo off :loop SETLOCAL ENABLEDELAYEDEXPANSION if exist "C:\Users\Administrator\Desktop\converted\*.jpg" ( for %%b in ...


2

You can use %random% to perform this. set /a n=%random%%6+1 will generate a random number between 1 and 5. %random% % 6 generates a number between 0 and 5 so %random% % 6 + 1 generates a number between 1 and 6. Doc: http://stackoverflow.com/questions/5777400/how-to-use-random-in-batch-script EDIT : I can't comment yet so here is how to implement this: ...


2

set /p UserInputPath = Enter chosen PC: ^ This space is included in the name of the variable So you end with a variable named %UserInputPath % Better use set /p "UserInputPath=Enter Chosen PC: " ping "%UserInputPath%.store.domain.company.com"


0

Here's a fancy bash script for you. Hacked it out earlier today for the original question before realizing it was for Windows. Considered converting it to a batch file for you but it looked painful. Reminded me of writing startup scripts in college. You need to use Powershell or spin up a *nix host somewhere. Powershell v3 is really nice. You could convert ...


-1

Looks like you did fall into the delayed expansion trap and your code snippet is enclosed between ( and ). When you use a variable changed inside such a block then you need to enable delayed expansion... @echo off SETLOCAL enableextensions enabledelayedexpansion set "UserInputPath=AnotherServer" ( set "UserInputPath=MyServerName" rem set /p ...


1

Following script works, at least for me on Win7. @echo off set /p name="Enter name:" ping %name%.google.com We first ask user to enter name, then store it in name variable, and pass it to ping (see %name%) adding google.com (just as example!).


0

This visual basic script does 3 things. ~ Grabs the current directory of where .VBS is stored and takes a file name. ~ Runs the given file w/ Admin privileges. (doesn't prompt for UAC) ~ Runs the file silently, without the CMD you mention. bElevate = False if WScript.Arguments.Count > 0 Then If WScript.Arguments(WScript.Arguments.Count-1) <> "|" ...


0

Deleting this registry key (as an admin) was missing from all the above (Windows 8.1): HKEY_CURRENT_USER\Software\Microsoft\Windows\Roaming\OpenWith\FileExts.bat\UserChoice. Hope this helps.


1

Run this batch file from the parent folder of Reports folder: for /f "delims=" %%a in ('dir /b /s "Reports folder\*.rep"') do for /f "tokens=2 delims=-" %%i in ("%%~a") do ( if not exist "%%~dpa%%i\" md "%%~dpa%%i" move "%%~a" "%%~dpa%%i\" ) %%a and %%i are the variables used in the two for loops.The former contains the full paths to the .REP ...


0

I first discovered this bug by mistake in 2010. I ultimately discovered my mistake - redirecting stderr to stream 0 (stdin for the current process) makes no logical sense, and cmd.exe did not have a handler for that scenario, so it just bailed out. The correct syntax was: dir 2> nul (if I only wanted to redirect the error) or dir 2>nul 1>&2 (if I ...


0

First method works after some changes: open Notepad copy all file names with extension which need to be deleted after adding del at the beginning like del File1.bin del File20.bin del File21.bin save the file as xyz.bat in the same folder run the file


2

You asked for Batch, but i answer with Powershell because i think that today Batch is a bit obsolete for such a task, hoping your system supports Powershell : $rootDir = "U:\Test" $files = Get-ChildItem $rootDir -Filter *.rep foreach($file in $files) { $folder = $file.toString().split("-")[1] $sourcefile = "$rootDir\$file" $targetdir = ...


0

You can do at least part of that using Windows Scheduler. Scheduled jobs can certainly be triggered on log in/out - Not sure about password change, possibly there is an event log message & they can also be used to trigger scheduled jobs. I'll try and look it up when I get 5 minutes.


0

PsExec is probably what you're looking for. https://technet.microsoft.com/en-us/sysinternals/bb897553.aspx Usage: psexec [\computer[,computer2[,...] | @file]][-u user [-p psswd][-n s][-r servicename][-h][-l][-s|-e][-x][-i [session]][-c [-f|-v]][-w directory][-d][-][-a n,n,...] cmd [arguments]


0

Save this as a .VBS file and use as a template to do what you want. You can find more help about the SendKeys method here. set WshShell = CreateObject("WScript.Shell") WshShell.Run "%SystemRoot%\System32\SndVol.exe" WScript.Sleep 1000 WshShell.AppActivate "Volume Mixer" WshShell.SendKeys "{PGUP}" ' Turn the volume up by 20. If muted it will unmute it. ...


-1

There are other great options than using a batch file for your purpose, but since you want it that way, here is the code @echo off Call :YesNoBox "Are you sure you want to do that?" if "%YesNo%"=="7" ( Call :MessageBox "You answered NO" "Heading" exit /b ) Code for invoking the message box exit /b :YesNoBox REM returns 6 = Yes, 7 = No. Type=4 = Yes/No ...


1

Look into Robocopy, Xcopy or copy commands for windows. Edit the following code to fit your needs, write into a notepad and save with .bat extension. Robocopy D:\Office\*.pdf D:\YourNewFolder1 Robocopy D:\Office\*.pdf D:\YourNewFolder2 Robocopy D:\Office\*.pdf D:\YourNewFolder3 The * character is called a wildcard. It copies ALL file names with the .pdf ...


1

Delete all files from current directory and sub-directories but leaving the folders structure. (/Q) switch is for asking the user if he is ok to delete Caution : try it without the /Q to make sure you are not deleting anything precious. del /S * /Q


0

To change your COMSPEC environment variable, you can put default value (%SystemRoot%\system32\cmd.exe) with this file.reg: Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment] "ComSpec"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,\ ...


1

It sounds like your COMSPEC variable is corrupted. On my Windows 7 machine I have ComSpec=C:\Windows\system32\cmd.exe. A corrupted COMSPEC value will also prevent pipes from working.


1

Im not sure at 100% if it will work but I think what you have to do is: echo ( Your Code ) > Directory\Batchfile.bat


0

It is possible, but it's at the cost of you being able to edit the program after. What you need to do is grab this utility here. All it is is a Batch file to EXE compiler, i.e. hides the password, but you're not going to be able to edit it after compilation. As pointed out by @EBGreen, you would still only need a Hex editor to view the password. However, ...


2

Option 1: Use a proper programming language that allows you to compile the code, and employ encryption/obfuscation techniques so the password is not easily visible to any inquisitive person. Option 2: There are Batch to EXE converters you can use. A tech-savvy user can probably use a hex editor (or even a text editor or a strings utility) to view the plain ...


0

I have taken Elvins code and developed it slightly to solve the issue of spaces being included in folder paths and names. The For Do command now uses a CSV file to source the folder paths from, it was then necessary to include the "delims=," option within the For command. for /f "delims=," %a in (D:\Batch_Files\Test_Bench\Folders_List.csv) do copy "%a\*" ...


1

There is no quick solution. Copy and Paste at this time is all you can do. Highlight all the PDF's in the folder, then open up a new folder and do Ctrl+V to paste. Repeat in each folder. You can possibly select all of the files you want to copy by highlighting them, using Ctrl+C, then selecting all the folders you want to copy them to, by using Ctrl+Click, ...


2

You have to put the ftp commands to a separate file. You cannot put lines you otherwise type on terminal to .bat file and expect it to behave identically. The .bat file can include only Windows commands. When you run the ftp command from the batch file, it waits for its commands. It does not know about the .bat file, so it cannot read the commands from ...


2

One solution is to deploy a package containing the following batch file and lenovo's utility: CheckBattery.bat LenovoBattery.exe CheckBattery.bat - - This .bat will check to make sure it can communicate with the file share, then will execute, saving the .csv. If the share is unreachable the script will exit. :Check Network Ping ...


-1

set path=%path%;C:\bin reg.exe ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /d ^%path^% /f


3

Considering a file containing with a similar contents containing a list of directories such as: c: c:\users c:\anyotherfolder xcopy inside a for loop will do the job :) for /f %a in (list.txt) do xcopy /e %a\* c:\destination_folder\ (by copying the whole directory tree (owing to /e) ) You should add an extra % to the variable name if you want to ...


1

Try this: @ECHO OFF SET var1=%1 SET var2=%2 E:\Erp\7z.exe u -tzip E:\Erp\Test1.zip %var1% copy /b %var2%\test1.zip E:\Erp\Final_output.zip


1

Quotes in wrong place. Plus needless indirection. start /b "" cmd.exe /c "touch.exe -xamq -t 201010201020 -- batch.cmd" So you are asking CMD to ask Explorer (Start command) to start CMD to run a program. start /b "" cmd.exe /c "touch.exe" -xamq -t 201010201020 -- batch.cmd Better "touch.exe" -xamq -t 201010201020 -- batch.cmd To do it in Windows ...


0

This will give you a nicely formatted text table: wmic /output:Services.txt service where "DisplayName like 'CommVault%'" get DisplayName,State,StartMode You can also use the various XSL files in Windows\System32\wbem and Windows\System32\wbem\en-US (or whatever language code your copy of Windows uses) to format the wmic output in various ways. For ...


1

In order to echo the > character, you need to escape it with ^. If the contents of File2.bat are: echo echo abc ^>^> op.txt >> main.txt then after running File2.bat, the contents of main.txt will be: echo abc >> op.txt Read more about escape characters.


0

Call this MyServiceViewer.hta. <html> <head> <style> BODY {font-size :100%;font-family: Arial, Helvetica, sans-serif;color: black; background:URL(images/watermark.gif);background-color: white; margin-top:0; margin-left:0pt; margin-right:0pt ; text-align:Justify} P {margin-left:40pt;margin-right:10pt} TABLE ...


0

You are running the Batch File in a "privileged space". Microsoft has become wise to this fact, and you need to address this accordingly. Most Virii (Viruses) and malware exploit the root of the OS Drive. What you need to do is to create a folder and move your batch file in there. C:\test\test.bat As an aside, in the "server world" it is actually ...


1

The batch file looks fine to me and works here (as long as you have directory creation rights in Program Files of course, so you might want to run it from an elevated (admin) command prompt). One tip is to modify the directory existence test slightly. Instead of: IF EXIST "C:\Program Files\NexphaseV6\ECF" you should use: IF EXIST "C:\Program ...


0

To improve your approach a little: keep forfiles with /d -2 switch to treat older files only use for %G with if /I [%~xG] neq [.idf] to omit files with .idf extension double all % if run from a batch file: %%G instead of %G etc. remove @echo no sooner than debugged. The command: forfiles /p "C:\Test" /s /m *.* /c "cmd /c for %G in (@path) do @if /I ...


0

Set the fill path to the vim like this: C:\cygwin64\bin\vim Main.cs -c ":%s#internal#public#ge | update" or /drives/c/cygwin64/bin/vim Main.cs -c ":%s#internal#public#ge | update"


0

start "Chrome" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --profile-directory="Profile 2" start "webpage name" "http://someurl.com/" start "Chrome" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --profile-directory="Profile 3" start "webpage name" "http://someurl.com/"


1

There is no way to automate Group Policy from the command line. That's what domain controllers are for. The only thing you can do is script the registry change that the GPO would have affected. The location you observed from Process Monitor is just the copy of the GPO itself, not the application of it. The actual location in the registry you need to ...


0

this really is a stupid hack and in my opinion not worth the effort but if it uses your default browser and calls it with a command line argument you could set up a batch file as your default for the "http://" protocol association or whatever it seems to use. You should be able to find out by viewing the Command Line column in the process tab of the task ...


0

You could try checking the errorlevel after the "dir X:\" command. The errorlevel is the integer value returned of the last executed command in your command line session. 0 means success if errorlevel 1 command means command is executed if the errorlevel is greater or equal 1 :drivex net use x: \\computer\share if errorlevel 1 goto drivey dir x:\ if ...


0

If you're comfortable with Powershell, you can do this by using the GetWmiObject cmdlet with the _Win32_Product_ option.


0

Have you tried adding the PSExec password switch with the account name you're running the batch with? -p Specifies optional password for user name. If you omit this you will be prompted to enter a hidden password.


1

That's not related to pushd. You need to use double percent signs when run from batch (as oposed to directly from cmd line.), so it should become: for /f %%i in ('dir /a:d /b bu* ') do echo /q %%i MS reference: https://technet.microsoft.com/en-us/library/cc754900.aspx



Top 50 recent answers are included