xp_cmdshell can''t execute VBS

  • Hi, I have created a VBS file with the following code :;

    Set WshShell = WScript.CreateObject("WScript.Shell")

    WshShell.Run("http://www.yahoo.com")

    When I double click on this file it opens http://www.yahoo.com but when I execute exec xp_cmdshell 'c:\Name.vbs' in Query Analyzer nothing happens and the output is 'NULL'.

    I want to run this VBS file through SQL and get the desire output. I am logged in as 'SA' and get the result when I type exec xp_cmdshell 'dir c:\'.

    Please help me out... Thanks in advance.

    Pradeep

  • to run a vbs file dont you need xp_cmdshell 'wscript.exe c:\Name.vbs' as the command?

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks for ur reply Lowell. I tried the command which you specified. Still i am getting the same output 'NULL' and the file is not getting executed. Please look into this.

  • you are right...i get the same results...it runs to completion and returns null.

    what are you expecting to get back, though? you don't expect it to return the html as results right, just zero or some number if it failed to run successfully?

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • For me, the following works - EXECUTE master.dbo.xp_cmdShell 'cscript.exe \\asm8\c$\transf~1\transfer.vbs'

    I use cscript.

     

    ~Steve

     

  • In fact I want to open an ASP page. yahoo.com is an example. Steve, did you use the same script which I had entered? When I use cscript to run the vbs file, I get the following result:

    Microsoft (R) Windows Script Host Version 5.6

    Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

    NULL

    NULL

    Please help me out with this...

  • Pradeep,

    I don't think that you can make a web page open using this method.  My understanding is that only batch-type commands will run, not something visual or requiring user input.

    ~Steve

     

  • Maybe something like the following will work:

    Set WshShell = WScript.CreateObject("WScript.Shell")

    WshShell.Run("""c:\program files\internet explorer\iexplore.exe"" http://www.yahoo.com")

     

  • To the best of my knowledge SQL Server is non interactive. Which means that u can't invoke a new program from it. I have tried to invoke a exe from SQL and found that the exe was invoked properly but the application was not called and when i checked the same in the process list i found that the exe was invoked and SQL server was not able to open that in a new windows or as a interactive application.

     

    Any comments on this is really welcome as this will solve a problem that even i am facing.

    Thanks in advance.

    Cheers,
    Sugeshkumar Rajendran
    SQL Server MVP
    http://sugeshkr.blogspot.com

  • ok, I see the issue is that you need an inet control to read a web page....no problem...so i built a dll in vb6 with just one public method.

    a .vbs file with these commands in it returns a msgbox with the text from any web page passed to it...

    so how do i get it to SQL server? write a file and bcp it in? any ideas?

    as soon as i know how to get it into sql server, add add the same thing for an FTP file and give everyone the source code...it's really like 6 lines of code...very simple.

    Set x = WScript.CreateObject("WebReader.Reader")

    msgbox x.GetWebPageContentsAsString("http://www.yahoo.com")

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 10 posts - 1 through 9 (of 9 total)

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