Connecting shared network drive through scheduled task - batch-file

Actually, i have one scheduled task in my application to trigger multiple batch files based on timings ( maintaining like crontab). I dont want store the password of the my account, i have selected "Do not store password" option when i created schedule task.
Now, i tried to connect the network drive through one pf the batch file which is triggered by this schedule task, i am getting access is denied error.
When i run the batch file normally (not triggered by schedule task), it is working without any issues.
Could you please help me to connect the network drives through the schedule task.
Thanks,

Related

Create files and folder to network drive using SSIS

I have created SSIS packages which creates new folder using file system task at output location and then creates data files in that folder using data flow task.
I have created one network drive which is mapped to azure blob. So I pass the network drive path like Z:\ to package and the folder and files are created as expected which are also reflected on the azure blob.
Now when I schedule this package through SQL agent job I get error that the cannot find part of the path Z:\folderName from file system task. So I though it is because the sql server agent service was not running through my user id . So I started sql server agent with my credentials but it still gives me same error.
Note: My Id doesnt have direct access to azure blob and the network drive is only accessible by my id.
We are currently using azure blob for dev but we may use separate server to store files due to which I cannot use flexible file system task available in SSIS azure service pack
We had reasons we could not use UNC paths (\server\share\file.txt) and struggled with mapped drives as well. The approach we ended up using was to explicitly map and unmap drives as part of our ETL Process.
Execute Process Task - Mount drive
We used a batch file to mount the drive as it made things easier on us but the command would take the form of something like
net use Z: \\server\share mypassword user#azure
Execute process task - Unmount Drive
Again, execute process task
net use /delete Z:
We ended up with a precursor step that I don't remember how we accomplished it, but we would test whether the drive had been unmounted before we attempted to mount it. I think it was File System Task to see if the drive existed and if so, then we had the Unmount task duplicated.
I was able to resolve this using credential manager. I logged in using a domain user and then added the azure path like \\server, userid and password to windows credentials . Then started the sql server agent service using the same domain user id . Set up the file path as \\server\share similar to what I have provided in windows credentials into the ssis package configurations.After doing this I was able to successfully execute the package through sql agent job.
I was able to solve this issue using script task (C# Code) to move data. I've generated a project parameter for Target ShareFolder and used it as ReadOnlyVariable for script task. The target share folder has been already mapped as a network drive on my local PC as well as on Application Server.

Execute process task not running from SQL Agent Job

I have an SSIS package that runs a backup in a T-SQL task and then uploads the file to google drive from an execute process task. The package runs perfectly from the catalog. When I try to run it from sql-agent job, the backup runs ok but the upload to google drive does not. There are no error messages in the job history or in the package history.
The sql agent job is set to run from a proxy account with the necessary credentials.
The issue turned out to be that the command file was trying to find another file it needed to run execute the code, but since the windows user changed it was looking in a different users folder. We solved it by passing the filepath as a param so it doesn't default to the user accounts folder its executed from.

Batch file runs fine but not in Task Scheduler

Afternoon everyone,
I've tried to research this topic in depth and I cannot come to a conclusion for my problem. I'm trying to automate a batch file in Task Scheduler to execute two SSIS packages. Currently when I attempt to execute the scheduled task (either waiting for its set schedule or running on demand), task scheduler will show that the task has completed successfully, the "Status" will continue to say "Running" but the destination files are never created/re-created. This is the script:
dtexec /f "D:\SSIS\Folder\Folder\Folder\Package.dtsx"
dtexec /f "D:\SSIS\Folder\Folder\Folder\Package.dtsx"
The SSIS is supposed to pull information from SQL and export it to a CSV which it does wonderfully... If I execute this script in CMD, Powershell, or run my batch file directly.
About my environment:
My script resides on a SQL Server. (Windows Server 2016 Standard)
I have a domain admin account used for scripting permissions (all parent folders including the batch file itself have that domain admin added with full permissions, including the csv destination).
The scheduled task is set to: "Run whether user is logged on or not", "Run with highest privileges", Configured for Windows Vista and Windows Server 2008. I know my credentials are correct for my domain admin account.
In "Actions", "Program/script:" is currently set to "C:\Scripts\file.bat", there is nothing in "Add Arguments (optional):" currently, "Start in (optional):" is set to "C:\Scripts".
So here is what I've tried:
I've set "Program/script:" to "cmd.exe" and added an argument of "file.bat" with a start in as "C:\Scripts", no dice.
I've set "Program/script:" to "Powershell.exe" and set an argument of "-ExecutionPolicy Bypass C:\Scripts\file.bat" with a start in as "C:\Scripts", no luck again.
I added my domain admin account to the local administrators group on the server as well.
I've changed the user/group from my domain admin account to my domain admin account (the one I'm logged into the server with) and set it to "Run only when user is logged on", if this is set and I attempt to run the scheduled task, CMD flashes on screen and disappears before I can read anything (it's still too fast for the script to actually run, it takes ~20 seconds) and the destination file isn't altered.
(This one really stumps me) I've tried to add the script to another scheduled task on the server, that scheduled task will run on schedule and complete every script in the batch file except for these 2 lines. The other scheduled task it was added to uses the same domain admin account, same settings across the board, it even has other similar SSIS packages being run using "dtexec", I don't get it.
Thanks for any input anybody can give me, it's greatly appreciated.
I know this is a super old post, but I just had the same issue and wasn't successful with any other popular solutions around StackOverflow, so I want to put out an alternative solution for anyone still struggling!
When in doubt, double check the user account in the Security Options under Properties (right-click on Task > Properties > first page under "Security Options").
Even though the user that it had selected by default should have permission to execute the script, I had to change the user account to a user with a higher privilege (I'm on a work computer). For me, this meant I had to select the Administrator group on my particular desktop environment.

Exe files run by Windows service remain in Task Manager and are not removed

I have a Windows service that is basically a job scheduler. When a job is supposed to be triggered it reads some parameters from an Sql Server database and runs an exe file.
In order for the service to read from the database I have to change my service properties to log on as another account who has access to the database. So I have to change my local account to an account e.g. john.smith#myserver.com with password=123
Things seem to be working fine, except when I leave the computer at night and a job is supposed to be run e.g. every hour. The morning after when I log on, I see that the jobs are successfully triggered but for each run of the job there is a new instance of the exe file in my processes. And I have to close all those instances. This obviously is not my desired behavior.
Does anything change when windows is in Locked mode? And either way, why the new instances of the program remain in task manager. Not to mention, the exe files are automatically closed whether they do their job correctly or not.
If you run the EXE from the command line, does it require any kind of keyboard input? Is it asking for parameters? Does it say something like "Press any key to exit"?

Batch file logs into remote desktop, but stops at interactive logon message

I've got this script in a batch file:
cmdkey /generic:"servername" /user:"user id" /pass:"password"
mstsc /v:"servername"
...which logs me into a remote server (remote desktop session). It works great, but doesn't actually log me in all of the way because this server is configured with an interactive logon, meaning there is a message that comes up that I have to click OK to when I first connect before it actually signs in all of the way.
We have a problem with our admins shutting down this server at night to apply updates and thus logging us out - causing our scheduled tasks to not refresh. I want to assign this batch file to a scheduled task on my local PC to ensure that every morning, before my scripts run, I'm logged back into the server.
Is there a way to get this batch file to bypass/acknoweldge this message so it finishes signing me in?

Categories

Resources