設置目錄的權限

 

///////////////////////////////////////////////////////////////////////////////
//                                                                          
// Function:  MyFunction
//                                                                          
//  Purpose:  This function will be called by the script engine when
//            Windows(TM) Installer executes your custom action (see the "To
//            Do," above).
//                                                                          
///////////////////////////////////////////////////////////////////////////////
function MyFunction(hMSI)  
  string svFolderOrFile;
  string svUserRights;
  string svTmp;    
  string svAccountIUSR;
  number iReturn;
begin
  //Set 'full control' for user IUSR/IWAM accounts for the installation
  //folder
  //svFolderOrFile = INSTALLDIR;   
  svFolderOrFile = TARGETDIR ^ "//db";    //安裝目錄下的db文件夾
  svUserRights = "/T /E /G";
 
  //Retrieve and add IUSR and IWAM machine accounts
  if(W3SVCGetAccountNameIUSR(svAccountIUSR) = ERROR_SUCCESS) then
    Sprintf(svTmp, "%s %s:F", svUserRights, svAccountIUSR);
    svUserRights = svTmp;
  endif;


   //SprintfBox(INFORMATION, "userrights", "%s", svUserRights);
  iReturn = SetUserRights(hMSI, svFolderOrFile, svUserRights); //安裝目錄的權限
 
  return(iReturn);
  end;                     

///////////////////////////////////////////////////////////////////////////////
//                                                                          
// Function:  SetUserRights
//                                                                          
//  Purpose:  This function uses the utility cacls.exe to adjust user rights
//            on the folder(s)/file(s) specified.
//                                                                          
///////////////////////////////////////////////////////////////////////////////
function SetUserRights(hMSI, sFolderOrFile, sUserRights)
  string svCACLSApplication;
  string svCACLSParams;
  string svStdOut;
  number iReturn;
begin   
  //cacls.exe <folder or file> /T /E /G ASPNET:R
  svCACLSApplication = WINSYSDIR ^ "//cacls.exe";
  if (Is(FILE_EXISTS, svCACLSApplication)) then
    if (Is(PATH_EXISTS, sFolderOrFile) || Is(FILE_EXISTS, sFolderOrFile)) then
      //InstallShield has the nasty habit of adding a backslash to the end of
      //path variables, remove this last slash.
      StrRemoveLastSlash(sFolderOrFile);
      //Put quotes around the folder/file name if needed.
      LongPathToQuote(sFolderOrFile, TRUE);
      LongPathToQuote(svCACLSApplication, TRUE);
      Sprintf(svCACLSParams, '%s %s',sFolderOrFile, sUserRights);
      //svCACLSParams = sFolderOrFile + ' ' + sUserRights ;
      iReturn = LaunchAppAndWait(svCACLSApplication, svCACLSParams,
                         LAAW_OPTION_WAIT |
                         LAAW_OPTION_HIDDEN |
                         LAAW_OPTION_SHOW_HOURGLASS |
                         LAAW_OPTION_NO_CHANGEDIRECTORY);
     
      if ((iReturn < 0) || (LAAW_PARAMETERS.nLaunchResult!=0)) then
        SprintfBox(WARNING, "Adjusting file/folder persmissions", "Adjusting " +
        "permissions for file/folder %s failed, the error codes are %d en %d.",
         sFolderOrFile, iReturn, LAAW_PARAMETERS.nLaunchResult);
        iReturn = LAAW_PARAMETERS.nLaunchResult;
      endif;
    else
      SprintfBox(SEVERE, "Adjusting file/folder persmissions", "Adjusting " +
        "file/folder permissions failed, specified path %s does not exist.",
         sFolderOrFile);
      return(ERROR_PATH_NOT_FOUND);
    endif;
  else
    SprintfBox(SEVERE, "Adjusting file persmissions", "Adjusting " +
      "file/folder permissions failed, required application %s could not be found.",
      svCACLSApplication);
      return(ERROR_FILE_NOT_FOUND);
  endif;
 
  return(iReturn);
end;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章