Running batch file on Remote Desktop login fails - batch-file

As just extra protection, I am wanting to backup remote sql db to my location nightly. There is no VPN so...
I created a user on the 2008 db server for the sole purpose to log on from my office and download the db bak file nightly. Gave this user read permission on the backup directory (T:\Backup) and added to the remote users group.
I created a Automated task on my workstation that calls a rdp file that successfully connects to the db server as this user.
The rdp file specifies in the "Start a program" tab the following path:
C:\Windows\System32\mstsc.exe T:\Backup\copydb.bat
I have tested both parts:
1) Double-clicking the rdp file will login automatically. (WORKS)
2) I can then manualy open the dos prompt and run the bat file. (WORKS)
However, the bat file does not seem to execute on connection . There is no cmd window. I can douple-click on the bat file and the cmd window will flash and go away but does not execute. The only way I've been able to get it to execute is to open the prompt and then the file.
I thought that's what this would do:
C:\Windows\System32\mstsc.exe T:\Backup\copydb.bat
What am I missing?

This might be your problem.
Refer to this MS support article You cannot create a terminal server session to a Windows Server 2008-based computer by using an .rdp file that runs an initial program
To work around this problem, add the program path to the RemoteApp Programs list. To do this, follow these steps:
Click Start, click Run, type remoteprograms.msc, and then click OK.
In the actions pane, click Add RemoteApp Programs, and then click Next.
Click Browse, locate the program that you want to approve, click Next, and then click Finish.

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.

Why Batch Process not working by Task Scheduler User Administrator?

I have a process for ETL, in a .bat file wich:
copy .xlsx file to a directory
open the excel file by progress
copy the information to progress database
When I run the .bat file by the user: TableauAdmin in the explorer:
it works fine !
TableauAdmin appears as the owner of the .log files
Then I created a scheduled task with the owner: TableauAdmin, and user to run the task: TableauAdmin, in Windows Server 2012. With the Highest privileges, wheter or not the user is loged ...
If I try to run the task I got this error:
Error occurred while accessing component property/method: open.
Microsoft Excel cannot access the file
'd:\ses\dat\FacturaMes-240817.xlsx'. There are several possible
reasons: Error code: 0x80020009 d:\ses\pro\sescargaexcelbd.p (5890)
And now, the owner of the .log files, is the user "Administrators".
Also, I am writing in the log files the %USERNAME% and appears "TableauAdmin"!!!
Is not working the progress-office-excel option by changing the account TableauAdmin to Administrators where is included TableauAdmin.
What to change to every thing works fine?
Today I changed the User that runs the Task to Administrators...
Now everything is working fine, but the user it is running it does not appears Administrators,
The User that appears running the process is another Administrator....
So the Excel File is owned by Administrators
And opened by Administrators
But is running by other Administrator, not TableauAdmin....
Why is running OK now?
Have a look at this link -> https://blogs.msdn.microsoft.com/dataaccesstechnologies/2012/12/19/error-microsoft-office-excel-cannot-access-the-file-while-accessing-microsoft-office-11-0-object-library-from-ssis/
For Windows 2008 Server x64: Create the following directory:
C:\Windows\SysWOW64\config\systemprofile\Desktop
For Windows 2008 Server x86: Create the following directory:
C:\Windows\System32\config\systemprofile\Desktop

Batch file's Core FTP line is Not running during Scheduled Task. Works if started Manually

I have a simple batch file which needs to be run weekly to upload some files via Core FTP.
I'm using the free version of Core FTP LE.
MySavedProfile is the Site Name of the saved profile I created using Core FTP's site Manager. The profile contains the URL / credentials / etc of the site to connect to.
Here are the contents of the batch file:
SET logf=confirm.log
echo test-start >> %logf%
"C:\Progra~1\CoreFTP\coreftp.exe" -B -s -pasv -O -site MySavedProfile -u "C:\Progra~2\PathToFiles\FileToUpload.txt"
echo test-finish >> %logf%
For the Windows Server 2012 r2 Task Scheduler, I have created a basic, weekly scheduled task on the Task Scheduler Library root which runs the batch file. For this scheduled task I have:
(Under the General tab)
"Run whether user is logged on or not" is selected
"Run with highest privileges" is checked
Configure for = Windows Server 2012 R2
(Under Actions)
Action = Start a program
Program / Script = "C:\Progra~2\PathToFiles\batch.bat"
Start in = C:\Progra~2\PathToFiles\
Here is the weird behavior I am getting:
If I double click on the batch file directly, it works fine and uploads the text file via Core FTP just fine.
However, if I try to let the Windows Task Scheduler run it, it runs everything except the Core FTP line. That is, I get the usual:
test-start
test-finish
in the confirm.log file, but the FileToUpload.txt has not been uploaded to the remote server, and there are no errors from CoreFTP that I can detect.
I have tried this with a service account that has permissions to run batch files, as well as my own account for this scheduled task. I get the same result: it doesn't seem to run that CoreFTP line. At least not via Task Scheduler. I need this upload to be automated.
I've searched Core FTP's documentation, Google, etc. No one seems to have run into this exact issue. I've applied recommendations from distantly related issues, but none of them have worked.
Any help would be greatly appreciated. Thank you.
The only way to do this is to use the full version of Core FTP (that is Core FTP Pro). If you use the LE version you have to check the "Run only when user is logged on" option.
This happens because of the splash screen at the beginning.
If you can't be logged on forever you could create a user that will always be logged on just for these tasks.
Remember to use the -Log option on CoreFTP to check if it is actually doing something.

Can not copy SQL Server files, Access is denied

I need to copy my SQL Server DBs to a folder. The files are attached to SQL Server, which I have detached using my code. When I try to copy these files using
My.Computer.FileSystem.CopyFile(filePathToCopyFrom1, targetFilePath1)
It returns error:
"Access to the folder D:\MyDbs is denied"
When I manually coped these files, it asked "You need Administror permission to copy these files" I clicked continue and it worked but how to fix this using my vb.net code?
I have given Full Control to administrator from Windows but still it did not work.
Thanks
Seems that the detaching process went well. You can copy through windows explorer, but not from you application. The key difference here is that the files are protected to be accessed by the administrator user only.
Then, you need to run your application using an administrator windows account so that the application inherits the permissions of the user to be able to perform this operation.
Remember, if you are using Windows Vista+ (which I assume you do) the root folder is almost off limits. You can run the App as Administrator, or copy it to a folder in the root. The other point is that where you copy from. If the DB is currently in Program files, it is very possible that you will get this problem as well, and then you will have to run the application as Administrator.
Right click on the application, and select Run as Administrator, or select properties and in Compatibility check the box that the program should be running as Administrator. If you use the latter, then a box will pop up every time you run it, unless you change the User Account Control settings.

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

Resources