Wednesday, December 29, 2010

Checking the version of Windows Installer on a machine.

Often, we need to know what version of windows Installer is available on a machine. Valid scenario's are like if we want some features of our installshield product specific to a Windows Installer version.


For this, go to Windows\System 32 folder. Look for MSI.DLL and check its version. If the version is 3.1.4000.2435, you have the latest version.


One common point of confusion is that even if you have the latest version of Windows Installer 3.1 on your system and you type in msiexec.exe /? from a command-window, you will still be told that you are on version 3.1.4000.1823 or 3.1.4000.1830. This is because msiexec.exe /? will only give you the version of msiexec on the system -- not the other Windows Installer-related dll's. (The version of msiexec was not updated to 3.1.4000.2435 with the (v2) redistributable, just msi.dll was updated.)"


VB Script:

I found a neat .vbs browser hosted script fo this. Save the following code as .htm
<html>
<head>
<script language="vbscript">
sub document_onclick()
set installer = createobject("windowsinstaller.installer")
msgbox installer.version
end sub
</script>
</head>
<body>
Click me for Windows Installer version...
</body>
</html>


and you are done:-). Note that the "windowsinstaller.installer" object is not marked safe for scripting in IE browser hosted script... Double click the saved htm file and then you need to click the information bar to allow the blocked ActiveX control in IE.

Friday, October 15, 2010

Validate Windows Service User Account

Hi Friends, in many of my projects, we need to create windows service, ask credentials for running the service. I spent a lot of time in my initial stage of profession for implementing it according to the choice of the user.


Scenario:
There was a scenario, where user needs to put a choice by means of installer, whether he needs to install an run the services on behalf of Local Account, or by entering the Windows Domain Account credentials for running the service.


Solution:
I write a Installscript custom action after a lot of R&D on net for the scenario when we ask custom credentials by user.


Description:
ValidateWindowsServiceUserAccount() -- custom function which we need to call from our script.
gsServiceAccountUserName -- global variable which i had used to store the credentials which were a mix of Domain + Windows account e.g. Domain\John.Natham.


function ValidateWindowsServiceUserAccount()
    OBJECT objDSO, objDomain;
    LIST listID;
    NUMBER iIndex, nResult;
    STRING sArray(), svString, strDomain, strWinServiceUser,szMsg;
begin
try
   set objDSO = CoGetObject("WinNT:","");
   if (!IsObject(objDSO)) then
      //MessageBox("Object NOT Created", 0);
   else
      //Break User name in domain and user
      listID = ListCreate (STRINGLIST);      
      if (StrGetTokens (listID, gsServiceAccountUserName, "\\") < 0) then
         //Error
      else
         //Success
         iIndex=0;
         nResult = ListGetFirstString(listID, svString);
         while (nResult != END_OF_LIST)
              //nitems=nitems+1;
              Resize(sArray,iIndex+1);
              sArray(iIndex)=svString;
              iIndex = iIndex+1;
              nResult = ListGetNextString (listID, svString);
         endwhile;
      endif;      
      ListDestroy (listID);
      strDomain = sArray(0);
      strWinServiceUser = sArray(1);
      //
      set objDomain = objDSO.OpenDSObject("WinNT://" + strDomain,
                            strWinServiceUser, gsServiceAccountPassword, 1);

      gbValidWinServiceUser = TRUE;
      //set objDSO = Nothing
      //set objDomain = Nothing
   endif;
catch
    gbValidWinServiceUser = FALSE;
    //MessageBoxEx(Err.Number,"",INFORMATION);
   switch (Err.Number)
       case "-2147023570":
            szMsg = "Invalid user name or password.";
            ListAddString(gLIST_VALIDATION_ERROR,"- "+szMsg,AFTER);
            //MessageBoxEx("Invalid user name or password.","",SEVERE);
       case "-2147022987":
            szMsg = "User account is locked.";
            ListAddString(gLIST_VALIDATION_ERROR,"- "+szMsg,AFTER);
            //MessageBoxEx("User account is locked.","",SEVERE);
       case "-2147023565":
            szMsg = "User account is disabled.";
            ListAddString(gLIST_VALIDATION_ERROR,"- "+szMsg,AFTER);
       default:
            szMsg = "Unknown error, unable to verify credentials.";
            ListAddString(gLIST_VALIDATION_ERROR,"- "+szMsg,AFTER);
    endswitch;
endcatch;
end;

Tuesday, September 28, 2010

Check if a windows process is running...

Hello Friends,
     During one of my project a requirement comes across to know whether a process is currently running on your machine or not. I looked across a number of sites, but none proved to be useful to me. But in the last I got some useful scripts which proved to be very efficient when applied through installscipt code.

The below script is in vb, which you could use through vbscript type custom action in your installshield project. In th variable PROCESS_NAME, you need to replace it by your process name, which you are looking for.

set service = GetObject ("winmgmts:")
for each Process in Service.InstancesOf ("Win32_Process")
      If Process.Name = "PROCESS_NAME" then
          wscript.echo "mmc running"
          wscript.quit             -- Here script will terminate
      End If
next

wscript.echo "mmc not running"         -- This code will execute if process is not running