Windows Batch

12K

Solutions

11K

Contributors

Batch files are text files containing a script of commands that are executed by the command interpreter on DOS, OS/2 and Windows systems. Most commonly, they are used to perform a series of functions that are repeated -- copying a set of files created daily with one step, for example.

Share tech news, updates, or what's on your mind.

Sign up to Post

Chemo has taken a lot from me. I am having problem with a batch file and have gone back to square 1 to test simple things.

@ECHO OFF
IF EXIST %1 GOTO ITEXIST
ECHO %%1 DID NOT EXIST
GOTO EXIT
:ITEXIST
ECHO %%1 DID EXIST
:EXIT
ECHO ON

Why am I getting a syntax error?
1
I do not have a problem. I need to know where to look to learn the different types of files in script.
0
Hello Experts,

I am trying to run as administrator a .bat file on a Windows 10 virtual machine remotely via VirtualBox's command line interface. I am controlling the Windows 10 virtual machine via a Linux headless server.

Currently I am using the command:

vboxmanage guestcontrol "win10clean" exec --image "C:/Temp/run.bat" --username localadmin --password *** --verbose --wait-stdout

Output:

Opening guest session as user 'localadmin' ...
Waiting for guest session to start ...
Guest session (ID 13) has been started
Starting guest process ...
Process 'C:/Temp/run.bat' (PID 4592) started

C:\WINDOWS\system32>REG ADD HKLM\Software\Microsoft\Windows\currentversion\explorer\advanced /v Start_PowerButtonAction /t REG_DWORD /d 2 Process terminated
Exit code=1 (Status=500 [successfully terminated])
Closing guest session ...

The VM name is win10clean
The .bat file is called run.bat and is stored on the VM under the path C:/Temp/
The run.bat file is suppose to update a registry value which is why the command must be run as administrator. However the registry value says the same.
1
I want to automate the file transfer.
FTP Client : Reflection FTP Client
SFTP Server : Tectia SFTP Server.
I tried using similar to winscp scripts powershell but it didnt work.
Can someone help me providing the script which will work to transfer file to sftp server running script.
Authentication method is public key + password authentication and password must be encrypted.
0
Hi All,

I have .txt  files in FileZilla server. I need to transfer files from FileZilla server to Local Path C:\, Below is the code i am running in job schedule,

prompt
lcd C:\
open sftp.getixhealth.com 22
abcd
xyz
bin
cd /In
mput *.txt
Quit


When i run the above code batch files is getting executed but files are not genearting in Local Path C:\. Please help me in transferring files from fileZilla Server to local path C:\.

Thank You In advance....
0
Hi

I have some reports (MS excel Spreadsheets) on my folder on C drive. I have created a module in MS Access 2013 database. This module can be called using AutoExec macro. Basically I have created some scripts which will run a query and export the result into different excel files and then do the formatting. I need to transfer those excel files into SharePoint on daily basis. SharePoint is password protected. I am trying to automate the process. I use windows 7 OS, Office 2013. I am looking for a vba code/scrip or MS DOS/batch to do this work for me.

On SharePoint, there are some files already exist. I don't want to delete those files while I run script to transfer my reports into SharePoint.

Any support on this would be greatly appreciated.

Thanks
K
0
Hello Experts,

we have backup in e:\data\
e.g.
TERMSCLE31_07_2018_04_12.zip
SMECLE31_07_2018_04_18.zip
TERMSCLE01_08_2018_11_00.zip
SMECLE01_08_2018_11_05.zip
TERMSCLE02_08_2018_02_39.zip
SMECLE02_08_2018_02_45.zip
TERMSCLE03_08_2018_05_55.zip
SMECLE03_08_2018_05_56.zip

I want take backup on daily base from e:\data\<current date .zip> to two drives

e.g.
g:\ace\<create current date folder>\

k:\rule\<create current date folder>\

Please suggest this process how to done from batch script, after complete this task log (.txt or .csv) should be generated ?
0
Hi all,

       Working on a project to automate Intel ME Firmware update for a security project. Currently, using the following process:

Adjusting the below script for each model/site:
Downloading the correct patches for the model
Placing patches on server and using a .bat file to execute
Running the below script against the model(s)
While this is faster than doing each computer manually, it still takes a long time to execute each script against each model across multiple sites.

What I'm hoping to do is figure out how to incorporate if/else logic in the below scripts such that I can run the script against a massive list of computers of different models.

Also, would like to figure out how to have the script grab the .bat files from say Dropbox or the like so I don't have to go into each site specific server and have the script run against that location.

I have the following template:

$model = (Get-Ciminstance -ClassName Win32_ComputerSystem).model

switch($model){
    model1 {<#code to download bat1 from dropbox#>;Start-Process "dropboxurl\folder\file1.bat"}
    model2 {<#code to download bat2 from dropbox#>;Start-Process "dropboxurl\folder\file2.bat"}
    model3 {<#code to download bat3 from dropbox#>;Start-Process "dropboxurl\folder\file3.bat"}
    default { write-warning "Model '$model' was unexpected - No action taken"}
}

Open in new window


And I've adjusted to reflect as follows:

$model = (Get-Ciminstance -ClassName Win32_ComputerSystem).model

switch($model){
    "HP EliteDesk 800 G1 DM" {https://www.dropbox.com/some info/more info ;Start-Process "https://www.dropbox.com/home/INTEL/HPEliteDesk800G1DM?preview=sp87844.bat"}
    default { write-warning "Model '$model' was unexpected - No action taken"}
}

Open in new window


Should I have it set with the specific model name or does the switch not care?

i.e. do I need to adjust the script to point to an actual model like I have in my second example or can it just be model 1 points to the dropbox url?

Running the script doesn't give an errors except:

WARNING: Model 'Virtual Machine' was unexpected - No action taken



Does anyone have experience with this type of template and using it in the manner I am trying.
0
We run Microsoft Dynamics AX 2012. We have Remote Desktop Servers which users access, to access AX.

I'd like a PS script or bat file that I can run once a week, at midnight, to delete *.AUC and *.KTI files from all the users C:\users\%users%\appdata\local   folder on these RDS machines.

I've tried
for /D %D in ("C:\USERS\*") do del "%~fD\AppData\Local\*.auc"
for /D %D in ("C:\USERS\*") do del "%~fD\AppData\Local\*.kti"
pause

Which Errors out:
The following usage of the path operator in batch-parameter substitution is invalid: "%~fD\AppData\Local\*.auc"

Also tried:
del "%userprofile%\AppData\Local\*.auc"
del "%userprofile%\AppData\Local\*.kti"

But that only delete the files for the current user.
0
All,

We mapped a share drive with both .bat and Preferences on group policy. We also hide these folders, everything is working fine for users on Windows 7 but they are not able to see or map the folder on Windows 10, so what would be an issue with 10. Is there anything need to be checked?

REgards
0
How do I use Task Scheduler in Windows to execute a shell script file (.sh extension)?
If cannot use Task Scheduler, how to create a crobjob that execute a shell script file (.sh extension) in Windows?
0
HI

Can I have script to clear google chrome browser history.

I have tried other scripts also but these are deleting bookmark also.
moreover I need help push this script to user though gpo.
0
Hello, I need to disable batch file execution in RDP (Windows 2012 r2) session for a regular user. Administrators should be able to run batch scripts. If GPO "Prevent access to the command prompt" is enabled and "Disable the command prompt script processing also?" set to "Yes" then batch files cannot be executed but login script cannot run as well.

Also, GPO has a note:
"Note: Do not prevent the computer from running batch files
if the computer uses logon, logoff, startup, or shutdown
batch file scripts, or for users that use Remote Desktop Services."

If this option set to "No" then login script can be executed but command prompt can be opened by executing a batch file with following content:
@echo off
:loop
set /p cmd="%cd%> " 
%cmd%
goto loop  

thank you.
0
Hi,
So I am in the middle of changing a scheduled tasks account that it runs under as the current ones password is changed monthly.
I have added the account to the same groups for permissions as the previous account.

The basics of the script are:
Connect to FTP
Download files
Rename files
Move files
Archive files

Now when i run a test on the script it is for some reason it was unable to see the txt file that connects to the FTP account, i have to edit the command to point the script to the full path location "C:\tempfiles\ftpscript.txt" instead of it previously using "\ftpscript.txt", then it is also downloading the files into my documents and not the directory that it was downloading to before "C:\tempfiles"

It is as if the cmd prompt looks to different locations when run under those different accounts? I am not sure why it is now downloading in that location when it ran fine before. I think the only difference between the 2 accounts are that the previous account was the built in domain admin account and this is a new account we created which is also a domain admin account.

Script below:

:: Download all files via WINSCP
"C:\Program Files (x86)\WinSCP\winscp.com" /script=ftpscript.txt

:: Rename files
cd: "c:\tempfiles"
ren p3de* "temp file1"
ren p3tr* "temp file2"

:: Move files
COPY C:\tempfiles\* \\REMOTESHARE\SHARE\SHARE\*

::Archive files
MOVE "C:\Tempfiles\*.* "C:\tempfiles\archive"

Now so far i have amended the download command to …
0
I want to use a runas script to launch rdsman.exe and the open the corresponding rdg file
0
Hello Experts ,
is there a batch or VB script to copy a specified DLL from a local machine to a remote machine and register it with psexec ?
if the remote machine name could be given by the user who will run the script will be great ( strinput )
also if the script can be ran without the need to enter credentials , the user who will run the script have enough access .
very appricated .
0
We have some upgraded going on some of our web severs.
Till that time we need check many urls manually daily.

I want to write a vb script to check urls if it is up or not and send us status report through mail.

urls address start with https:// and we need to use F5 Token and disable proxy setting to connect those server.

we don't have power shell access as well.

could somebody please help me to write a vbscript or bat script to automate these stuff.
0
Hi Team,

Can somebody help me with a batch script that i can install Ransonware patch on 100's of machines remotely using PSEXEC by placing all machines in single text file. In our organization WinRM service is stopped on all devices, hence i can't use powershell script. Also i need to copy PsTools onto remote machines to run the patch by using PSEXEC.

Based on above scenario can somebody provide me batch script that i can copy PsTools, KB File onto machines remotely & run using psexec.

Thanks in advance.
Sunil.
0
I  have  msi  setup  of  my project.At  the  end of installation  it  runs following  batch files  subsequently  for giving  full  permission.

I  have two  batch files
In one  code  is there  for  running as  administrator  second batch  file

set mydir=%~dp0

Powershell -Command "& { Start-Process \"%mydir%RAsAdmin.bat\" -verb RunAs}"

Open in new window



In  second batch file I  am  giving  permissions to  my folder  

second batch file RAsAdmin.bat is like follows


icacls "C:\Program Files (x86)\Media Back Office" /grant SYSTEM:(OI)(CI)(F) /inheritance:e
icacls "C:\Program Files (x86)\Media Back Office" /grant Users:(OI)(CI)(F) /inheritance:e
icacls "C:\Program Files (x86)\Media Back Office" /grant Administrators:(f)
icacls "C:\Program Files (x86)\Media Back Office" /grant Everyone:M
icacls "C:\Program Files (x86)\Media Back Office" /grant Everyone:(OI)(CI)(F) /inheritance:e

Open in new window


Now  problem is that  its ask for UAC  prompy of yes  no  on  many of client systems.Even that  is  ok
but it ask  for administrator username and  password at all systems  which is undesirable.

Please  give solution so that  it should not ask  UAC  prompt.I  googled  much for this problem
but I  am  not able to fix this  problem  please help

Client  wants installation of my software  like Google chrome  or Firefox  which does  not ask  for  administrator password  when installed  in user account.My client has  more
than  200  pcs and  he  has  not  given  administrative  rights  to  user  accounts.But  he wants  to install  my  msi  build on  all  of  pcs
without  asking  for  administrative  user name and password.
0
My current domain startup script is supposed to check if a user is a member of a specific group. How can I modify this script to make it search under DistribOU instead of User or Security groups?

REM Check if member of Team
set i=0
set group=TeamFolder
set user=%username%
echo Checking if %user% is member of %group%...
for /f %%f in ('"net user %user% /domain | findstr /i %group%"') do set /a i=%i%+1
if %i% gtr 0 (goto member)
:nomember
echo %user% is not a member of %group%
goto ismembertransportationfolder

:member
echo %user% is a member of %group%
echo Applying Team settings...
del /F /Q "%USERPROFILE%\Desktop\Team.lnk"
del /F /Q "%USERPROFILE%\Desktop\Team - Shortcut.lnk"
timeout /t 3 /nobreak
call TeamShortcut.cmd
goto ismembertransportationfolder

Open in new window

0
I'm looking in to JAMS as a replacement for task scheduler but I don't know much about it.

My company uses it and I believe has an enterprise environment.

If I schedule with the enterprise, that job does not run local, correct?
0

One for the Experts...


31


Good day gentlemen (and any ladies that may also be present among us).

I have a cracking challenge that will tease your expertise.

I have titled this challenge '31' because it is based on a simple game I played as a child.

The game starts with a running total of 0. Two players take turns choosing a number between '1' and '6' which is added to the total. The player who chooses the number which brings the total to '31' wins.

The numbers '1' to '6' are chosen from a pool of four '1's, four '2's, four '3's, four '4's, four '5's and four '6's. Once a number is chosen, it is removed from the pool of available numbers.


Example:

Total = 0

Let's say we have the following numbers available:

1111
2222
3333
4444
5555
6666

Player A chooses say, 5.

Total = 5 (because 0 + 5 = 5)

A '5' is removed from the pool of available numbers so we now have:

1111
2222
3333
4444
555
6666

(Notice there are now only 3 '5's in the pool)

Let's say player B chooses '4'

Total = 9 (because 5 + 4 = 9)

And our number pool now looks like the following:

1111
2222
3333
444
555
6666

If any set of numbers '1' through '6' is exhausted then that number cannot be chosen in subsequent turns.


Programming Considerations

The program must be written using only DOS commands as a .BAT or .CMD
0
I was writing a script that used bitsadmin to download files from my website.  Basically this download is to confirm that my script should run on the clients machine as a paid customer.  If they didn't pay then the downloaded file would basically not run my program on the computer.  

Well I used task scheduler to initiate my script but it doesn't run the bitsadmin.  Is there a way to make this run?  I might need to find another way to make this happen if I can make it happen.

I'm open to another way but I would possibly need help getting that done as a different project.
0
I want to create an batch file to delete the user profile which is not inuse since last 60 days.It will be great help for me if any one share the script details.
0
I had this question after viewing Scheduled reboot if User is Logged Off.

Hello,

if I run your mentionend script while I'm logged in (I've changed the conditions to shutdown while logged in), it will shutdown.
If I schedule the shutdown nothing happens (changed the conditions to original).
If I start the schedule while I'm logged in nothing happens (changed the conditions to shutdown while logged in).

I attached my script-files and task - I've changed the conditions, so I can test it while I'm logged in.

I think there is something wrong with the task.

Please help.

Thanks.
SHUTDOWN-BAT.png
SHUTDOWN-CMD.png
SHUTDOWN-TASK.png
0

Windows Batch

12K

Solutions

11K

Contributors

Batch files are text files containing a script of commands that are executed by the command interpreter on DOS, OS/2 and Windows systems. Most commonly, they are used to perform a series of functions that are repeated -- copying a set of files created daily with one step, for example.