Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x

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

I will have several files during the day. Cannot select the latest with timestamp, i need to have to file with the greatest id.

The file name is in a format: [standardname]_[date]_[id].csv. Eg invoices_2017_09_19_186.csv
0
[Webinar] Lessons on Recovering from Petya
LVL 10
[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

I am trying to deploy Intune to all the computers in my company.  Unfortunately, MS requires the user to be a local admin to join Intune.  These are all AD Domain Joined.  I am looking for a way to give the logged in user local admin rights, have them connect to Intune with their username and password and then remove them from the local admin group.  So far I have this for my script:

Net localgroup administrators “domain\%username%” /add
Start ms-device-enrollment:?mode=mdm
Timeout 300
Net localgroup administrators “domain\%username%” /delete

It works fine if a domain admin right clicks and runs the batch file as administrator.  I would like it run as a logon script one time.  I also tried to copy the file to common startup folder so it would run at logon, but get access denied on the first line.  The rest of the script runs without error.  Has anyone had success joining computers to Intune without manually making users local admins?
0
There are a few PC's on my network that have unknown versions of CCLEANER on them.  CCLEANER doesn't update automatically so they would have whatever version that was current at the time.  Since CCLEANER now is being bundled with MALWARE, I need to just remove it from my network.  Looking for a script that I can add to my login scripts, or even a command line that I can run remotely to remove any and all versions on a PC, or preferably  the entire network.  

Thanks in advance.
0
I need help. How to create batch file to import value from text file and write it to registery during osd.
I want to add key  in hkl\software\syswow64\me\  the value would be jack,  help would be appreciated.
thanks
0
Example Folder Structure

>Share

>>Department 1
>>>Job Title 1
>>>>Subfolder 1
>>>>Text.txt

>>>Job Title 2
>>>>Subfolder 1
>>>>Text.txt

>>Department 2
>>>Job Title 1
>>>>Subfolder 1
>>>>Text.txt

>>>Job Title 2
>>>>Subfolder 1
>>>>Text.txt

I want the batch file to go through all the job title folders and delete everything in them including sub folders. Without deleting the Department and Job title folders.
0
I should be able to do this but I think the brain has had enough for the day :~(


I have a file in the following format (already containing the values):

Server=\\servername\sharepath
Username=server\user
Password=passwdval

I need to read the values and insert those values into the following file (as shown below):


<SHARE>\\servername\sharepath</SHARE>
<DOMAIN>server</DOMAIN>
<USER>user</USER>
<UPWD>passwdval</UPWD>


This HAS to be done with a cmd file.
0
Hello EE,

I have the following script that I am running and it pulls up a command window, but I cannot get the command window to close.  I thought Exit would work, but it is not.  Neither is close.

@echo off
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
 /log="C:\Users\xxxxxxxxxxxxxxxx\Desktop\WinSCP.log" /ini=nul ^
  /command ^
    "open sftp://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/ -hostkey=""ssh-rsa 2048 9e:c2:dd:6d:86:a6:30:56:9d:ea:99:de:ff:c3:5f:2d"" -rawsettings FSProtocol=2 ProxyMethod=3 ProxyHost=""xxxxxxxxxxxxxxxxxxxxxx"" ProxyPort=xxxxxxxxxxx ProxyUsername=""xxxxxxxxxxxxxx"" ProxyPassword=""xxxxxxxxxxxxxxx""" ^
    "synchronize local T: /outbound/xxxxxxxxxx"
    "exit"

set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)

exit /b %WINSCP_RESULT%
0
Hi Experts,

Good Day..

As per my Work,  I have to move files from one sever to another server using  batch Script. I am able to perform this task. Screenshot of the same is attached below
move /y "\\ServerA\F$\Folder 1\*.zip" "\\ServerB\F$\Folder 3"

Open in new window


.But After this, I need to validate whether moving files is fine or not. If any error occurs (because of network issue or something ) , then need to perform moving task again..

SO how can I do this task ?  How can we capture errors? Can I use IF command ? Any help regarding this would be highly appreciated.

Thanks in Advance...
0
I'm writing a batch file that needs to read In a text file with multiple lines (2-3 or more) and assign them to variables (i.e. Line1, Line2, Line3).  which will then act on those to run jobs based on the variables read in.  What is the easiest way to do this preferably without for loops or delims. etc.

Thx,
Brian
0
Hello All,

Requirement:
Need to run Exe file which run for some seconds(2-3) and save output of Exe file at desired location.

Concern:
We are able to execute exe  file but we are getting 0 Kb output file.
We are getting output file but there is NO data in output file.
are we missing something here !

Command used:

Start F "\Program Files\location1\"xyz.exe > "F:\Program Files\location2\abc.txt"
0
Important Lessons on Recovering from Petya
LVL 10
Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Hi Experts, I need to add a delay within a batch file so that it starts after 2 minutes. This batch script runs as part of first login when imaging machines and I call the batch file by specifying this command within software we are using to image machines. The OS is Windows 10 Enterprise:

C:\Apps\AnyConnect\Regimport.bat

The first part of script calls an elevated prompt, the next part after ECHO runs the actual command

::::::::::::::::::::::::::::::::::::::::::::
:: Automatically check & get admin rights V2
::::::::::::::::::::::::::::::::::::::::::::
@echo off
CLS
ECHO.
ECHO =============================
ECHO Running Admin shell
ECHO =============================

:init
setlocal DisableDelayedExpansion
set "batchPath=%~0"
for %%k in (%0) do set batchName=%%~nk
set "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs"
setlocal EnableDelayedExpansion

:checkPrivileges
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )

:getPrivileges
if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
ECHO.
ECHO **************************************
ECHO Invoking UAC for Privilege Escalation
ECHO **************************************

ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
ECHO args = "ELEV " >> "%vbsGetPrivileges%"
ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
ECHO args = args ^& strArg ^& " "  >> "%vbsGetPrivileges%"
ECHO …
0
how to copy the letters from pictures into text,see the 2 pic. (i have 10.000 ) :

Save the name from that pictures to a text file,like this,is possbiel?

Output.txt content:
Johanna
DANIEL

Open in new window


thank you!
pic1.jpg
pic2.bmp
0
How to call an oracle function written in a package via Batch file?
0
I'm trying to create a batch file that will continue after two known error messages to look for unknown errors in a windows batch file on Windows Sever Enterprise Edition.  If the known errors are found, continue but action on anything found thereafter.  What is the easiest way to do this?

Thx,
Brian
0
HI,

I have an ERP and its use windows local users authentication and i need a script to prompt users to change their password when password soon to expire as i configure on local security policy.
0
Dear,
In order to be used by a GPO, I would like to be assisted to create a script with take as input unc name with subfolders \\servername\Office Templates (on a server) and as output a pathnname on a workstation %public%\Office Templates

I'am currently learning powershell but my knowledge is not yet sufficient to be efficient.
any help is welcome.

tks
0
I have looked through other posts with similar issue, but none of the solutions resolved mine. I have the following ONLY command to install a printer driver, nothing else besides Pause and Exit.

cscript %WINDIR%\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -a -m "HP LaserJet P2035n" -h "C:\HP LaserJet P2035n" -i "C:\HP LaserJet P2035n\HP2030.INF"

The driver name is correct and the location exists. I tried the following to see if it would work as others suggested:
1. Used double back slashes \\ in paths for -h and -i attributes
2. Added -v 3 -e "Windows x64" parameters

All systems are Windows 7 x64. I'm just baffled on how this script is not working, even locally. Can someone take a look and tell me why this script keeps failing? Script contains no typos or extra spaces. Copy and pasted as is.

Thank you!
0
Call a Batch File  based on Event - is this possible in XP., not having much luck.  I know it is available in W7 & up.  Any help would be great.
0
I want to write a batch file that I can distribute to users that will map their sharepoint secure folder, have the UNC that will prompt them for logon name and password for sharepoint when run and when the cookie times out and the connection drops they can simply click the batch file and remap

net use i: /delete
net use i: "\\XXX.sharepoint.com@SSL/DavWWWRoot/sites/Commercial/Team Secure/" USER:email address * /PERSISTENT:YES

No domain, sharepoint online
* dont want to store password, want to prompt


Any help appreciated

John
0
Free Tool: Subnet Calculator
LVL 10
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.

hi team

we require a script which will copy the reg file to remote servers and add it in registry.

we are implementing wsus. we don't want to use the GP. so we would like to add the reg key in our servers. please help to provide a nice script.
0
I have a folder A on 10 window machines located on  C drive folder temp which contains .cmd file for execution , I want to execute that .cmd file on all 10 windows machines from one machine using batch file. which should run in highest permission with run as administrator & UAC should not block when script executed.

Thanks in advance
0
Hi all...

I've tried finding what I need but most solutions offer various entries and switches on a vbs script or batch file.

I need to delete one single registry key if it is present. The key is as an example:

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Network Associates\ePolicy Orchestrator\Application Plugins\DATALOSS1000

How can I accomplish this, and run it remotely on approximately 300 systems?

Batch file preferred...

Thanks in advance...
0
batch script help with exit when finds a specific error( e.g:
TIMEOUT error

Open in new window

) ,exit means close the process
0
How do I check this. Have already written a command in SQL SERVER JOB [Test_Job] and executing the job in Sql Server, **Have disable the Informatica service through Informatica Admin panel**, when I execute this job I don't know why It is still running successfully and cannot generate a failure mail.

This is the command which I have put in a job.

    DECLARE @result int
    EXEC @result = xp_cmdshell "D:\Informatica\Informatica_961_HotFix2_Installation\server\bin\infacmd ping -dg HERHRETEST:1000"
    IF (@result <> 0)
        RAISERROR (50001, -1, -1)

Please help at the earliest
0
I need a batch command to stop the process and exit immediately when it finds this error:
connection error

Open in new window

the batch works with a certain tool and these are some benchmarks if they help something
The script I own closes the process in these situations and I want someone to help me add a new situation


:: Controll stopping
:: (1=enable,0=disable;)

Open in new window


:: Error exit codes
SET /A ERROR_UNKNOWN=-1
SET /A ERROR_OK=0
SET /A ERROR_NO_BOOKMARK_FOUND=1
SET /A ERROR_NO_MORE_DICTS=2
SET /A ERROR_FINDSTR_UNKNOWN_EXIT_CODE=3

Open in new window


and

1'st exit situation:
:: Check if the file exists
IF NOT EXIST "%filep%" (
	ECHO File "%filep%" was not found. Assuming we ran out.
	ECHO We did not find.
	SET /A errno=%ERROR_NO_MORE_DICTS%
	GOTO END
)

Open in new window


Another exit situation:

) ELSE (
	:: tool did not run ok. No ideea why. The multitude of checks should have
	:: prevented this.
	ECHO %tool% exited with non-zero exit code. No ideea why. Contact dev.
	SET /A errno=%ERROR_UNKNOWN%
	GOTO END
)

Open in new window


The 3'rd situation:

:: Call command
%composedcmd%

:: Check if we ran ok
IF /I "%ERRORLEVEL%" EQU "%ERROR_OK%" (
	:: Check if we found mamammia
	FIND "Discovered mamammia" "%tooloutfile%" >NUL 2>&1 && (
		ECHO mamammia.
		GOTO END

Open in new window



I want to add new exit,so when finds this error EXIT:
connection error

Open in new window


THANK YOU!
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.