Using SSIS execute process task to run a batch file - batch-file

I was tasked to execute a batch file using SSIS "execute process task".
FYI,The batch file(named test.bat) uses PsExec command to call a runthisboy.bat file on a remote webserver to refresh the appPool. Here is what I wrote in the test.bat:
psexec -d -i -s \\webserver1 -u domainName\myID -p myPassword "C:\Documents\runthisboy.bat"
After I run the SSIS package, there is an error message shows up:
[Execute Process Task] Error: In Executing "C:\Windows\System32\cmd.exe" "/c C:\Users\myName\Desktop\test.bat" at "", The process exit code was "1" while the expected was "0".
But if I use this SSIS package to run other .bat file, like:
xcopy /d /y "C:\Users\myName\Desktop\sample.txt" "C:\documents"
It runs without any problems.
If anyone can give me some clue about what is happening here, I will be so thankful!

Related

dtutil import ssis package from remote

I am trying to import an ssis package (.dtsx) from one server to another remotely but I face a strange issue. (dtsx is on Server-02 and need to be imported on Server-01)
Let me explain with 3 commands :
Running on Server-01
osql -E -h -Q "select name from [msdb].[dbo].[sysssispackages] where name like '%MIC%'"
This returns nothing, my package is not imported yet, that's ok.
I have a .bat file on Server-01 which contains the following command :
"C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\dtutil.exe" /FILE \\Server-02\D$\BAM_DM_IBZMICVU001.DTSX /COPY SQL;BAM_DM_IBZMICVU001 /QUIET
DTSX is located in D:\ on Server-02, .bat file is located in D:\ on Server-01.
This bat file must be run in order to import the ssis package.
Then running on Server-02
WMIC /NODE:"Server-01" process call create "cmd.exe /A /C D:\\BAM_DM_IBZMICVU001.bat"
It returns successful state. But then when I run again on Server-01 my osql command, it still returns 0 result. It seems the package hasn't been imported...
We could think that the bat file isn't working but if I run the bat file directly by double clic on Server-01, it also runs successfuly. Then I do the osql select, it returns 1 result, the package has been imported successfuly.
At this moment, I thought that the bat script was simply not executed remotely. So I changed it a little.
echo "C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\dtutil.exe" /FILE \\Server-02\D$\BAM_DM_IBZMICVU001.DTSX /COPY SQL;BAM_DM_IBZMICVU001 /QUIET > D:\debug.txt
Then from Server-02
WMIC /NODE:"Server-01" process call create "cmd.exe /A /C D:\\BAM_DM_IBZMICVU001.bat"
D:\debug.txt has been successfuly created on Server-01 which means the bat script also executed well...
Any idea of what could happen in my case ?

How do I execute cmd commands through a bat file?

I need to create a .bat to put together with my setup system to install a network driver, but I have some difficulties in creating the bat.
This .bat needs:
execute a cmd with administrator privileges
run this command: netcfg.exe -v -l networkbll_lwf.inf -c s -i nt_networkbll
exit
The folder for all files location is: c:\Windows\System\Drivers.
You might have to use another batch file first to launch the second with admin rights.
In the first use
runas /noprofile /user:mymachine\administrator batchfilename.bat
PAUSE
and write the needed command in another bat file

batch file - sqlcmd failing in scheduled tasks (0x2331)

I'm trying to use scheduled tasks to run a database back up once per day using sqlcmd that points to a SQL script.
If I open a command prompt and run the code in the batch file everything is successful but when task manager tries it gets a 0x2331 error.
A search reveals it's something to do with permissions - maybe I need to change the path to the sql file?
here is the script:
ECHO OFF
ECHO This is running to backup a database
sqlcmd -S COMPNAME -i C:\backup.sql
GO
ECHO Success!
EXIT
I'm new to batch files to tried to keep it as simple as possble.

Task Scheduler Error (0x1)?

I created batch file with curl script for my Task Scheduler in windows. For some reason I'm keep getting error 0x1 after my script runs in scheduler. Here is my batch file script:
dir C:\curl.exe
for %%# in ("E:\One\Two\*.txt") do curl.exe -T "%%~f#" -u UserName:Password ftp://ftp.test.com/Hello/%%~nx#
If anyone can tell me what is wrong with my script or how I should create call in task scheduler.
Thanks in advance.

MSBuild PSExec hangs without error while executing batch file

As part of as our Team Build MSBuild script, we have a deployment batch file which I need to execute on a remote server:
<Exec Command="psexec -accepteula \\servername D:\Build_Drop\DeploySites.bat "/>
I can confirm it is not permissions or firewall: if the bat command is changed to run iisreset or calc.exe for example, the command will work.
I have tried -s and >nul flags, and also wrapping the batch file in a call to cmd. I have tried with and without quotes around the bat cmd.
All the options I have tried will work fine from the cmd line on the build server, but none will work from within the build script itself.
Any ideas?
Adding a -i parameter to psexec seems to have worked.
Oddly, we now get the error message:
The command "psexec -accepteula \\server -i cmd /c "D:\Build_Drop\DeploySites.bat"" exited with code 5. Please verify that you have sufficient rights to run this command.
But the command does actually work

Resources