Text File Permissions Issue - batch-file

What is the default SSIS Account that is used in SSIS packages.
In one of my packages I have a Data Flow task that creates a flat file. A BAT file later runs and creates a file based on information in that .txt file. If I execute the .BAT in Windows Explorer it runs fine. When SSIS tries to execute it I can see the CMD window open and it tries to access the txt file and isnt able to. Says "Unable to access nameoffile.txt"
I assume the issue is that the permissions are probably inherited by the SSIS user account so I am trying to figure out which account that is.

If you are running it from the IDE then it uses your permissions. Most likely the problem is that your file is locked by some other process in your SSIS package. To verify:
Add a PAUSE to your batch file to make it wait for any key.
Run your package. While the dos prompt is waiting, go into windows explorer and run your batch file again - you'll find the same error.

I changed the attrib value in dos for that specific folder by attrib -r -s and it worked. It thought it was read-only.

I am using Windows Server 2012 server, with a SQL Server 2012 database.
Adding Modify, Read, Write permissions to the folder containing the required file to the NETWORK SERVICE user seems to work for me.

Related

SSIS runs package that runs powershell script but SSMS don't

I have a package on SSIS that executes a .BAT file that consequently executes a PowerShell file, which brings the file metadata from a folder, generating a CSV file.
I already granted access to the folder for the SQL Server Agent user, but it didn't work.
When I run the package on SSIS, it works correctly! However, if I execute the same package through a JOB in SSMS, it ends the step, but the .BAT file was not executed, or if it was, the Powershell file did not, because after the execution the CSV file is "1kb", no data.
Am I forgetting something?
SSIS package (portuguese language):
[EDIT 1]
A strange thing that I noticed, was that we have 3 packages scheduled by SSMS, but only one of them that doesn't work, which is the one mentioned in the question. But I can't find out why or what the difference is to others.
2 packages extract information from Sharepoint and work on SSMS, but this other package that extracts metadata from files does not.
Check the job step's "Run As" value, which is a "Proxy" (visible in the Object Explorer in SSMS.
Open the Proxy (SQL Server Agent >> Proxies >> SSIS Package Execution). It will list a Credential Name.
Open the Credential (Security >> Credentials). It will list an Identity. That's the user whose security needs to be configured.
Open a cmd window and run runas /user:<userGoesHere> cmd and enter the password when prompted. See the documentation of runas here
Now, it opens a second cmd window which runs under this user used in the SQL Server Agent. Execute your batch file and see if you'll catch any error.
Also, the process you're running may require the user to have Log on as a batch job permission. Run secpol.msc from an admin account and add this user to this permission.

Batch or .exe via SSIS package fails to give output despite of success status of SQL Agent Job

I have created a batch file which starts a command line (IrfanView) with several arguments. The batch looks like this:
start /wait /d "C:\Program Files (x86)\IrfanView" i_view32.exe C:\Source\*.png /advancedbatch /convert=C:\Destination\*.jpg
Basically it converts all PNG from source folder to JPEG using advanced batch settings stored in INI of IrfanView to destination folder.
The batch file is located on my server (same as IrfanView) and when manually started it works fine. I also tried to start the batch using SSIS execute process task, which also works when package executes manually.
Another option was to start IrfanView directly from the execute process task (so no batch file) and then manually trigger the package. Every option seems to work manually.
However, whenever I try to run the batch (cmdExec) or any package in SQL Agent it will run the job successfully, but... there is no output in the folder. So, it doesn't give an error, it simple does nothing.
When run manually the output files will appear as expected in the destination folder.
When run through SQL Agent no output files will appear although the job was run successfully.
Could it have to do with security settings? SQL Agent runs under local user with full administrator rights.
I have read something about credentials and proxy, but not sure how to use it and if it will solve the problem.
I have another job running which also calls an executable (7zip) in a SSIS package and it works fine.
If I use another program, for example Flash Renamer from command line, then the SQL Job keeps running (status in progress), while triggering the package or batch manually it works fine.
Using SQL Server 2008 (BIDS + SSMS)
How can this be resolved?
Command start often interprets first double quoted string as title string. Therefore it is necessary to specify a title in double quotes if any other string must be enclosed also in double quotes.
IrfanView does not require that its program directory is the current working directory. Therefore simply starting IrfanView with full path would be better in my point of view.
IrfanView option advancedbatch requires data from i_view32.ini. On running IrfanView with a different account, it will be necessary most likely to specify the path to the folder containing i_view32.ini.
i_view32.ini is usually stored either in program files directory of IrfanView or in directory "%APPDATA%\IrfanView".
The first option is usually not used anymore as default program files location "%ProgramFiles(x86)%\IrfanView" on Windows x64 or "%ProgramFiles%\IrfanView" on Windows x86 is write-protected by default for users of Windows Vista and later Windows versions.
Therefore i_view32.ini is nowadays by default in application data directory of IrfanView of current user account.
Yes, environment variable APPDATA contains name of the user account and differs therefore from user account to user account. And by default user X has no permission to access the application data directory of user Y.
So on running IrfanView with a different account, file i_view32.ini or a copy of it containing the advanced batch conversion options must be located in a folder readable for all user accounts or at least the used account and on command line the path to this folder must be specified, too.
With summarizing up all information above, you would need most likely
start "Convert PNG to JPEG" /wait "%ProgramFiles(x86)%\IrfanView\i_view32.exe" C:\Source\*.png /advancedbatch /convert=C:\Destination\*.jpg /ini="Path to folder with i_view32.ini" /cmdexit
But below should also work if the batch file does not contain any other commands and therefore no batch file is needed at all.
"%ProgramFiles(x86)%\IrfanView\i_view32.exe" C:\Source\*.png /advancedbatch /convert=C:\Destination\*.jpg /ini="Path to folder with i_view32.ini" /cmdexit

Batch runs manually but not in scheduled task

I don't generally write batches, but I currently have a batch that uses forfiles to copy my FLVs from one folder to another. When I run the batch manually it works every time, but from a scheduled task, it throws a (0x1) error.
forfiles -p "C:\Program Files\Adobe\Flash Media Server 4.5\applications\name\streams" -m *.flv -s -d -1 -c "cmd /c copy #file ^0x22C:\Program^ Files\Adobe\Flash^ Media^ Server^ 4.5\applications\name\output\"
Not sure what syntax the scheduled task doesn't like.
Update
Under my scheduled task, Actions I have the following:
Program/script: name.bat
Start in (optional): \\servername\file\to\batch
Hi might be this is helpful,
I also face the same issue.
Just set the startin path like:
Here start in path is the path of batch file:
like you have enter in program script:
"E:\program related files\demo.bat"
then in startin just pass:
E:\program related files & done!
When my Start in (optional): path was a UNC path, it wouldn't work. So I moved my batch on the server and everything worked correctly.
UNC in Windows Batch Files
forfiles with UNC path
On Server 2008 R2 when running the batch file under domain user credentials, with confirmed "log on as a batch job" security in the Local Security Policy>Local Settings>User Rights Assignment,
even then my batch (copying a log file to a network share) would not run as scheduled task, until I selected in tab General the option "Run with highest privileges" (default NOT checked!)
The option Run whether user is logged on or not was also selected, with radio-button, but I guess this is quite standard, when selecting to run the task using a domain user account.
For the tab Actions : specifying the entire batch file name including its path, directly in "Program/script:" works fine (with Server 2008 R2)
Using double quotes inside the batch file causes no problems.
See the screen shot bellow.
You need to change the user to system
Most common reason for such problems is permissions: scheduled tasks does NOT always run with your user credentials. If you want scheduled task to run as you you will have to set it up as you or alternative user.
Besides that I hope that your line of code is a content of your batch file, you are not trying to run this command directly. Or are you?
P.S. What are these ^0x22 and ^ doing in your code?
I know this is an old question, but just wanted to share some info.
The (0x01) error code can also refer to resources that are not found. Therefore:
all files/folders referd from within the batch file should be accessible to the user which account is being used to run that scheduled task;
pay attention when using network locations in combination with "Run whether user is logged on or not" option;
the above-mentioned option can be tricky to use because some resources may be available only after log on.
For .bat files to run inside your scheduled task, you need to specify your .bat file path inside the start option - despite the fact that your .bat file is at the same directory as your .exe. Also, I flagged it to run with highest privilege. After I have done those two things, the task suddenly takes off without any problem!

How can I use a batch file to launch an application as a specific user?

I'm trying to figure out how I can use a batch file to launch Internet Explorer as a local user on the system hosting the batch file. Ideally I'd like to be able to double click the batch file and not have to enter user credentials. To break it down a bit:
User is logged onto the host system with a domain user (Server 2008 R2 Standard 64bit)
User can then double click on a batch file that will launch Internet Explorer as a local user on the host system, without prompting for the local user credentials
All I can find is information about NET USE, any help would be greatly appreciated!
"runas" command was intentionally designed to prompt for password. So, that is not your solution.
One of option is to create a scheduled task where you can store the password (safely) and run the scheduled task from batch file.
But if the batch file is distributable and not going to be run on same machine.. you may have to investigate on how to create a schedule task from batch file and then run it.
you may find this reference helpful

Running batch job using TeamCity fails, but Manual command prompt works

I am getting this error message running a batch job with TeamCity. The batchjob is copying files from TeamCity Server to another server(server2). Have checked multiple times, the folders have all the rights permissions needed and this works fine (copies files between servers) when the batch job is run manually from command prompt. I have this error for each file that needs to be copied.
error MSB3021: Unable to copy file "..\bin\Release\Boo.Lang.Compiler.dll" to "\Server2\DestinationFolder\". Could not find a part of the path '\Server2\DestinationFolder'.[10:54:32]: Creating directory "\Server2\DestinationFolder".
I tried few things, but issue remains unresolved. Thanks for your input.
TeamCity build Agent is running as System user account that has no access to the network resources, you should change the service user to an account that has network permissions, like your Administrator account.
See also the related question.

Resources