diff --git a/pandora_agents/win32/ChangeLog b/pandora_agents/win32/ChangeLog
index 7395466774..68f67a95a9 100644
--- a/pandora_agents/win32/ChangeLog
+++ b/pandora_agents/win32/ChangeLog
@@ -1,3 +1,11 @@
+2010-06-30  Ramon Novoa  <rnovoa@artica.es>
+
+	* windows/pandora_wmi.cc: getDiskFreeSpacePercent should not return
+	  any value if the drive does not exist. Fixed.
+
+	* modules/pandora_module.h, modules/pandora_module_factory.cc,
+	  modules/pandora_module.cc, pandora_windows_service.cc: Added support
+	  for saving the value of a module as an environment variable. 
 
 2010-06-13  Sancho Lerena <slerena@artica.es>
 
diff --git a/pandora_agents/win32/modules/pandora_module.cc b/pandora_agents/win32/modules/pandora_module.cc
index c88e6ef294..a459ca2991 100644
--- a/pandora_agents/win32/modules/pandora_module.cc
+++ b/pandora_agents/win32/modules/pandora_module.cc
@@ -273,6 +273,36 @@ Pandora_Module::getDataOutput (Pandora_Data *data) {
 	return trim (data->getValue ());
 }
 
+/** 
+ * Export the module output to en environment variable.
+ */
+void
+Pandora_Module::exportDataOutput () {
+	Pandora_Data *pandora_data = NULL;
+	string putenv_str, module_data;
+
+	/* putenv expects a string of the form name=value */
+	putenv_str = this->save + "=";
+	
+	/* No data */
+	if ( (!this->has_output) || this->data_list == NULL) {
+		putenv (putenv_str.c_str ());
+		return;
+	}
+
+	/* Get the module data */
+	pandora_data = data_list->front ();
+	if (pandora_data == NULL) {
+		putenv (putenv_str.c_str ());
+		return;
+	}
+	module_data = pandora_data->getValue ();
+	putenv_str += module_data;
+
+	/* Save it as an environment variable */
+	putenv (putenv_str.c_str ());
+}
+
 /** 
  * Set the output of the module.
  *
@@ -544,3 +574,23 @@ void
 Pandora_Module::setDescription (string description) {
 	this->module_description = description;
 }
+
+/** 
+ * Set the name of the environment variable where the module data will be saved.
+ * 
+ * @param save Name of the environment variable.
+ */
+void
+Pandora_Module::setSave (string save) {
+	this->save = save;
+}
+
+/** 
+ * Get the name of the environment variable where the module data will be saved.
+ * 
+ * @return The name of the environment variable.
+ */
+string
+Pandora_Module::getSave () {
+	return this->save;
+}
diff --git a/pandora_agents/win32/modules/pandora_module.h b/pandora_agents/win32/modules/pandora_module.h
index 25157d7d1e..191441baa6 100644
--- a/pandora_agents/win32/modules/pandora_module.h
+++ b/pandora_agents/win32/modules/pandora_module.h
@@ -139,6 +139,7 @@ namespace Pandora_Modules {
 		Module_Type           module_type;
 		string                module_kind_str;
 		Module_Kind           module_kind;
+		string                save;
 
 	protected:
 		
@@ -191,7 +192,8 @@ namespace Pandora_Modules {
 		int          getInterval   ();
 		void         setTimeout    (int timeout);
 		int          getTimeout    ();
-		
+		string       getSave ();
+
 		virtual string getXml      ();
 
 		
@@ -209,13 +211,16 @@ namespace Pandora_Modules {
 		Module_Type getTypeInt     () const;
 		Module_Type getModuleType  () const;
 		Module_Kind getModuleKind  () const;
-		
+
 		void        setType        (string type);
 		void        setKind        (string kind);
 		void        setDescription (string description);
 		void        setMax         (int value);
 		void        setMin         (int value);
 		void        setAsync       (bool async);
+		void        setSave        (string save);
+
+		void        exportDataOutput ();
 	};
 }
 
diff --git a/pandora_agents/win32/modules/pandora_module_factory.cc b/pandora_agents/win32/modules/pandora_module_factory.cc
index 9b877aba84..2e961669c2 100644
--- a/pandora_agents/win32/modules/pandora_module_factory.cc
+++ b/pandora_agents/win32/modules/pandora_module_factory.cc
@@ -80,6 +80,7 @@ using namespace Pandora_Strutils;
 #define TOKEN_TIMEOUT       ("module_timeout ")
 #define TOKEN_REGEXP        ("module_regexp ")
 #define TOKEN_PLUGIN        ("module_plugin ")
+#define TOKEN_SAVE          ("module_save ")
 
 string
 parseLine (string line, string token) {
@@ -122,7 +123,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
 	string                 module_retries, module_startdelay, module_retrydelay;
 	string                 module_perfcounter, module_tcpcheck;
 	string                 module_port, module_timeout, module_regexp;
-	string                 module_plugin;
+	string                 module_plugin, module_save;
 	Pandora_Module        *module;
 	bool                   numeric;
 	Module_Type            type;
@@ -159,6 +160,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
 	module_timeout       = "";
 	module_regexp        = "";
 	module_plugin        = "";
+	module_save        = "";
 	
 	stringtok (tokens, definition, "\n");
 	
@@ -280,6 +282,9 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
 		if (module_plugin == "") {
 			module_plugin = parseLine (line, TOKEN_PLUGIN);
 		}
+		if (module_save == "") {
+			module_save = parseLine (line, TOKEN_SAVE);
+		}
 
 		iter++;
 	}
@@ -378,6 +383,10 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
 	if (module_description != "") {
 		module->setDescription (module_description);
 	}
+
+	if (module_save != "") {
+		module->setSave (module_save);
+	}
 	
 	if (module_async != "") {
 		module->setAsync (true);
diff --git a/pandora_agents/win32/pandora_windows_service.cc b/pandora_agents/win32/pandora_windows_service.cc
index d37db09d20..9b1a32f345 100644
--- a/pandora_agents/win32/pandora_windows_service.cc
+++ b/pandora_agents/win32/pandora_windows_service.cc
@@ -570,7 +570,7 @@ Pandora_Windows_Service::checkConfig () {
 	int i, conf_size;
 	char *conf_str = NULL, *remote_conf_str = NULL, *remote_conf_md5 = NULL;
 	char agent_md5[33], conf_md5[33], flag;
-	string conf_file, conf_tmp_file, md5_tmp_file, temp_dir, tmp;
+	string agent_name, conf_file, conf_tmp_file, md5_tmp_file, temp_dir, tmp;
 
 	tmp = conf->getValue ("remote_config");
 	if (tmp != "1") {
@@ -590,9 +590,16 @@ Pandora_Windows_Service::checkConfig () {
 
 	/* Get agent name */
 	tmp = conf->getValue ("agent_name");
-	if (tmp == "") {
+	if (tmp.empty ()) {
 		tmp = Pandora_Windows_Info::getSystemName ();
 	}
+	agent_name = tmp;
+	
+	/* Error getting agent name */
+	if (tmp.empty ()) {
+		pandoraDebug ("Pandora_Windows_Service::checkConfig: Error getting agent name");
+		return;
+	}
 
 	Pandora_File::md5 (tmp.c_str(), tmp.size(), agent_md5);
 
@@ -675,7 +682,7 @@ Pandora_Windows_Service::checkConfig () {
 		return;
 	}
 
-	pandoraLog("Pandora_Windows_Service::checkConfig: Configuration has changed");
+	pandoraLog("Pandora_Windows_Service::checkConfig: Configuration for agent %s has changed", agent_name.c_str ());
 
 	/* Get configuration file from server */
 	try {
@@ -849,7 +856,12 @@ Pandora_Windows_Service::pandora_run () {
 		
 			pandoraDebug ("Run %s", module->getName ().c_str ());
 			module->run ();
-		
+			
+			/* Save module data to an environment variable */
+			if (!module->getSave().empty ()) {
+				module->exportDataOutput ();
+			}
+
 			this->modules->goNext ();
 		}
 	}
diff --git a/pandora_agents/win32/windows/pandora_wmi.cc b/pandora_agents/win32/windows/pandora_wmi.cc
index c7034b17d6..804d823d23 100644
--- a/pandora_agents/win32/windows/pandora_wmi.cc
+++ b/pandora_agents/win32/windows/pandora_wmi.cc
@@ -183,7 +183,6 @@ Pandora_Wmi::getDiskFreeSpacePercent (string disk_id) {
 	CDhInitialize      init;
 	CDispPtr           wmi_svc, quickfixes;
 	double      free_space = 0, size = 0;
-	double      total_free_space = 0, total_size = 0;
 	string             query;
 
 	query = "SELECT Size, FreeSpace FROM Win32_LogicalDisk WHERE DeviceID = \"" + disk_id + "\"";
@@ -200,15 +199,12 @@ Pandora_Wmi::getDiskFreeSpacePercent (string disk_id) {
 			dhGetValue (L"%e", &size, quickfix,
 				    L".Size");
 
-            total_free_space += free_space;
-            total_size += size;
+			if (size == 0) {
+				return 0;
+			}
+
+			return (unsigned long) (free_space * 100 / size);
 		} NEXT_THROW (quickfix);
-		
-		if (total_size == 0) {
-            return 0;
-        }
-        
-        return (unsigned long) (total_free_space * 100 / total_size);
 	} catch (string errstr) {
 		pandoraLog ("getDiskFreeSpace error. %s", errstr.c_str ());
 	}