CreateObject and GetObject fails when launched using CreateProcess
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: CreateObject and GetObject fails when launched using CreateProcess

  1. #1
    Join Date
    Dec 2009
    Posts
    1

    CreateObject and GetObject fails when launched using CreateProcess

    I am having some issues under Windows Vista and Windows 7 with an application that used to work just fine under Windows XP.

    The projects consists of a GUI and a command line utility. When the CLU is launched stand-alone from explorer or the command shell it works fine under all versions of Windows. However, when it is launched from the GUI using CreateProcessA, I have the following problems:

    1) Under Windows Vista, when trying to use the CoGetObject api to obtain a reference to winmgmts, I get an "automation error".

    2) Under Windows 7, I also get an "automation error" when trying to use CoCreateInstance to retrieve an instance of Scripting.FileSystemObject.

    The actual CreateProcessA call seems to work fine, the application is launched and the pipes work fine. As previously mentioned it works perfectly under Windows XP. Seems to me this problem is security or context related.

    The code below is VB6, sorry about that, but the problem has been verified with C++ using equivalent code and I am convinced the users in this part of the forum are alot more qualified to answer questions regarding windows api's. I hope you'll be able to do a mental translation of the code.

    GUI:

    Dim PID As Long, hPipe As Long
    Dim cmdLine As String

    cmdLine = buildCmdLine()

    pa.nLength = Len(pa)
    pa.bInheritHandle = 1

    pra.nLength = Len(pra)
    tra.nLength = Len(tra)

    CreatePipe hRead, hWrite, pa, 0

    If hRead = 0 Or hWrite = 0 Then Err.Raise hErrBase

    sui.cb = Len(sui)
    GetStartupInfoA sui
    sui.hStdOutput = hWrite
    sui.hStdError = hWrite
    sui.dwFlags = STARTF_USESHOWWINDOW Or STARTF_USESTDHANDLES
    sui.wShowWindow = SW_HIDE

    PID = CreateProcessA(0&, cmdLine, pra, tra, 1, 0, 0&, 0&, sui, pi)

    If PID = 0 Then Err.Raise hErrBase

    CLU:

    Set oFSO = CreateObject("Scripting.FileSystemObject")

    ... and ...

    Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!//./root/cimv2")

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,473

    Re: CreateObject and GetObject fails when launched using CreateProcess

    To determine if this is a permissions issue, right click on your program and choose "run as adminstrator", if it runs, you know you have a permissions issue.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center