How to get login script stored in mssql database

Posted on 2009-12-16
Last Modified: 2013-11-21

I want to put an entire login script in a sql database and then get it when the user login in the domain.

I tested write a script like this:

Set obj_Shell = CreateObject("WScript.Shell")
select.txt run sp for print out login script in text form
Set obj_WSH = obj_Shell.Exec("sqlcmd -h-1 -S\wdb11 -U xx -P xx -d loginscript -i select.txt")

Set obj_STDOUT = obj_WSH.StdOut
str_Output = obj_STDOUT.ReadAll
WScript.echo str_Output

'objFile.writeLine str_Output

Can I use sql database for storing login script in text form in the database? And get it from there, and run it when the user login?

Question by:mholmen
    1 Comment

    Accepted Solution

    I figured out....:
    'Start -----------------------------------------------
    Set WSHNetwork = WScript.CreateObject("WScript.Network")
    UserName = ""
    UserName = WSHNetwork.UserName

    On Error Resume Next
    Set obj_Shell = CreateObject("WScript.Shell")

    sql_query = "sqlcmd -h-1 -S\wdb11 -U xx -P xx -d loginscript -Q ""exec LongPrint """ + username + """"
    Set obj_WSH = obj_Shell.Exec(sql_query )
    Set obj_STDOUT = obj_WSH.StdOut
    str_Output = obj_STDOUT.ReadAll

    'WScript.Echo str_Output
    'End ------------------------------------------------------------------------

    The procedure I had to use, found at:
    I neded this because the loginscript field vas more then 8000 characters.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Want to promote your upcoming event?

    Is your company attending an event or exhibiting at a trade show soon? Are you speaking at a conference? Spread the word by using a promotional banner in your email signature. This will ensure your organization’s most important contacts are in the know.

    My previous article  ( one possible method to get SCCM 2007 installed an…
    Back in July, I blogged about how Microsoft's new server pricing model, combined with the end of the Small Business Server package, would result in significant cost increases for many small businesses (see SBS End of Life: Microsoft Punishes Small B…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now