Windows Task Scheduler wont run ren command, but cmd.exe will - windows

I am creating a task that executes a batch file for ftp uploads.
The batch script just renames any file in a certain folder to an appropriate name, then uploads that folder.
I have set the task to run under a service account, when I log in with the service account and run the .bat file it works perfectly. When I run the task scheduler it runs the .bat file but the log shows that the ren command doesn't work.
Here is the output from the log after being invoked via task scheduler:
c:\TEMP\Bulletin>rename "R:\x\x\x\*.pdf" Bulletin.pdf
c:\TEMP\Bulletin>chdir c:\Program Files (x86)\WinSCP
c:\Program Files (x86)\WinSCP>WinSCP.com /ini=nul /script=c:\TEMP\Bulletin\bulletin.tmp
Searching for host...
Connecting to host...
Authenticating...
Using username "svc-bulletin".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Session started.
Active session: [1] svc-bulletin#x.x.x
File or folder 'C:\FileShares\Drive-R\x\x\x\Bulletin.pdf' does not exist.
System Error. Code: 2.
The system cannot find the file specified
(A)bort, (R)etry, (S)kip, Ski(p) all: Abort
c:\Program Files (x86)\WinSCP>exit
Here is the output from just manually invoking the .bat file:
C:\TEMP\Bulletin>rename "R:\x\x\x\*.pdf" Bulletin.pdf
C:\TEMP\Bulletin>chdir c:\Program Files (x86)\WinSCP
c:\Program Files (x86)\WinSCP>WinSCP.com /ini=nul /script=c:\TEMP\Bulletin\bulletin.tmp
Searching for host...
Connecting to host...
Authenticating...
Using username "svc-bulletin".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Session started.
Active session: [1] svc-bulletin#x.x.x
C:\FileShares\Drive-R\x\x\x\Bulletin.pdf | 957 KB | 1390.5 KB/s | binary | 100%
c:\Program Files (x86)\WinSCP>exit
I am running the task with full permissions and have also tried starting it in the same directory as the .bat and without, neither works. Appreciate any pointers/ideas.

I'm, assuming R: is a mapped drive. Mapped drives are established when a user logs on as they are only mapped for the user that did the mapping. The service account doesn't know anything about mapped drives that are mapped under your account. To complicate the issue the task may be running under S4U authentication depending on your task settings so you won't have access to network resources. That also eliminates using a UNC rather than a mapped drive. See technet.microsoft.com/en-us/library/cc722152(v=ws.11).aspx

Related

How to run a batch file in a remote machine from the Teamcity

I am building a C# project and deployed the package using Teamcity.
I have added a step in the build configuration that I need to execute a batch file present in the remote machine.
The batch file is copied to the remote machine along with the deployed package.
I am getting the error "The system cannot find the path specified."
If you are directly entering the path of the batch file, it will look for the same path on teamcity server and not on the remote machine.
you would have to install psexec on team city machine. See https://learn.microsoft.com/en-us/sysinternals/downloads/psexec
This command will help you to execute the script on remote machine
Now create a Command line step like this
and then in custom script use following :-
psexec \10.0.111.111 -d -accepteula -u domainname\userid -p password cmd.exe "Path/To/BatchFile.bat"
Here 10.0.111.111 is the ip adress of remote machine(Can use hostname as well).
domainname\userid is domain name and user id used to login the remote machine.
password is the password used to login remote machine.
Path/To/BatchFile.bat is the path to the batch file.

Windows 10 - How can I fix - C:\ Ace entries not in canonical order

I have run into an issue with my windows backup software that I believe is due to an issue with permissions on my C:\ drive. I am using cygwin which can cause issues.
The problem manifests itself by the Veritas SRS software not being able to snapshot the C:\ drive due to issues with VSS.
When attempting to run a utility that diagnoses and fixes issues with VSS (vss-doctor by Acronis), it indicates that the SYSTEM account does not have Full Control access to C:\
When I try to run the fix, the utility complains that that the access control list is not in canonical order. I can confirm this by running:
C:\>icacls C:\ /verify
C:\: Ace entries not in canonical order.
Successfully processed 0 files; Failed processing 0 files
When I try to reset, I receive this error (I am running the command prompt in Administrator mode):
C:\>icacls C:\ /reset
C:\: Access is denied.
Successfully processed 0 files; Failed processing 1 files
What can I do to correct this problem?

Run FORMAT command from task scheduler

I'm trying to get a scheduled Format running on Win10.
I have a Batch File that consists of the following line:
Format F: /V:test /Q /FS:NTFS /A:4096
Starting the Batch manually Formats the drive as desired, but starting the Batch as a Scheduled Task gives me an error:
cannot open volume for direct access.
I did a lot of Google Research but nobody seems to have found a solution or hasn't shared one.
I already did try/ensured the following things:
The Task runs with highest privileges
The user has admin rights and full Control over the Folder
I tried running it from SYSTEM - didn't work
The Task is configured for Win10 and running only as user is logged on

Transfer files from one server to another using batch script

I have certain files in a folder on my local machine (Windows 8) and I want to transfer them to a remote server (Windows server 2012 R2) using a batch script.
Shown below is the script that I am trying to run but it throws an Invalid drive specification error. Note: I am sure that there is a folder called test in the specified location.
map.bat
xcopy /-y C:\Users\ssubburathinam\Documents\map1\*.* \\192.168.1.11\C:\Users\ssubburathinam\Desktop\test\ /d /c /y
pause
Screenshot of error
I do not know where to put my login credentials in this script as the remote server has login enabled. How can I accomplish this?
I recommend you to use the "Add a network location" in the main computer, so you can see a new drive letter with the network location. For your try, it might be wrong the share name on the remote computer, if you share a folder, usually is called by:
\\IP_or_name_of_the_remote_server\shared_name

Automating an installation using BAT/PS scripts

I have been attempting to automate the installation of one of my applications but have run into a few roadblocks and I really need some help.
Currently we are using Dell's KACE technology to push the installer to the local machines. The installer is run as the SYSTEM user meaning it does not and can not have direct access to network shares (relevant later).
The application installation workflow is as follows:
Stop Local Security Services to allow software install
Remove anything mapped to drive letter X
Map network drive X \test\test
TestApp.exe /s
msiexec /i Test.msi /quiet
Start Local Security Services to allow software install
copy shortcut file to desktop
The installation itself has 1 Executable and 1 MSI that have to be run. The EXE installs a mainframe application. The MSI file installs a few files locally and then registers 6 DLL files located on that mapped drive.
This is where the issue comes in - Because those files MUST be on that share drive and the installer is running as SYSTEM -> The System account account can't access the mapped drive to register the files so the installation fails.
I am further limited by the fact that I can't simply store a username/password in plaintext in the batch file.
Here is my code so far:
REM Stopping McAfee Services
echo Stopping McAfee Services.
net stop mcshield
net stop mcafeeframework
REM Map Network Drive
echo Mapping Network Drive
net use X: /delete /y
net use X: \\test\test
(Here is where I need help - Is there a way to force a username/password prompt here for the user? I basically just want the user to authenticate to the X drive mapping, which will allow the installation to move forward)
echo Starting Test 1 Installation
Test1.exe /s /v"/qb"
echo Starting Test 2 Installation
msiexec /i Test2.msi /quiet
(If the drive has not been mapped by this point, the installation fails as the SYSTEM account can't access the drive)
echo.
REM Restarting Mcafee Services
echo Starting McAfee Services.
net start mcshield
net start mcafeeframework
echo.
REM Copy Shortcut
xcopy "shortcut\*" "C:\Users\public\desktop"
Alternatively,
Could/should I convert this to a PS script? I know PS is more powerful than batch, but wasn't sure how to go about it.
If by forcing authentication prompt, you mean something that will need human input (and you aren't running this script remotely), then this line should interact with existing login session and ask for credentials:
start explorer \\test\test
echo After you have entered network credentials
pause
Once user enters valid ones, the remaining script can continue
net use X: \\test\test
After toying with ideas about this problem for a couple of weeks I decided to take a new approach.
I created a new batch file using a simple NET USE and passed the credentials of a service account w/ access to the network share in plain text. Next, I compiled the batch into an executable. It's not the most elegant solution out there I'm sure, but it's sufficient for our needs currently.
Thanks for the help everyone!

Resources