Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

InstallScript and folder permission


2 replies to this topic

n_guerin

n_guerin
  • Full Members
  • 2 posts

Posted 25 October 2012 - 16:22

Hello !

I'm working on InstallShield 2009 (Version 15), and I've been trying to use InstallScript for a few days, without success until now...

The idea is simple and has already been raised in previous topics : I need to give full permissions to user for a specific folder during the set-up.
Typically, in a batch script, it would be the following command :
cacls "c:\my folder" /T /E /G "Users":F

I want to insert this instruction in the set-up produced by InstallShield, and therefore to edit the existing InstallScript.
I added a custom function, setUserRights, which I integrated in the set-up.

But I can't find the right code for this function ...

I noticed there exists built-in functions that can do it now (setObjectPermissions), but unfortunately, they do not seem to exist for InstallShield 2009 (and I cannot upgrade it for a lot of good and bad reasons...).

In previous topics, it was suggested to use the cacls exe file :
QUOTE

Prog = "cacls";
s = "C:\myDirectory";
CmdLine = s + " /e /t /g " + myGroupname+":f";
LaunchAppAndWait ( Prog , CmdLine , LAAW_OPTION_WAIT );


I tried with this code ; but it had no effect.
In order to get more information, I tried to create a batch script file (.bat), to write the right line of code into it, and to launch it.
This is the code I wrote :
(knowing that INSTALLDIR is worth something like "C:\Program Files\My Folder\")

CODE

#include "Ifx.h"

#define TEMP_SCRIPT_DIR  "C:\\"
#define TEMP_SCRIPT_FILE "temp_script.bat"

export prototype SetUserRights(HWND);

function SetUserRights(hMSI)  
   STRING  szTitle, szMsg, tempString;
   NUMBER  nvFileHandle;
begin    
   OpenFileMode (FILE_MODE_APPEND);        

   // Create a new file and leave it open.  
   if (CreateFile (nvFileHandle, TEMP_SCRIPT_DIR, TEMP_SCRIPT_FILE) < 0) then      
       // Report the error.    
       MessageBox ("CreateFile failed.", SEVERE);  
       abort;    
   else                                  
       // Set the message to write to the file.
       tempString = INSTALLDIR;
       //we need to remove the last slash because cacls does not accept it
       StrRemoveLastSlash (tempString);  
       szMsg = "cacls \"" + tempString + "\" /e /t /g Users:f";      

       // Append the message to the file.              
       if (WriteLine(nvFileHandle, szMsg) < 0) then    
           // Report the error.                      
           MessageBox ("WriteLine failed.", SEVERE);    
       else                          
           // Report success.          
           szTitle = "CreateFile & WriteLine";    
           szMsg   = "Successfully created and wrote to %s.";    
           SprintfBox (INFORMATION, szTitle, szMsg, TEMP_SCRIPT_FILE);
       endif;              
   endif;                  

   // Close the file.    
   CloseFile (nvFileHandle);

   if (LaunchAppAndWait ( TEMP_SCRIPT_DIR^TEMP_SCRIPT_FILE, "" , LAAW_OPTION_WAIT ) < 0) then
    MessageBox("Unable to launch temp script.", WARNING);    
   else        
       // Report success.  
     SprintfBox (INFORMATION, "Success", "Success");
  endif;
end;


Unfortunately, this is not working either : the message boxes indicate success, the batch script is created and filled as I wish; but the folder is still not in full access for the Users group.
Right after the installation, I tried to execute the batch script that had been created : it works fine.

So, I guess the install script does not manage to launch the batch script.
Isn't it the right way to do it ? Does anyone find anything wrong in the code ?
Or has got a working suggestion ?

Thanks in advance for any help !
Nicolas

Taco Bell

Taco Bell

    IS6 Expert

  • Moderators
  • 1,281 posts

Posted 26 October 2012 - 13:21

First off, you could add like a pause command to your batch file to further debug the problem and ensure it's actually being ran.

I've always just used WAIT instead of LAAW_OPTION_WAIT for LaunchAppAndWait()'s nOptions parameter though, so I would try that instead.

If you still have problems, then you can also check the value of LAAW_PARAMETERS.nLaunchResult for the launched application's error code and ensure the cacl's return code is passed back in the case of a batch file.
user posted image

n_guerin

n_guerin
  • Full Members
  • 2 posts

Posted 26 October 2012 - 14:26

Thank you for your help !

Indeed, I did not know the pause command (I'm not used to batch scripts...), very useful in that kind of cases !

The actual problem was that my script was executed too soon : before the folder I needed to share had been created.

I had placed this script in the custom actions sequences ; but I had placed it too soon.
It is now corrected, and it works !

Thanks again ! smile.gif