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

I am attempting to run powershell.exe from within a batch file to add registry entries to the logged on HKCU using the Administrator account.  The following works from the command prompt:

PowerShell.exe -File "%cd%\WriteToHkcuFromSystem.ps1" -RegFile "%cd%\PhishHookLocalUser.reg" –CurrentUser
PowerShell.exe -File "%cd%\WriteToHkcuFromSystem.ps1" -RegFile "%cd%\PhishHookLocalUserOrgInfo.reg" –CurrentUser

When I run the exact same commands using a batch file I get the following error messages:

D:\PhishHook\PhishHook_2.0.0.0\WriteToHkcuFromSystem.ps1 : A positional parameter cannot be found that accepts argument
'ΓÇôCurrentUser'.
    + CategoryInfo          : InvalidArgument: (:) [WriteToHkcuFromSystem.ps1], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : PositionalParameterNotFound,WriteToHkcuFromSystem.ps1

D:\PhishHook\PhishHook_2.0.0.0\WriteToHkcuFromSystem.ps1 : A positional parameter cannot be found that accepts argument
'ΓÇôCurrentUser'.
    + CategoryInfo          : InvalidArgument: (:) [WriteToHkcuFromSystem.ps1], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : PositionalParameterNotFound,WriteToHkcuFromSystem.ps1

I've been Googling all day and I have found nothing but over complicated code that is messy and confusing.  It would be a great help if someone can tell me how to run powershell.exe and give it a variable that means current directory without making any changes to the .ps1 files.

Any help would be …
0
I have a windows batch script that I would like to run as a Windows Service
(non-interactively ie it's running even before user login to Windows) &
this Service should check if it's down/not running & then auto-start
(auto-start when Windows boots up but also auto-start when the
 service is down/not running).

User must not be able to set this service to shut down or Disabled or
Manual;  only local administrator or domain admin can be allowed to
do this.  I'm running on Win 7 & Win 10.

Appreciate a step by step instruction, thanks.
0
We currently use Checkpoint VPN client on our Win7 & Win10 laptops
for about 300 laptops to connect back to office:

this client will auto pops up when it detected Internet, prompting for
2FA.  Is there any way to prevent our users from accessing Internet
unless :

a) they're on our corporate network   OR
b) if they are connected to outside (or their home Internet/Wifi),
    they can't access Internet till they've connected to this Checkpoint
    VPN (which connects to our Checkpoint blade).

Don't plan to use "Always-On VPN" yet as some of our laptops will
still be on Win 7 till end of 2020 (yes, it's beyond the MS EoSL date
but we're applying virtual patches in place of MS patches).

A batch script that detects which network is connected (if it's
Corporate network) that would alter the routing table etc will
be good.

No Powershell script as we've removed PowerShell from users'
laptops
0
I currently use an fping command in a batch file that writes all output to a text file. I want to tweak it to write only errors such as no responses or request time outs. Here is my current batch command.

fping 8.8.8.8 -T -c -L ping_google.txt
0
Hello Gents.  

Can anyone provide me with a quick batch script I can use to remotely deploy Office 2016 to a couple machines.   I am using Datto's RMM tool to do so.   The path location is located here..

\\SERVERNAME\Data\Software & Drivers\Microsoft Office 2016  (I have the correct server name I just put SERVERNAME for security)

I tried to use this script..

@echo off

setlocal

::Store working directory to return after finished
set WORKDIR=%CD%

::Map and switch to a network drive and give it unmapped drive letter
pushd \\SERVER\Data\Software & Drivers\Microsoft Office 2016

::Store the name of the network drive so it can be unmapped when finished
Set NETDRIVE=%CD%
set NETDRIVE=%NETDRIVE:\=%

::Change back to the original directory
cd /d %WORKDIR%

::Run commands with the network drive mapped
%NETDRIVE%\setup.exe /configure

::Uncomment this to catch errors from the executable
::if %errorlevel% GTR o exit %errorlevel%

::Unmap the network drive
net use %NETDRIVE% /delete /y

endlocal

Open in new window


However the STDERR returned the following


The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The network connection could not be found.

More help is available by typing NET HELPMSG 2250.



I am wondering if some of the variables in that batch script need to be changed.

I just need a script to deploy the job to point to that folder location where the setup.exe is and run silent.   Appreciate the assistance as always
0
For interactive AD accounts, we can find out the "Last logon" date/time
by issuing  "net user /domain  AD_Id  | find "Last logon" " : a non-admin
user can do this.

For non-interactive/service AD accounts, how can a non-admin user
find out when it's last used?   We are doing a review of the hundred
over non-interactive accounts to see if they're truly needed.

Can't ask the owner as the documentation/record of who requested or
own these non-interactive/service account is lacking.
0
Hello experts,
I would like to know to check which are the various windows shortcut set up in my computer.
Can I do it with a powershell or a windows batch command?
Thank you in advance for your help.
0
Hello,
My Goal is to perform a BULK  PTR Record Import without creating A records.

The author of this article gave good information but its not working for me at least.
http://kpytko.pl/dns/dns-bulk-ptr-records-creation/

for /f "tokens=1-2" %i in (c:newPTR.txt) do dnscmd %LOGONSERVER% /RecordAdd 30.168.192.in-addr.arpa %i PTR %j

Can anyone replicate this using DNSCMD and loop through a file called newPTR.txt
0
Hello experts,
I have multiple csv file in a root folder.
I am looking for a script that allows me to replace string based on specific column
-The script should contain strCol = (numeric or a letter), strSourcestring = (value to look up) strTargetcestring = (Value to replace)
-Header row shouldn't be replaced. The replacement should start as of row 2
-Csv delimiter is ";"

If possible:
-Be able to report multiple strCol values
-Have a strFlag to avoid strCol and appy the procedure for all columns

-Windows batch & powershell approach are more than welcome
Thank you in advance for your help.
1
Hello experts,
I have the following xml file (dummy file) in input folder.
I am looking for a vbscript & windows batch & powershell to generate the attached csv file in output folder.
How should I proceed?
If you have questions, please don’t hesitate to contact me.
Thank you in advance for your help.
export.xml
dummy-file-export.csv
0
Hello experts,
I have the following csv file (dummy file) in input folder.
I am looking for a vbscript & windows batch to generate the attached xml file in output folder.
How should I proceed?
If you have questions, please don’t hesitate to contact me.
Thank you in advance for your help.
dummy-file-export.xlsx
export.xml
0
Some links say the Wallpaper are stored in following location:
C:\WINDOWS\Web\Wallpaper\...\*.jpg

But in my office's Win7 & Win10 PCs, seems like every few days
the image on the desktop (when screen is locked, prior to login
as well as the desktop) appears to be changing every few days.

We want to publish or 'push' into users PCs centrally  educational
posters (for IT Security awareness) on their desktop (ie while they're
logged into Windows, screen is locked or prior to login) such that
Windows can't  "rotate or change" these wallpapers.

How can we do it centrally?

As the local admin password is common across all PCs, I thought
of looping thru all PCs using script below from the sysadmin PC:
  while PC_hostname do
     net use x: \\PC_hostname\C$  /user:localhost\administrator theAdminPassword
     copy c:\AdminPC\Educational.jpg   x::\WINDOWS\Web\Wallpaper\...<pls advise>
     net use x: /d
  end while loop

Kindly provide script above or step-by-step instructions for any other easier ways
0
I have a customer that needs to copy the same file to the same destination (manually) every once in a while. He is not too computer savvy. I need a real simple GUI copy program that I can set and save the Source and Destination so all he has to do is double click on it, click "start" and see the results. I tried Rich Copy. It won't let you save source or destination. Need something simple.
0
How can I pause for 3 seconds between these two lines of code?

DoCmd.OutputTo acOutputTable, "Data2", acFormatXLS, "C:\AmazonFeeds\Data2Export" & "\Data2-" & SuppID & ".xls", False


DoCmd.TransferText acExportDelim, "Data2SmallExportSpecification", "Data2", "C:\AmazonFeeds\production\outgoing\Flat.File.PriceInventory.us-" & SuppID & ".txt", True, ""
0
Hello experts,
I have a bunch of csv files located in C:\csv
I need to make sure that column I & M have the YYYYMMDD value. The rest of values will remain the same.
The idea is to have script  which reads the various files  in C:\csv, generates revised version of files as specified in previous point (YYYYMMDD value for column I & M)  in C:\out .
Columns involved by the change I & M should be related to a variable.
I attached dummy file.
If you have questions, please contact me.
Thank you in advance for your help.
0
Hello experts,
I have the following modules attached which I used in my personal Add-in.
I have a mapping table to follow up the various sub procedures.
I would like to set up a script in order to.
Generate a csv by .bas in a yyyyymmdd_hhmm folder and report in column A the sub procedure name and in column B the name of .bas file name information should be reported in ascending order
I attached .bas files.
Example:
Sub procedure name 1;Bas name
Sub procedure name 2;Bas name
Sub procedure name 3;Bas name

If you have questions, please contact me.
g2bRangesFormulas.bas
g1aStringsFormulas.bas
0
Hello experts,
I have A C:\Folder which contains multiple subfolders such as conf, lib, input, out, logs exports, etc.
I would like to launch robocopy command and exclude files of specific subfolders such as logs and out. The difficult part is that I need to exclude files of specific subfolders but keep the folder empty.
My attempt is.
 Robocopy C\Folder C:\Destionation /e /xf *.* 

Open in new window

The problem with this is that I exclude all files.
What I need is to exclude all files of specific folders and keep the folder involved empty.
If you have questions please contact me.
Thank you very much for your help.
0
Hello experts,
I have the following command
Del C:\folder \*.csv* C:\folder2\*log.* /q /s 

Open in new window

I would like to exclude of the delete operation a specific file with the following name mapping.csv
If you have questions, please contact me.
Thank you.
0
After using the used Ideapad S10-3 a few times, it kept
updating Win 7 updates with message:
"Failure configuring Windows updates
    Reverting Changes
  Do not turn off yr computer"

When I boot up in "Safe Mode", got the above message
too & sometimes it will go thru into "Safe Mode" windows,
just that I can't locate in Control Panel "System & Security"
but only "System" : don't see any option to disable
Windows auto-update.

Is there any way to disable it at command prompt or
where did I miss?
0
Hello experts,
I have various csv files in a specific folder I would like to:
-Replace the value 05 by 06 in column C
-Script should have SourceString TargetString.
I attached dummy file.
Windows batch, Powershell, VBscript and MS VBA approaches are more than welcome.
If you have questions, please contact me.
Thank you.
Dummy-file.csv
0
Is there a way to execute Powershell 'as administrator' from command line?  When I open a command window on the Server and select 'Run As Administrator' then run my main script that then calls this script it works great.  If I try and schedule the main script in Task Scheduler this part doesn't run.  Thus was thinking a permissions issue.  Not really sure as nothing writes to my log file......

@echo off

if not exist %ARCHIVEDIR%\PBCS\Backups\%Timestamp% mkdir %ARCHIVEDIR%\PBCS\Backups\%Timestamp%

setlocal
set Source=%FILEDIR%\Backup_Data\%AppName%\%AppName%_FY*_Export_SUI.txt
set Target=%ARCHIVEDIR%\PBCS\Backups\%Timestamp%\%AppName%_Data.zip
powershell.exe -Command "Get-ChildItem '%Source%' | Compress-Archive -DestinationPath '%Target%' -Force"


exit /b

Open in new window

1
OS: Windows 2008
An indefinite batch script running back ground from task Scheduler on the server .. want to bring cosnsole it being run to foreground.

Advise how this we can make possible
0
Hello,
I am tried to copy folder structure from folder a to folder b exlcuding all files.
I don't understand why files are copied with the following command:
robocopy folder a folder b /e xf *.*

Open in new window

Thank you
1
I'll need a command/script that will list out what's installed in
the corporate's PCs & save outputs to a shared folder.

"wmic product show ..."  won't even show Chrome, Firefox, plug-in
while 'psinfo -accepteula -s' shows Chrome, FFox but not plug-ins
(eg: Zoom, Webex, browsers' plug-ins) & Java 8 Upd ...

"program features" will show plug-ins, Java, Chrome, FFox etc
but it's in GUI so can its output be extracted out by script?
0
Hello experts,
I am trying to list in 3 commands:
-All full path subfolders (immediate subfolders) on a folder
-All full path files on a folder
-All full path files and (immediate subfolders) on a folder

Drill down not required.
command should output a list.txt in %cd% folder

I tried  for second requirement this:
for /d %%a in ("%CD%\*") do echo %%~fa

Open in new window

but it doesn't work.

Batch and Powershell approaches are more than welcome.

Thank you in advance for your help.
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.