How to get VBS-Script running inside of MacroScheduler

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
migro
Macro Veteran
Posts: 152
Joined: Thu Nov 06, 2003 5:23 pm
Location: Germany
Contact:

How to get VBS-Script running inside of MacroScheduler

Post by migro » Fri Feb 29, 2008 12:31 am

Hi there,

does anybody can help me with this Problem?
I like to run the following script inside of MacroScheduler, but it won't be executed. If I run it directly as *.vbs it works well.

Code: Select all

Let>Action=MyInstance
Vbstart

Option Explicit
On Error Resume Next

Dim strInstanceName : strInstanceName = "%Action%"
Dim objShell : Set objShell = Nothing
Set objShell = Wscript.CreateObject("WScript.Shell") : CheckError

Dim strSqlCmd, strShellCmd
strSqlCmd = "SELECT @@servername" & vbcrlf & "GO" & vbcrlf

strShellCmd = """" & GetSqlCmdFilePath() & """ -S .\" & strInstanceName & " -E -Q """ & strSqlCmd & """ -o C:\test.log"
objShell.Run strShellCmd, 0, True

Function GetSqlCmdFilePath()
   Dim strPath
   strPath = objShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\90\Tools\ClientSetup\Path")
   GetSqlCmdFilePath = strPath & "sqlcmd.exe"
End Function

Sub CheckError
	Dim message, errRec
	If Err = 0 Then Exit Sub
	message = Err.Source & " " & Hex(Err) & ": " & Err.Description
	Wscript.Echo message
	Wscript.Quit 2
End Sub

Vbend

Label>ReadTmp1
ReadLn>C:\test.log,k,line
If>line=##EOF##,Exit
MessageModal>%line%
Let>k=k+1
Goto>ReadTmp1

Label>Exit

regards
migro

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Feb 29, 2008 7:56 am

1) Remove references to WScript - the WScript object is the host. Has no meaning when the host is Macro Scheduler.

2) You can't just reference a MacroScript variable inside VBscript. But you can PASS a variable INTO VBScript.

3) Put your code inside a Sub then you can VBRun it from MacroScript and pass any variables into it you need.

So:

Code: Select all

VBSTART
Option Explicit
On Error Resume Next

Dim objShell : Set objShell = Nothing

Sub DoIt(strInstanceName)
  Set objShell = CreateObject("WScript.Shell") : CheckError

  Dim strSqlCmd, strShellCmd
  strSqlCmd = "SELECT @@servername" & vbcrlf & "GO" & vbcrlf
  strShellCmd = """" & GetSqlCmdFilePath() & """ -S .\" & strInstanceName & " -E -Q """ & strSqlCmd & """ -o C:\test.log"
  objShell.Run strShellCmd, 0, True
End Sub

Function GetSqlCmdFilePath()
   Dim strPath
   strPath = objShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\90\Tools\ClientSetup\Path")
   GetSqlCmdFilePath = strPath & "sqlcmd.exe"
End Function

Sub CheckError
	Dim message, errRec
	If Err = 0 Then Exit Sub
	message = Err.Source & " " & Hex(Err) & ": " & Err.Description
	'Wscript.Echo message
	MsgBox message
	'Wscript.Quit 2
End Sub
VBEND

VBRun>DoIt,MyInstance
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
migro
Macro Veteran
Posts: 152
Joined: Thu Nov 06, 2003 5:23 pm
Location: Germany
Contact:

Post by migro » Sat Mar 01, 2008 12:04 am

Dear Marcus,

thanks for the great help.

I try it out.
regards
migro

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts