Link to home
Start Free TrialLog in
Avatar of LovetoLaugh
LovetoLaughFlag for United States of America

asked on

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

Avatar of LovetoLaugh
LovetoLaugh
Flag of United States of America image

ASKER

See the screen print of the DTS ActiveX Script Task (Sql-Server-2000-DTS-ActiveX-Scri.JPG)
Sql-Server-2000-DTS-ActiveX-Scri.JPG
ASKER CERTIFIED SOLUTION
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
How can I check the success or failure of the API call?
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.
>>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.
Thank you for your help.  I'm trying a different approach.  So no need to pursue this further at the moment.
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
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