Community Forums
Page 1 of 2 12 LastLast
Results 1 to 5 of 15

Thread: ServiceAddService returns -1

Hybrid View

  1. #1
    Join Date
    Feb 2008
    Posts
    54

    ServiceAddService returns -1

    Hello,

    ServiceAddService return -1. This is no >= ISERR_SUCCESS. And Format function gives no text message for this code. What does this code mean?

  2. #2
    Join Date
    Jul 2003
    Location
    Austin, TX
    Posts
    4,436
    Can you tell us what project type it is and a code snippet? If MSI, how are you scheduling it?
    Christopher Painter
    ISWIX, LLC.
    Visit iswix.com for contact information

  3. #3
    Join Date
    Feb 2008
    Posts
    54
    Yes, this is a Basic MSI type.

    As far as I remember (I am now at home and will check it tomorrow and send a snippet) it is scheduled after InstallServices action.

    And in fact it is installed despite -1 error code and successfully started.

  4. #4
    Join Date
    Feb 2008
    Posts
    54
    Here is the whole function that installs Windows Service with relevant comments:

    Code:
    //
    // Installs QEF as Windows service.
    // This CA is deferred and used after InstallServices and SetInstallWindowsServiceData actions.
    //
    function InstallWindowsService(hMSI) 
        LIST lCustomActionData; // CA data list 
        STRING svServiceName, // QEF Windows service name
        	svDisplayName, // QEF Windows service display name
        	svDescription; // QEF Windows service description
        STRING svCustomActionData, // CA data string
        	svBinDir, // Bin directory
        	svAccountType, // QEF Windows service account type
        	svLogin, // QEF Windws service login
        	svPassword, // QEF Windws service password
        	svStartupType, // QEF Windws service startup type 
        	svStartAfterInstall; // QEF Windws service start after insttallation value
        STRING svScriptFile, // script file in which the error occurred
        	svError, // error code for the error
        	svErrorMessage; // error message
        NUMBER nvSize, // size of buffer used to get MSI properties 
        	nResult, // result code 
        	nAccountType, // QEF Windows service account type 
        	nStartupType; // QEF Windws service startup type  
        NUMBER nvLineNumber, // line number in which the error occurred
        	nvError; // error code for the error
        BOOL bStartAfterInstall; // QEF Windws service start after insttallation value 
    begin	
    	svServiceName = "QEF";                
    	svDisplayName = "QualiWare Execution Framework"; 
    	svDescription = "Enables deployment of QualiWare modules, management of user and groups, security and licensing, logging and monitoring.";
        
        // Check if QEF Windows service is already installed.
    	if(ServiceExistsService(svServiceName) = TRUE) then
    		MessageBox("Cannot install Windows Servcie, because Windows Service with name \"" + svServiceName + "\" already exists!", WARNING);
    		
    		return NOTHING;
    	endif;             
          
        nvSize = 256;    
        nvError = -1;
        
        // Get CA data as a string.     
        nResult = MsiGetProperty(hMSI, "CustomActionData", svCustomActionData, nvSize);
        if(nResult != ERROR_SUCCESS) then
        	MessageBox("Cannot get CA data!", SEVERE); 
        endif;                                        
        
        // Convert CA data from string to list.
        lCustomActionData = ListCreate(STRINGLIST);
        
        if (StrGetTokens(lCustomActionData, svCustomActionData, ";") > 0) then 
            MessageBox ("Failed to get tokens from string!", SEVERE); 
        endif;
        
        // Get Bin directory from CA data list.
        nResult = ListGetFirstString(lCustomActionData, svBinDir);
        if(nResult = -1) then
        	MessageBox("Cannot get Bin directory path!", SEVERE); 
        endif;  
        
        // Get QEF Windows service accoount type from CA data list.
        nResult = ListGetNextString(lCustomActionData, svAccountType);
        if(nResult = -1) then
        	MessageBox("Cannot get Windows service account type!", SEVERE); 
        endif; 
        
        // Get QEF Windows service login from CA data list.
        nResult = ListGetNextString(lCustomActionData, svLogin);
        if(nResult = -1) then
        	MessageBox("Cannot get Windows service login!", SEVERE); 
        endif; 
        
        // Get QEF Windows service password from CA data list.
        nResult = ListGetNextString(lCustomActionData, svPassword);
        if(nResult = -1) then
        	MessageBox("Cannot get Windows service password!", SEVERE); 
        endif;               
        
        // Get QEF Windows service startup type from CA data list.
        nResult = ListGetNextString(lCustomActionData, svStartupType);
        if(nResult = -1) then
        	MessageBox("Cannot get Windows service startup type!", SEVERE); 
        endif;  
        
        // Get QEF Windws service start after insttallation value from CA data list.
        nResult = ListGetNextString(lCustomActionData, svStartAfterInstall);
        if(nResult = -1) then
        	MessageBox("Cannot get Windows service start after install value!", SEVERE); 
        endif;
         
        // Destroy CA data list.
        ListDestroy (lCustomActionData); 
        
        // Convert QEF Windows service account type from string to integer.
        StrToNum(nAccountType, svAccountType);
        
        // Set QEF Windows service login and password if account type is set to user account.
        if(nAccountType = 1) then
    	    SERVICE_IS_PARAMS.lpServiceStartName = &svLogin;
    	    SERVICE_IS_PARAMS.lpPassword  = &svPassword;
        endif;
        
        // Convert QEF Windows service startup type from string to integer.
        StrToNum(nStartupType, svStartupType);
        
        // Set QEF Windows service startup type.
        switch(nStartupType)
        	case 0:  
        		SERVICE_IS_PARAMS.dwStartType = SERVICE_AUTO_START;
        	case 1:                          
        		SERVICE_IS_PARAMS.dwStartType = SERVICE_DEMAND_START;
        	case 2:                          
        		SERVICE_IS_PARAMS.dwStartType = SERVICE_DISABLED;
        endswitch;
        
        // Convert QEF Windows service start after insttallation value from string to integer.
        StrToNum(bStartAfterInstall, svStartAfterInstall);
    	
    	
    	nvError = ServiceAddService(svServiceName, svDisplayName, svDescription, svBinDir ^ "Qef.exe /RunAsService", bStartAfterInstall, "");
    	NumToStr(svError, nvError);     
    	MessageBox("Exit code: " + svError, INFORMATION);
    	NumToStr(svError, ISERR_SUCCESS);     
    	MessageBox("ISERR_SUCCESS code: " + svError, INFORMATION);
    	// Add QEF Windows service to the list of services to install.
    	if(nvError < ISERR_SUCCESS) then
    		svErrorMessage = "Windows sevice \"" + svServiceName + "\" cannot be installed!";
    		GetExtendedErrInfo(svScriptFile, nvLineNumber, nvError);
    		NumToStr(svError, nvError);
    		if(nvError = 1057) then // 1069 - wrong password
    			svErrorMessage = svErrorMessage + " The account name is invalid or does not exist!";
    		elseif(nvError = 1069) then
    			svErrorMessage = svErrorMessage + " The service did not start due to a logon failure!";
    		elseif(nvError = 2) then
    			svErrorMessage = "";
    		else
    			svErrorMessage = svErrorMessage + " Error code: " + svError;
    		endif;  
    		
    		MessageBox(svErrorMessage, WARNING);
    	endif;
    end;

  5. #5
    Join Date
    Jul 2003
    Location
    Austin, TX
    Posts
    4,436
    If your using Basic MSI, what problem are you trying to solve that requires you to roll all of this code instead of just using the ServiceInstall table?
    Christopher Painter
    ISWIX, LLC.
    Visit iswix.com for contact information

Page 1 of 2 12 LastLast

Posting Permissions

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