SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


passing parameters to a vbs file in command line


passing parameters to a vbs file in command line

Author
Message
coolchaitu
coolchaitu
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1652 Visits: 1174
Hi,

I have a VbScript file that has oSQLServer.Connect statement using windows authentication. I am trying to pass the servername as parameter from command line.

cscript ScriptJobs.vbs KIRAN\SECONDARY

this value KIRAN\SECONDARY should be passed as the servername in VBScript. I have the following code
Dim ArgObj
Dim ServerName
Set ArgObj=Wscript.Arguments
Set ServerName=ArgObj.Item(0)

Dim oSQLServer
Dim oStream
Set oSQlServer = CreateObject("Wscript.SQLDMO.SQLServer")
Set oStream = CreateObject("ADODB.Stream")
oSQLServer.LoginSecure=True
oSQLServer.Connect "& ServerName"

Dim idStep
Dim ScriptJob
Dim CountJobs
Dim JobName
Dim ScriptAllJobs

For Each oJob In oSQLServer.JobServer.Jobs
CountJobs = oSQLServer.JobServer.Jobs.Count
Next

For idStep = 1 To CountJobs

JobName = oSQLServer.JobServer.Jobs.Item(idStep).Name
ScriptJob = oSQLServer.JobServer.Jobs.Item (idStep).Script(4, "C:\" & JobName & ".sql")

ScriptAllJobs = ScriptAllJobs & ScriptJob

Next

oStream.Open
oStream.WriteText (ScriptAllJobs)
oStream.SaveToFile ("C:\SQLAllScripts.sql"), 2

oStream.Close
oSQLServer.DisConnect

Set oStream = Nothing
Set oSQLServer = Nothing
Set ArgObj=Nothing


However, the parameter that i pass in command line is not being taken as input into the ServerName.

Please help me out with this
Gianluca Sartori
Gianluca Sartori
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24699 Visits: 13362

Set ServerName=ArgObj.Item(0)



should be changed to


ServerName=ArgObj.Item(0)



because in VBScript Set is used to assign objects only, not primitive types.

Hope this helps
Gianluca

--Gianluca Sartori

How to post T-SQL questions
spaghettidba.com
@spaghettidba
coolchaitu
coolchaitu
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1652 Visits: 1174
Thanks a lot for replying. Take CAre
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search