WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE COM ADO CDO ADSI LDAP
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Virtual Server COM CoInitializeSecurity


Question:

The ms virtual server is nearly fully accessible via Com objects and I would like to use winbatch to do the job :)

I'm probably missing something because I can create the VS object but when I try to do something with it I got an "OLE Exception".

objVS= CreateObject("VirtualServer.Application")
name= objVS.Name
When I use a method instead of a property and don't supply any parameters it says "bad parameter count", so I seam to have 'contact' with the object.

any idea what I'm doing wrong or should do to find out what the problem is?

(I've got local administrator permissions on the server)

Answer:

I have encountered similar problems but don't have a good explanation. I believe the issue revolves around the default authentication used by the COM client. (This in not an authentication issue that is address by the rights and privileges of the user account used to launch the script.)

If I remember correct, I was able to get access to Virtual Server object properties and methods by fiddling with the Component Services administrative tool. What I changed I don't recall.

Sorry I can't be of more help.

User Reply:

I found that the key for this is in the underlaying VB code ('CoInitializeSecurity')according to Ms. This security should be set before one can work with the virtual server com objects Can somebody give me some hints howto translate this in wbt...:-)
________ VB code __________
The following steps must be performed to set up the build environment:

Create a new Windows Applications project called ShowVSVersion. Form1 is created by default.
Add a module to the project. Module1 is created by default.
Add the reference to the Virtual Server 2005 Type Library
From the Project menu, choose Properties and define Sub Main as the start-up procedure.
Enter the following sample code into Module1:


Imports System.Reflection
Imports System.Runtime.InteropServices
Imports Microsoft.VirtualServer.Interop

Public Class InitVS

' Create a SUB with PreserveSig:=FALSE so the COM InterOp layer will
' perform the error checking and throw an exception, instead of using 
' a Function and returning an HRESULT.
PreserveSig:=False, _
ExactSpelling:=True, _
EntryPoint:="CoInitializeSecurity", _
CallingConvention:=CallingConvention.StdCall, _
SetlastError:=False)> _
Private Shared Sub CoInitializeSecurity( _
ByVal pSD As IntPtr, _
ByVal cAuthSvc As Int32, _
ByVal asAuthSvc As IntPtr, _
ByVal pReserved1 As IntPtr, _
ByVal dwAuthnlevel As UInt32, _
ByVal dwImpLevel As UInt32, _
ByVal pAuthInfo As IntPtr, _
ByVal dwCapabilities As UInt32, _
ByVal pvReserved2 As IntPtr)
End Sub

Private Const RPC_C_AUTHN_LEVEL_PKT_PRIVACY As Long = 6
Private Const RPC_C_IMP_LEVEL_IMPERSONATE As Long = 3
Private Const EOAC_DYNAMIC_CLOAKING As Long = 64

' Call CoInitializeSecurity with dwImpLevel set to Impersonate. Required by
' the Virtual Server COM Interface
Public Sub New()
CoInitializeSecurity(System.IntPtr.Zero, _
-1, _
System.IntPtr.Zero, _
System.IntPtr.Zero, _
Convert.ToUInt32(RPC_C_AUTHN_LEVEL_PKT_PRIVACY), _
Convert.ToUInt32(RPC_C_IMP_LEVEL_IMPERSONATE), _
System.IntPtr.Zero, _
Convert.ToUInt32(EOAC_CLOAKING), _
System.IntPtr.Zero)
End Sub


'Get VMVirtualServerClass instance from local server using COM
Public Function GetVMVirtualServerClass() As VMVirtualServerClass
GetVMVirtualServerClass = New VMVirtualServerClass
End Function
End Class

Module Module1
_
Sub Main()
' Initialize COM with Impersonate first
Dim myApp As InitVS
myApp = New InitVS

' Connect locally 
Dim myVS As VMVirtualServer
myVS = myApp.GetVMVirtualServerClass()

' Display VS version info
name= myVS.Name
End Sub
End Module 

Answer:

Yes, I am aware of the the CoInitializeSecurity API call and its affect on Virtual server access. Unfortunately, WB like many COM clients does not use this technique to initialize the COM system in its process space. The alternative is, as I suggested in the previous post, to modify the default security that the COM clients are running under. (This does work. I just do not remember the details.)

With Windows there is almost always more than one answer and very seldom just "the answer". But if demand is sufficient, the alternative COM initialization may be provided as a user option in some future version of WB.

Here is an MSFT article that discusses using the DCOMCNFG utility to set security

http://msdn.microsoft.com/library/en-us/dncomg/html/msdn_practicom.asp


Article ID:   W17100
File Created: 2007:07:03:14:28:18
Last Updated: 2007:07:03:14:28:18