-
November 22nd, 2012, 10:07 AM
#1
Can not connect to SQL Server using WMI Services to Remote Computer
I have a VBScript using which I was trying to connect to a server and try to run an EXE - this executable internally is connecting to a SQL Server.
When I run this from my local computer it failed and say -
"Invalid connection string attribute"
When I remote-login to that server and run that EXE directly, it successfully connect to that SQL Server.
Here is the SQL Server Connection string -
ConnString=Provider=SQLOLEDB;Server=xxx.aa.conn\xxxx;Database=COMMONDB;Username=;trusted_connection=yes
Here I am using the same domain, user_id, password to connect to my current computer and that remote computer. No doubt, it connects to that remote server and run whatever command/exe I would like to run.
Here is my script -
Code:
' Run it as -
' cscript //nologo test.vbs <server_name> "command to run task/job"
' E.g. -
' cscript //nologo test.vbs . "notepad.exe"
Option Explicit
Dim strComputer:strComputer = WScript.Arguments.Item(0)
Dim strCmd:strCmd = WScript.Arguments.Item(1)
Dim objWMIService, objWMIService1, errReturn, i
Dim intProcessID, colProcesses, objProcess
'Get the WMI service object for Win32 Process
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & _
"\root\cimv2:Win32_Process")
'Get the WMI service object
Set objWMIService1 = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'Create a process for the to-be-run-job
errReturn = objWMIService.Create(strCmd,null,null,intProcessID)
'Successfull launch of the process returns 0
if errReturn = 0 Then
Wscript.Echo "Process ( " & intProcessID & " ) : " & strCmd & " has Started"
Else
Wscript.Echo strCmd & " Could not be Started. Error: " & errReturn & "."
Wscript.Quit 99
End If
'Get notification of the processes currently executing
Set colProcesses = objWMIService1.ExecNotificationQuery _
("Select * From __InstanceDeletionEvent " _
& "Within 1 Where TargetInstance ISA 'Win32_Process'")
'Check for the process that you ran for it's completion
'once done - notify by echoing end message
Do Until i = 999
Set objProcess = colProcesses.NextEvent
If objProcess.TargetInstance.ProcessID = intProcessID Then
Wscript.Echo "Process ( " & intProcessID & " ) : " & strCmd & " has Ended"
Exit Do
End If
Loop
So, any kind of help/ suggestion is really appreciable.
Please revert, if you would like to know any other information from my side.
Thanks in advance.
Raju2001006
Please put [CODE][/CODE] tags around your code to preserve indentation and make it more readable...
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|