Windows Batch

11K

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

How to create a batch file to install an .exe file with administrative privilages?
0
Cloud Class® Course: Microsoft Office 2010
LVL 12
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

We are currently using a batch file that runs a 'mkdir' using a pre-defined variable and then calls another batch file to run a backup task, to supplement our existing tape backup for a short period of time.

setlocal enableextensions
set name=%DATE:/=_%
mkdir G:\Backup\%name%
call C:\FFSBackup.bat

Open in new window

This produces folder names in the format 20_06_2018

I would like to be able to have another scheduled task to delete historical directories - the above runs daily (Mon-Fri) through a scheduled task and I would like to be able to remove directories that are, for example, older than 5 days to manage space on the destination disk - a USB drive. Is there any way I can use the above date variable to achieve this?
0
Hello experts,

I am looking for a BAT files in order to list in a List.csv files, files, folders path and size.
First column: Path of File or Folder
Second column: report if the line reported in first column is a FILE or a FOLDER
Third column: size related to FILE or FOLDER

In the BAT file I should report the folder where are located the various files and folders to report in List.csv
BAT files should drill down the various subfolders.

If you have questions, please contact me.
0
I want to use a runas script to launch rdsman.exe and the open the corresponding rdg file
0
Need a batch script which will run with an inbuilt delay of 30 minutes when called. This is part of a one time start up process to deploy symantec as part of imaging process. On first login after 30 minutes this batch script should call an .exe which will run with administrator privileges on machine to deploy the Symantec AV

Thanks
0
Does anyone have a script or command line that I can use to install a software package remotely? I have an MSI file on the users machine in their C:\temp folder. I would like to run that remotely. I willing to try anything. VB script, powershell, psexec, bat or cmd.
0
Goal: a batch to delete certain words from a file and replace it with a few empty spaces

Below is a sample line in the input file...
|cffaaffaaTicket|r:|cffaaccff 3.|r |cff00ff00Creator|r:|cff00ccff Test|r |cff00ff00Created|r:|cff00ccff 10s ago|r 

Open in new window


Would need to delete "|cffaaffaa" "|r:|cffaaccff" "|r |cff00ff00" "|r:|cff00ccff" "|r |cff00ff00" "|r:|cff00ccff "

So in the end, it should look like this ideally...

Ticket 3   Creator Test   Created 10s ago   

Open in new window


This will be used in various input files, so that input example will change.  But I would like to simply edit the "text to remove" in the script.  
I tried several solutions I found online, they all either fail (maybe because of the pipe character) or are designed to delete the whole line of data not just the words

Thank you in advance
0
Dear Experts

Please can someone assist me. I would like to run a batch file on remote machines as an administrator. The batch file is located on a share that is accessible to everyone.

I am  trying to use psexec.

I am trying this but it doesnt seem to be working:

PS C:\Users\navishkars\Desktop\PSTools> .\PsExec.exe \\agent47-pc -u mydomain\admin-navishkars -p password cmd "\\dbnfiles\Software\DB2-ODBCClient\1_clidrivercopyandinstall.bat"
0
I am using 7-Zip to automatically backup a database directory from a batch file.

The command is something like:
C:\Program Files\7-Zip\7z.exe a "C:\MyDataFolder"

Open in new window

What switch can I add to automatically skip any files that may being modified at that time ?

I have searched and searched the net and can find no switch to do this !
0
I would like to use AD logon script to set persistent routes on selected PCs in our domain:
  ... some checks on the selected PCs (ie those with hostnames starting with ABC...) ..., then only execute commands below
  route del 0.0.0.0 mask 0.0.0.0  current_gateway
  route add -P 10.6.7.0 mask 255.255.255.0  new_gateway

Can it be done?

Understand the above command requires admin privilege & a colleague told me it will fail as domain
/AD users don't have admin rights.    To put it into GPO is too complex, so we want to put into user
logon scripts
0
Cloud Class® Course: Ruby Fundamentals
LVL 12
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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 a batch file that I'm using trying to:
1. Create local admin account, and place in the Administrator group.
2. Password must be set to never expire.
3. Need a description added to the account as "Local Admin"

The script I'm using is as follows:
setlocal
set NewAdmin=Tek
set NewPassword=Support@4777
set NewComment=Tekmanagement Support
echo Creating user account '%NewAdmin%' ...
net.exe user "%NewAdmin%" "%NewPassword%" /add /comment:"%NewComment%"
echo Adding '%NewAdmin%' to local administrators ...
net.exe localgroup Administrators "%NewAdmin%" /add
REM *** If the "wmic.exe" line is executed, it will disable the "Must change password" option ("/logonpasswordchg:YES" in "net user /add"), because these two are mutually exclusive.
echo Setting password of '%NewAdmin%' to never expire ...
wmic.exe useraccount WHERE "Name='%NewAdmin%'" SET PasswordExpires=FALSE


It creates the local account but does not add it to the administrators group.
The script says:
System error 1317 has occurred.
The specified account does not exist.
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
Hi,

I'm trying to get rid of local admin privileges for users. All users have a scheduled task that runs a Syncback backup of local files.
Works fine when user is admin, but when I remove local admin privileges, users are not able to schedule tasks.

Windows 10 client.1709. Domain member.
Group policy:  Computer Configuration\Windows Settings\Security Settings\Local Policies\User Rights Assignment.
Allow members of domain group Staff to Log on as a bath job.

Suggestions?

BR,

Nils
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
I have a bunch of files in a directory (with sub directories) with similar names except the last string of random numbers (randomnumbers_randomnumbers) will be the same and those will be the duplicates to each other.  I would like to keep the file version that is the oldest. (example rather keep last week version instead of todays version).

One file format will be randomword~randomnumbers~randomnumbers_randomnumbers.mp4/,jpg

helloworld~1548561505~1725485205568546231_1484516592.mp4

Open in new window


and the other file format will be

randomnumbesr_randomnumbers.mp4

1725485205568546231_1484516592.mp4

Open in new window



Their will be 1000's of files some duplicates, some not, some will have 2+ duplicates. I will like to keep only 1 version (the oldest version).
0
Free Tool: Subnet Calculator
LVL 12
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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
Hi All,

   I have used the following script in a text file "AVS-Weekly.txt".
option batch abort
option confirm off
echo off

open sftp://AVS_USER:aZZaWerP@1.1.4.131 -hostkey="ssh-rsa 1024 60:19:e6:8c:f3:0b:e8:73:90:47:bc:78:a2:ca:c3:c6"
option transfer binary

PUT  C:\AVS_USER\FTP_Files\Weekly\*.TXT  /app/AVS/Outbound/Production              
close
exit

Open in new window


Then a bat file is created with the below script.
"C:\Program Files (x86)\WinSCP\WinSCP.com" -script=C:\AVS_USER\FTP_Files\Weekly\AVS-Weekly.txt

Open in new window


When i double click the bat file, it is not uploading the file to the FTP location.
When i opened the bat file using the command editor, it says "session opened" and "session started", "active session", "session closed".

Can someone kindly help me with the fix?
0
I've been tasked with finding a backup solution for Yammer (Office 365), and thought it was "job done" when I found this article:

https://developer.yammer.com/v1.0/docs/data-export-api

Towards the end of the article there is a Windows batch script you can run in order to do the backup:

@ECHO OFF

    IF [%1]==[ ] (
      IF [%2]==[ ](
        ECHO "Usage: export.cdm <OAuth Access Token> <Directory>"
        EXIT /B
      )
    )

    :: Your Yammer Oauth 2 Access Token. This must be a token for a verified admin account. 
    SET AT=%1

    :: Download location for the export files.
    SET DIR=%2
    cd %DIR%

    :: Find the last export of there is one. The start date and time of the previous export is encoced in the filename 
    SET LAST_EXPORT=0
    IF EXIST export-*.zip (
      FOR /f "delims=" %%a in ('dir /B /D export-*.zip') do(
        :: Use the timestamp from the most recent file
        SET LAST_EXPORT=%%a
      )
    )

    :: Remove the relevant parts of the filename so the timestamp can be stored 
    SET LAST_EXPORT=%LAST_EXPORT:export-=%
    SET LAST_EXPORT=%LAST_EXPORT:.zip=%
    :: Don't foget the replace the underscore with the colons to ensure correct ISO-8601 formatting
    SET LAST_EXPORT=%LAST_EXPORT:_=:%

    :: Calculate the current date in UNIX time for the filename of the export.
    SET TIME_STAMP=%time:~0,2%:%time:~3,2%:%time:~6,2%z
    SET NEXT_EXPORT=%date:~10,4%-%date:~4,2%-%date:~7,2%T%TIME_STAMP%
    :: Make sure to replace 

Open in new window

0

Windows Batch

11K

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.