String.prototype.trim = function(){
return this.replace(/(^\s+)|(\s+$)/g, '');
}; IniConfig = function(iniFileName) {
this.iniFileName = iniFileName;
this._iniSecDictionary = new Array();
this.fso = new ActiveXObject("Scripting.FileSystemObject");
} IniConfig.prototype._checkFile = function(){
if (!this.fso.FileExists(this.iniFileName)){
this.fso.CreateTextFile(this.iniFileName, true, true);
}
} IniConfig.prototype.load = function(){
this._checkFile();
var currSecName = null;
var fs = this.fso.OpenTextFile(this.iniFileName, 1, false, -1); while (!fs.AtEndOfStream) {
var strLine = fs.ReadLine().trim();
if (strLine.length > 0){
var firchCh = strLine.substr(0, 1);
if (firchCh != ';'){
if (firchCh == '['){
var secName = strLine.substr(1, strLine.length - 2);
currSecName = secName;
this._iniSecDictionary[secName] = new Array();
} else {
var idx = strLine.indexOf('=');
var strKey = strLine.substring(0, idx);
var strVal = strLine.substr(idx + 1);
if (currSecName == null){
throw ("Ini文件格式不正确!");
}
this._iniSecDictionary[currSecName][strKey] = strVal;
}
}
}
}
fs.Close();
fs = null;
} IniConfig.prototype.save = function(){
this._checkFile();
var dic = this._iniSecDictionary;
var currSecName = null;
var fs = this.fso.OpenTextFile(this.iniFileName, 2, true, -1);
for (var sec in dic){
fs.WriteLine('[' + sec + ']');
for (var key in dic[sec]){
fs.WriteLine(key + '=' + dic[sec][key]);
}
}
fs.Close();
fs = null;
} IniConfig.prototype.get = function(secName, keyName) {
var dic = this._iniSecDictionary;
try{
return dic[secName][keyName];
} catch (e) {
return '';
}
} IniConfig.prototype.set = function(secName, keyName, val) {
var dic = this._iniSecDictionary;
try {
if (dic[secName] == null) {
dic[secName] = new Array();
}
dic[secName][keyName] = val;
} catch (e) {
alert(e.message);
}
} try {
var iniFile = new IniConfig("E:\\a.ini");
iniFile.load();
alert(iniFile.get("Shutdown","0CmdLine"));
iniFile.set("Shutdown","0CmdLine","aaa");
iniFile.set("Shutdown","0CmdLine","abc");
iniFile.set("Shutdown", "1CmdLine", "bbb")
iniFile.save();
} catch(e) {
alert(e.message);
}

JS通过ActiveX读写ini配置文件的更多相关文章

  1. C# 读写 ini 配置文件

    虽说 XML 文件越发流行,但精简的 ini 配置文件还是经常会用到,在此留个脚印. 当然,文中只是调用系统API,不会报错,如有必要,也可以直接以流形式读取 ini文件并解析. /// <su ...

  2. [转]VB 读写ini 配置文件

    转自 百度知道 C# 读写 ini配置文件 点此链接 'API 声明Public Declare Function GetPrivateProfileString Lib "kernel32 ...

  3. 自己写的 读写 ini 配置文件类

    /// <summary> /// 不调用系统API 读写 ini 配置文件 /// </summary> public class RW_ini { #region ==== ...

  4. 引用“kernel32”读写ini配置文件

    引用"kernel32"读写ini配置文件 unity ini kernel32 配置文件  引用"kernel32"读写ini配置文件 OverView ke ...

  5. C# 文件的一些基本操作(转)//用C#读写ini配置文件

    C# 文件的一些基本操作 2009-07-19  来自:博客园  字体大小:[大 中 小] 摘要:介绍C#对文件的一些基本操作,读写等. using System;using System.IO;us ...

  6. C#操作读写INI配置文件

    一个完整的INI文件格式由节(section).键(key).值(value)组成.示例如:[section]key1=value1key2=value2; 备注:value的值不要太长,理论上最多不 ...

  7. c#读写ini配置文件示例

    虽然c#里都是添加app.config 并且访问也很方便 ,有时候还是不习惯用他.那么我们来做个仿C++下的那种ini配置文件读写吧     其他人写的都是调用非托管kernel32.dll.我也用过 ...

  8. WritePrivateProfileString等读写.ini配置文件

    配置文件中经常用到ini文件,在VC中其函数分别为: 写入.ini文件: BOOL WritePrivateProfileString( LPCTSTR lpAppName, // INI文件中的一个 ...

  9. C++读写ini配置文件GetPrivateProfileString()&WritePrivateProfileString()

    转载: 1.https://blog.csdn.net/fengbingchun/article/details/6075716 2. 转自:http://hi.baidu.com/andywangc ...

随机推荐

  1. [Zhx] 无题

    https://www.luogu.org/problemnew/show/T15368 区间修改,区间查询k(<= 10)大值 应该也可以用分块写 #include <cstdio> ...

  2. sqlserver数据库查询语句

    --数据库所有表select * from sysobjects where type='u'; --指定表的所有列select name from syscolumns where id=(sele ...

  3. Bsgs模板

    模板最主要的是自己看得舒服,不会给自己留隐患,调起来比较简单,板子有得是,最主要的是改造出适合你的那一套.                  ——mzz #include<bits/stdc++ ...

  4. Mac 下反编译Android APK

    准备工作:安装ApkTool.dex2jar.JD-GUI 安装ApkTool 1.下载ApkTool.大家可以从 https://ibotpeaches.github.io/Apktool/inst ...

  5. Deep & Cross Network总结

    一.介绍 CTR预估全称是Click Through Rate,就是展示给用户的广告或者商品,估计用户点击的概率.公司规模较大的时候,CTR直接影响的价值在数十亿美元的级别.广告支付一个非常流行的模型 ...

  6. base64和hex

    base64和hex 我们知道,字符分为二种:一种是可见字符:另一种是不可见字符. 1)三种编码方式 hex也称为base16,意思是使用16个可见字符来表示一个二进制数组,编码后数据大小将翻倍,因为 ...

  7. Apache 后台服务器(主要处理php及一些功能请求 如:中文url)   Nginx 前端服务器(利用它占用系统资源少得优势来处理静态页面大量请求)   Lighttpd 图片服务器   总体来说,随着nginx功能得完善将使他成为今后web server得主流。

    Apache 后台服务器(主要处理php及一些功能请求 如:中文url) Nginx 前端服务器(利用它占用系统资源少得优势来处理静态页面大量请求) Lighttpd 图片服务器 总体来说,随着ngi ...

  8. word中英文双引号的样式区分与替换技巧

    https://jingyan.baidu.com/article/3f16e003147ea42590c10349.html 场景:一篇word文档中,想要全选更改字体,使得中文全部为“宋体”,英文 ...

  9. Java同步数据结构之ConcurrentSkipListMap/ConcurrentSkipListSet

    引言 上一篇Java同步数据结构之Map概述及ConcurrentSkipListMap原理已经将ConcurrentSkipListMap的原理大致搞清楚了,它是一种有序的能够实现高效插入,删除,更 ...

  10. golang 循环创建闭包 问题排查

    ][]string{ { { "邀请码是什么", "我没有邀请码", "这个邀请码我可以随便填吗", "邀请码可以填他的手机号吗& ...