DECLARE @procedure varchar(255),                                                                    
         @objectName varchar(30),                                                                    
         @file varchar(255),                                                                         
         @user varchar(30)                                                                           
 SET NOCOUNT ON                                                                                      
  DECLARE object_cursor CURSOR
  FOR                                                                                                
  SELECT DISTINCT o.name, c.text, u.name                                                             
  FROM master..sysobjects o, master..syscomments c,                                                  
       master..sysprotects p, master..sysusers u                                                     
  WHERE c.id = o.id                                                                                  
  AND p.id = o.id                                                                                    
  AND p.uid = u.uid                                                                                  
  AND o.type = "X"                                                                                   
  AND o.category = 0                                                                                 
 OPEN object_cursor                                                                                  
   FETCH NEXT FROM object_cursor INTO @objectName, @file, @user                                      
     WHILE (@@fetch_status <> -1)                                                                    
       BEGIN                                                                                         
         SELECT @procedure = "EXECUTE sp_addextendedproc " + CHAR(39) +                              
                             @objectName + CHAR(39) + ", " + CHAR(39) +                              
                             @file + CHAR(39)                                                        
         PRINT @procedure                                                                            
         PRINT "GO"                                                                                  
         SELECT @procedure = "GRANT EXECUTE  ON master.." +                                          
                             @objectName + " TO " + @user                                            
         PRINT @procedure                                                                            
         PRINT "GO"                                                                                  
         PRINT ""                                                                                    
     	 FETCH NEXT FROM object_cursor INTO @objectname, @file, @user                                  
      END                                                                                            
 DEALLOCATE object_cursor