SetupFactory-脚本

本文详细介绍了如何使用注册表进行文件操作,包括注册表的创建、设置值、检查Oracle客户端是否安装、下载文件、添加Oracle连接串和修改hosts文件等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、写注册表

lResult = Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, "SOFTWARE\\MapInfo\\MapX\\5.0");
if not lResult then
 Registry.CreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\MapInfo\\MapX\\5.0");
end;
Registry.SetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\MapInfo\\MapX\\5.0", "ProgramDir", "C:\\Program Files\\MapInfo\\MapX 5.0", REG_MULTI_SZ);
Registry.SetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\MapInfo\\MapX\\5.0", "SearchPaths", "", REG_MULTI_SZ);
Registry.SetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\MapInfo\\MapX\\5.0", "GeoDictionary", "", REG_MULTI_SZ);
Registry.SetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\MapInfo\\MapX\\5.0", "VersionCode", "5.02", REG_MULTI_SZ);
Registry.SetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\MapInfo\\MapX\\5.0", "CommonDLLDir", "C:\\Program Files\\MapInfo\\MapX 5.0", REG_MULTI_SZ);

2、注册文件

lreg = SessionVar.Expand('"%AppFolder%\\MapX 5.0\\regsvr32.exe" /s ');
lfile = SessionVar.Expand('"%AppFolder%\\MapX 5.0\\MAPX50.DLL"');
localfile = String.Concat(lreg,lfile);
File.Run(localfile, "", "", SW_SHOWNORMAL, false);
--result = Dialog.Message("注意",localfile, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);

3、检查Oracle客户端是否安装

function isOracleClientInstalled()
  retVal = Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, "Software\\Oracle\\HOME0");
  -- 提供额外的检查
  return retVal;
end;

4、下载文件(s)

function downloadFile(remoteUrl, localFile, title)
  retVal = ""
  httpOK = HTTP.TestConnection(remoteUrl);
  if (httpOK) then
    StatusDlg.Show(0, false);
    StatusDlg.SetTitle(title);
    HTTP.Download(remoteUrl, localFile);
    StatusDlg.Hide();
    err = Application.GetLastError();
    if err == 0 then
      return localFile;
    end;
  end;
 
  if (not httpOK) then
    return "";
  end;
end;


function downloadFiles(remotePath, files, localPath, title)
  StatusDlg.Show(0, false);
  StatusDlg.SetTitle(title);
  for idx, f in files do
    remoteFile = String.Concat(remotePath, f);
    localFile = String.Concat(localPath, String.Replace(f, "/", "\\"));
    HTTP.Download(remoteFile, localFile);
    err = Application.GetLastError();
    if err ~= 0 then
      return "";
    end;
  end;
  StatusDlg.Hide();
  return localPath;
end;

5、添加Oracle连接串

function addOracleLocalService(serviceName, host, port, remoteService)
  oraFile = Registry.GetValue(HKEY_LOCAL_MACHINE, "Software\\Oracle", "ORACLE_HOME");
  oraFile = String.Concat(oraFile, "\\network\\admin\\tnsnames.ora");
 
  stroraFile = TextFile.ReadToString(oraFile);
  svcPos = 1;
  oraFileLen = String.Length(stroraFile);
 
  while svcPos > 0 and svcPos < oraFileLen do
    svcPos = String.Find(stroraFile, serviceName, svcPos + String.Length(serviceName), false);
    if svcPos > 0 and prevIsNotSymbol(stroraFile, svcPos) and nextSymbol(stroraFile, svcPos + String.Length(serviceName), oraFileLen) == '=' then
      break;
    end;
  end;
 
  if svcPos == -1 then
    stroraFile =
    String.Concat(serviceName,
      String.Concat(" =\r\n  (DESCRIPTION =\r\n    (ADDRESS_LIST =\r\n      (ADDRESS = (PROTOCOL = TCP)(HOST = ",
        String.Concat(host,
          String.Concat(")(PORT = ",
            String.Concat(port,
              String.Concat("))\r\n    )\r\n    (CONNECT_DATA =\r\n      (SERVICE_NAME = ",
                String.Concat(remoteService,
                  ")\r\n    )\r\n  )"
                )
              )
            )
          )
        )
      )
    );
    stroraFile = String.Concat("\r\n", stroraFile);
    orabakFile = String.Concat(oraFile, ".sbk");
    File.Copy(oraFile, orabakFile);
    TextFile.WriteFromString(oraFile, stroraFile, true);
  end;
end;

6、修改hosts文件

function addSdeLocalHosts(LName,MapIP)
  hostsFile = _WindowsFolder;
  hostsFile = String.Concat(hostsFile, "\\system32\\drivers\\etc\\hosts");
  --Debug.SetTraceMode(turn_on);
  --Debug.ShowWindow(true);
  --Debug.SetTraceMode(true);
  Avar =String.Concat(MapIP,"      ");
  Avar =String.Concat(Avar,LName);
  --strhostFile = TextFile.ReadToString(hostsFile);
  --strhostFile =String.Concat(strhostFile,Avar);
  strhostFile =String.Concat("\r\n",Avar);
   -- strhostFile=Avar;   
    hostsbakFile = String.Concat(hostsFile, ".sbk");    
    File.Copy(hostsFile, hostsbakFile);
    TextFile.WriteFromString(hostsFile,strhostFile, true);
end;

7、检查fromwork2.0是否安装

function isDotNETInstalled()
  retVal = Registry.DoesKeyExist(HKEY_LOCAL_MACHINE,
    "Software\\Microsoft\\.NETFramework\\Policy\\v2.0");
  -- 做额外的检查
  return retVal;
end;

8、其它

 

DlgProgressBar.SetRange(CTRL_PROGRESS_BAR_01, 0, 5);
DlgProgressBar.SetStep(CTRL_PROGRESS_BAR_01, 1);

-- Test if Oracle 9i Client is installed.
-- If not, download from the location specified by session variable "%OracleDownloadUrl%"
-- and install it.
DlgProgressBar.SetProperties(CTRL_PROGRESS_BAR_01, {Text="正在验证Oracle客户端安装..."});
DlgProgressBar.Step(CTRL_PROGRESS_BAR_01);
if not isOracleClientInstalled() then
  localOracleStartFolder = SessionVar.Expand("%TempFolder%\\Oracle\\");
  localOracle = String.Concat(localOracleStartFolder, "Oracle9iClient.msi");
  oracleUrl = SessionVar.Get("%OracleDownloadUrl%");
  if downloadFile(oracleUrl, localOracle, "正在下载Oracle客户端……") == localOracle then
   runMSINoAttention(localOracle, localOracleStartFolder);
  else
    Dialog.Message("错误",
      "不能下载安装Oracle客户端,安装完本软件后,请自行下载安装。",
      MB_OK,
      MB_ICONEXCLAMATION);
  end;
end;

-- If oracle client does exist or has just been installed, register local oracle service name.
DlgProgressBar.SetProperties(CTRL_PROGRESS_BAR_01, {Text="正在验证Oracle客户端服务名..."});
DlgProgressBar.Step(CTRL_PROGRESS_BAR_01);
if isOracleClientInstalled() then
  addOracleLocalService(
    SessionVar.Get("%OracleLocalService%"),
    SessionVar.Get("%Oracle

.NET 4 dotnet4 Friday, December 08, 2017 .Net4.0°²×°¼ì²â function isDotNet_Installed() -- .Net 4 Reg Key local DotNet_Key = "SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full"; --Check to see if the registry key exists local DotNet_Registry = Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, DotNet_Key); if (DotNet_Registry == false) then -- The registry key does not exist -- Run the .NET Installation script -- Output to the log file that .NET could not be found, so it will be installed. SetupData.WriteToLogFile("Info\t.NET 4 Module: No version of .NET 4 was found. .NET 4 will be installed.\r\n", true); return false; else -- The key does exist -- Get the .NET install success value from the registry local DotNet_Install_Success = Registry.GetValue(HKEY_LOCAL_MACHINE, DotNet_Key, "Install", true); if (DotNet_Install_Success == "1") then -- Check the version key. local DotNet_Install_Version = Registry.GetValue(HKEY_LOCAL_MACHINE, DotNet_Key, "Version", true); -- Compare the returned value against the needed value Compare = String.CompareFileVersions(DotNet_Install_Version, "4.0.30319"); if (Compare == 0 or Compare == 1) then -- .NET version 4 is installed already SetupData.WriteToLogFile("Info\t.NET 4 Module: .NET version 4 is installed already\r\n", true); return true; else SetupData.WriteToLogFile("Info\t.NET 4 Module: A lesser version of .NET 4 was found on the users system.\r\n", true); return false; end else -- The success value wasn't found -- Run the .NET Installation script -- Output to the log file that .NET could not be found, so it will be installed. SetupData.WriteToLogFile("Info\t.NET 4 Module: No version of .NET 4 was found. .NET 4 will be installed.\r\n", true); return f
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值