WScript.Shell in a job

  • I have an ASP page that creates a job in SQL Agent, waits for the job to complete and then shows some output. The job that is created uses wscript.shell to run an executable (our time card program) on the sql server.

    sample job step:

    Set obShell=CreateObject("WScript.Shell")

    obShell.Run "c:\kronos\apps\tkcwin.exe /data x:\kronos\data /sl c:\weblog.txt /s c:\test.ks1", 6,true

    set obShell=nothing

    just fyi -

    /data tells tkcwin where to pull the db info

    /s tells tkcwin what script to run

    /sl tells it where to create a log file

     

    The job starts, and tkcwin appears under "processes" in event manager. However, tkcwin never does anything. Even if it fails, it should create the log file c:\weblog.txt. That's not even getting created . The process never terminates. I have to manually kill the process, then the job finally completes.

    If I put the same script into a vbs file and run it (logged into the server using the same credentials that sql agent is started with), it works fine. This is using SQL2000, Win 2003 server.

    I have agent service starting with a domain account because tkcwin's data is on the network (x:\kronos\data)

    If I switch agent service to start as system account and check "interact with desktop", I can see tkcwin start, but it gives the expected error that it can't find the data (system account can't hit the network resource x:\)

    The real P.I.T.A. is that I have this exact setup working on my server running WINNT, but I'm being forced to upgrade to 2003 for obvious reasons.

    I set up this process years ago, so I can't remember now what (if anything) I had to do to get this to work. Is there a permission that the sql agent startup account is missing?

    Any help is greatly appreciated!

    Eric

  • I should also point out that this is not something specific to the tkcwin.exe. I wrote a simple vb app that just writes a txt file and terminates, and tried the same technique calling my vb app in place of tkcwin.exe. I get the same result.

  • Don't use WScript.exe, use CScript.exe.

    The former is the Windows desktop version which pops up a window to allow parameters to be specified. This is the same as trying to use MsgBox in server executed code--it executes in a process without a GUI desktop or anyone to click on the buttons to let it continue.

    CScript.exe is the command-line versions, intended for batch use. You can feed it all the parameters and options in the command string that starts with

    "CScript.exe " and your script name.

    See the MSDN library http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/3d348b43-f98a-43dd-986b-93adff7945fe.asp

    Which is   MSDN Home >  MSDN Library >  Web Development >  Scripting >  Microsoft Windows Script Technologies >  Windows Script Host > Running Your Scripts.

    David Lathrop
    DBA
    WA Dept of Health

  • Thanks! This did help, but I also had to change x:\kronos\data to unc path : \\drive\share\kronos\data\

     

    This surprises me since SQL's startup account has X mapped correctly. I wonder if this is some new layer of security in 2003, since it worked in NT without converting to unc. Oh well, best not to dig too deep. Otherwise I'm liable to break it again.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply