Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 472
  • Last Modified:

Running a command (batch file) on a remote PC from SQL Server 2000

I am trying to run a batch file on a remote PC from SQL Server 2000 DTS.  
I created a Visual Basic ActiveX script interface in DTS.  I have attached the code below.
The DTS package completes successfully, but results from the Batch file are not seen.

I do not know how to debug vbscript in SQL server DTS or even if I have the DTS package setup properly.

Any help would be great.
'**********************************************************************
'  Visual Basic ActiveX Script
'************************************************************************

Function Main()
	Call RunBatchFile()
	Main = DTSTaskExecResult_Success
End Function

Sub RunBatchFile()
	strComputer = "simCompServer"
	Set objWMIService = GetObject _
	("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
	objWMIService.Create "D:\OperatorActions\3cfgserver.bat", Null, Null, intProcessID
End Sub

Open in new window

0
LovetoLaugh
Asked:
LovetoLaugh
  • 4
  • 4
1 Solution
 
LovetoLaughAuthor Commented:
See the screen print of the DTS ActiveX Script Task (Sql-Server-2000-DTS-ActiveX-Scri.JPG)
Sql-Server-2000-DTS-ActiveX-Scri.JPG
0
 
Anthony PerkinsCommented:
>>The DTS package completes successfully, but results from the Batch file are not seen.<<
That is because you are not checking the success or failure of the API call and instead are always setting the task to Success.

>>I do not know how to debug vbscript in SQL server DTS or even if I have the DTS package setup properly.<<
1. Right click on Data Transformation Services.
2. Select Properties
3. Enable "Turn on just-in-time debugging"
0
 
LovetoLaughAuthor Commented:
How can I check the success or failure of the API call?
0
Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

 
LovetoLaughAuthor Commented:
The code works fine when I change
 strComputer = "simCompServer"
TO
 strComputer = "."

That is, I can run a batch file on the local machine with this code, but I am not able to run code on the remote machine.
0
 
Anthony PerkinsCommented:
>>How can I check the success or failure of the API call?<<
Send me the definition of this particular API and I may be able to figure it out.
0
 
LovetoLaughAuthor Commented:
Thank you for your help.  I'm trying a different approach.  So no need to pursue this further at the moment.
0
 
Anthony PerkinsCommented:
Never mind, I beleive I have figured it out:

Function Main()
        If RunBatchFile() = 0
              Main = DTSTaskExecResult_Success
        Else
              Main = DTSTaskExecResult_Failure
        End
End Function
 
Function RunBatchFile()
        strComputer = "simCompServer"
        Set objWMIService = GetObject _
        ("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
        RunBatchFile = objWMIService.Create("D:\OperatorActions\3cfgserver.bat", Null, Null, intProcessID)
End Function
0
 
Anthony PerkinsCommented:
Here is the definition for the Create Method and all the potential errors:
Create Method of the Win32_Process Class
http://msdn.microsoft.com/en-us/library/aa389388(VS.85).aspx
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now