Loading
CoGetObject fails on 64bit OS - checking if process running
So huge thanks to 'Super User Reureu,' I can now check to see if my application is running before I allow my install program to continue. It works perfect on windows xp, 32bit. Unfortunately, it always fails on the CoGetObject line. I tried to 'run as administrator' but that didn't help. [one of my coworkers thought I didn't have permissions to create the object...]

 

 

prototype ISGetObj.ForEachStart(byref OBJECT, byref VARIANT);

 

prototype ISGetObj.ForEachGetNextItem(byref VARIANT, byref OBJECT);

 

function BOOL FindRunningProcess()

 

OBJECT obj, WMI, slist;

 

STRING szSupportDir, szDllname, szMessage, szMsg1, szMsg2, szMsg3, szMsg4;

 

STRINGszProcessName;

 

NUMBERnResult;

 

VARIANT __varEnumHolder;

 

STRING query;

 

INT nCnt, openDllSuccess;

 

BOOL bStatus;

 

begin

 

szProcessName = "MyProgram.exe";

 

bStatus = FALSE;

 

nCnt = 0;

 

// Load IsGetObj.dll

 

szDllname = SUPPORTDIR ^ "IsGetObj.dll";

 

openDllSuccess = UseDLL(szDllname);

 

if (openDllSuccess != 0) then

 

Sprintf(szMessage, "Could not open %s.", szDllname );

 

nResult = WriteLine(glLogFile, szMessage);

 

szMsg1 = "An error occurred checking if MyProgram.exe is already running. ";

 

nResult = AskYesNo(szMsg1, NO);

 

if (nResult = NO) then

 

nResult = WriteLine(glLogFile, "User elected to Exit the setup process.");

 

mpx_Cleanup();

 

abort;

 

else // YES

 

nResult = WriteLine(glLogFile, "User elected to Continue the setup process.");

 

endif;

 

else

 

try

 

// Get the Windows Management Instrumentation (WMI) object

 

set WMI = CoGetObject("winmgmts:{impersonationLevel=impersonate}!//./root/cimv2", "" );

 

// Verify that the object was created

 

if (!IsObject(WMI)) then

 

nResult = WriteLine(glLogFile, "WMI was not created.");

 

szMsg1 = "An error occurred checking if MyProgram.exe is already running. ";

 

nResult = AskYesNo(szMsg1, NO);

 

if (nResult = NO) then

 

nResult = WriteLine(glLogFile, "User elected to Exit the setup process.");

 

mpx_Cleanup();

 

abort;

 

else // YES

 

nResult = WriteLine(glLogFile, "User elected to Continue the setup process.");

 

endif;

 

endif;

 

// Search for selected process

 

query = "Select * From Win32_Process Where Name Like '" + szProcessName + "'";

 

set slist = WMI.ExecQuery (query);

 

// Count the number of processes that have the selected name

 

ForEachStart(slist, __varEnumHolder);

 

while(ISERR_SUCCESS == ForEachGetNextItem(__varEnumHolder, obj))

 

nCnt++;

 

endwhile;

 

// Cleanup

 

set __varEnumHolder = NOTHING;

 

catch

 

nResult = WriteLine(glLogFile, "Exception raised when querying the Process list.");

 

szMsg1 = "An error occurred checking if MyProgram.exe is already running. ";

 

nResult = AskYesNo(szMsg1, NO);

 

if (nResult = NO) then

 

nResult = WriteLine(glLogFile, "User elected to Exit the setup process.");

 

abort;

 

else // YES

 

nResult = WriteLine(glLogFile, "User elected to Continue the setup process.");

 

endif;

 

endcatch;

 

UnUseDLL("IsGetObj.dll");

 

endif;

 

if (nCnt != 0) then

 

bStatus = TRUE;

 

szMessage = szProcessName + " found in WMI's Win32_Process list. MPX is running." ;

 

nResult = WriteLine(glLogFile, szMessage);

 

else

 

bStatus = FALSE;

 

szMessage = "Could not find " + szProcessName + " in WMI's Win32_Process list. MPX is not running.";

 

nResult = WriteLine(glLogFile, szMessage);

 

endif;

 

 

// Return the result

 

return bStatus;

 

end;

  • Could it be due to the problem described here?

     

    http://stackoverflow.com/questions/2429477/cannot-use-createobject-from-vb-scripts-on-windows-7

     

    Am I right in thinking that you are working on a pure InstallScript project?

     

    This code works fine in a Basic MSI project when running on x64 OS.

     

    Does the attached VB Script works on your x64 OS?

     

    This little script does not do much more than your IS code. So, if this script works on your x64 OS, then I would assume that your InstallScript code should work.

     

    By the way, I would not call AskYesNo before checking whether that's a silent installation if I were you, but that's a different point.
    Expand Post
  • Yes, I have a pure InstallScript project.

     

    I have no idea how to check if the attached VB Script works on our x64 OS.

     

    the script code works perfect on windows xp 32-bit. It seems logical that something akin to the issue referenced in the article you mentioned is the cause of the problem. We have found that IS isn't really ready for 64bit or 64bit applications natively.

     

    All I know right now is that after [set WMI = CoGetObject("winmgmts:{impersonationLevel=impersonate}!//./root/cimv2", "" );]

     

    IsObject(WMI) is always false on win7, 64bit.

     

    I don't know how to make it work.

     

    Side note: I don't check if its a silent install or not - the askyesno is there as a backup catch so that if there is an error checking if the application is running (like I am encountering now), the user has the opportunity to exit the install and stop the program before continuing. Bad things happen if the installer is run while the applciation is running, which is why I want to programmatically add this check.

     

    thanks for your help.
    Expand Post
  • It is the script I have been using in our Basic MSI project for a while, and never had the issue you are facing.

     

    I have also tested your IS code in a dummy InstallScript project. It works fine on Win7 x64.

     

    I assume you are facing a different problem. Have you tried on a different x64 machine?
    Expand Post
  • Hi -

     

    I did try it on another machine and got the same results.

     

    I also created a new InstallScript project with just 2 routines OnSetUpdateMode and FindRunningProcess. The project worked fine!

     

    Now to figure out why in the real project it doesn't work. I simply did a cut and paste of the routine for the test project that worked.

     

    TLM
    Expand Post
  • Reureu - thank you so mcuh for your PATIENCE.

     

    Turns out the problem is that an earlier call in OnSetUpdatemode() that we added called Disable(WOW64FSREDIRECTION); Once I moved the call to FindRunningProcess() [the routine that checks for the exe running] before the call to the routine that called Disable, it worked fine.

     

    yeah
    Expand Post

Loading
CoGetObject fails on 64bit OS - checking if process running