Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 99
  • Last Modified:

cant launch executables in sql server agent

Hi,

I'm unable to run an executable in the Sql Server Agent.
For example if I just wanted to open Notepad from the Sql server Agent, I did the following:
Create Job Step -> Change Type to Operating System (CmdExec) -> Command is C:\Windows\System32\Notepad.exe.
But the job doesn't do anything it just keeps executing with no results...
 What am I doing wrong, I tried a couple of commands. I even created an SSIS package to open it...the package opens the application correctly from SSIS, but once the package is in a job it doesn't open.
0
cErasmus
Asked:
cErasmus
  • 10
  • 8
  • 2
  • +1
1 Solution
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
Did you check the job log? Or the Event log?
Must be there something pointing to the problem.
0
 
cErasmusAuthor Commented:
Hi Vitor,

I'm looking at the log file viewer and I'm not seeing anything that was captured for this specific job.
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
The job runs in the context of the SQL Server Agent account so be sure that it has the necessary permission on  C:\Windows\System32
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Vitor MontalvãoMSSQL Senior EngineerCommented:
And you can check the history of a job in the Job Activity Monitor by right-clicking on the job's name and choosing View History:

JobHistory.PNG
0
 
cErasmusAuthor Commented:
Hi,

Maybe you misunderstood me...when I start the job it doesn't finish or give me an error it only keeps on trying to execute.
In the job history it says that I stopped it.
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
Ok. I did a test myself and got the permission error for the SQL Server Agent account. It was immediate.
0
 
cErasmusAuthor Commented:
Did you get it to open Notepad?
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
I think I could replicate your problem. It wasn't a permission issue as I thought.
You are only using Notepad for testing or it will be really your finally solution?
I'm getting the impression that it doesn't work with Windows programs that needs user interaction.
0
 
ZberteocCommented:
You have to understand that the Notepad will be opened ON THE SOL server machine and not on your local unless the SQL server is installed locally on your laptop/desktop.
0
 
ZberteocCommented:
What I mean is that when you try the SSIS it will execute on YOUR machine but as soon as you put your command or package into an SQL Job it will execute on the box where the SQL server resides.
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
I assumed that he tested this in the local server as I did and got the exactly the same issue.
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
And if you don't cancel the job you can see the notepad.exe process in the Task Manager so I really think the problem is with programs that has GUI interaction.
0
 
Deepak ChauhanSQL Server DBACommented:
Please check the "processes" tab in windows task manager. you can see notepad. exe running there as a process.

if you kill the notepad process (end process) in task manager. your job will be stopped.

Reason:

CmdExec is not designed to start applications that have a user interface that interact with a user. If you use to start an application (for example, Notepad) that has a user interface,  your application start in background and then wait indefinitely until it ends. Because it pass the control to your application and it never regains control from your application.

The same is story is for xp_cmdshell as well.
0
 
cErasmusAuthor Commented:
Hi Zberteoc,

I am running the SQL on a localsystem.

Hi deepakChauhan,

I checked my task manager and did not find any instance of notepad when I started the job. You say that CmdExec doesn't allow for applications to open which has a user interface, how can I then open an application? I already created a SSIS package with an Execute Process Task to open notepad. It works fine in SSIS, but as soon as I try to run it through SQL Server Agent it gives me the same result of not opening notepad.

Hi Vitor Montalvão

I am only using Notepad for testing, I actually need to run an app to open a Cisco VPN AnyConnect.
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
cErasmus, did you try to open the Cisco VPN AnyConnect with the SQL Server job?
0
 
cErasmusAuthor Commented:
Yes I tried that, and it doesn't open. You see my whole problem is that I need to automate the login with the Cisco VPN Autoconnect, so I created an AutoHotKey.exe to do this.
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
Looks like you'll need to find a workaround for that.
Can't you use the Windows Schedule Task utility?
0
 
cErasmusAuthor Commented:
That's what I'm thinking about, but I really wish I could have used the sql server agent, because I have a couple of jobs that need to run after each other, with different logins and depending on the connection the time it takes to finish a job can cause a conflict with the next VPN that must start with the windows scheduler.
0
 
cErasmusAuthor Commented:
Vitor, I'm going to keep this question open for now, but if I don't receive any solutions I'll award the points to you.

Thanks for the help.
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
Ok. I'm sorry I couldn't help more. I also never used SQL Server jobs to open another application.
Good luck.
0
 
cErasmusAuthor Commented:
Although my problem didn't get a solution Vitor was very helpful.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 10
  • 8
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now