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. 【Winfrom-无边框窗体】Winform如何拖动无边框窗体?

    去掉边框 this.FormBorderStyle = FormBorderStyle.None; 方法一: Point mouseOff;//鼠标移动位置变量 bool leftFlag;//标签是 ...

  2. hive表的DDL

    查看表            hive> show tables;创建表            hive> create table t1(id int);查看表结构           ...

  3. 学到了林海峰,武沛齐讲的Day18 迭代

    x='hello' gxr=iter(x) gxr=x.__iter__() print(next(gxr)) print(gxr.__next__()) iter()===__iter__ next ...

  4. spring security控制session

    spring security控制session本文给你描述在spring security中如何控制http session.包括session超时.启用并发session以及其他高级安全配置. 创 ...

  5. CF358D Dima and Hares dp

    状态的定义挺奇特的~ 发现最终每一个物品一定都会被选走. 令 $f[i][0/1]$ 表示 $a[i]$ 在 $a[i-1]$ 前/后选时 $1$~$(i-1)$ 的最优解. 因为一个数字的价值只由其 ...

  6. Peaks 线段树合并

    Peaks 线段树合并 \(n\)个带权值\(h_i\)山峰,有\(m\)条山峰间双向道路,\(q\)组询问,问从\(v_i\)开始只经过\(h_i\le x\)的路径所能到达的山峰中第\(k\)高的 ...

  7. 【概率论】5-4:泊松分布(The Poisson Distribution)

    title: [概率论]5-4:泊松分布(The Poisson Distribution) categories: - Mathematic - Probability keywords: - Po ...

  8. 扩展kmp学习笔记

    kmp没写过,扩展kmp没学过可还行. 两个愿望,一次满足 (该博客仅用于防止自己忘记,不保证初学者能看懂我在瞎bb什么qwq) 用途 对于串\(s1,s2\),可以求出\(s2\)与\(s1\)的每 ...

  9. ros平台下python脚本控制机械臂运动

    在使用moveit_setup_assistant生成机械臂的配置文件后可以使用roslaunch demo.launch启动demo,在rviz中可以通过拖动机械臂进行运动学正逆解/轨迹规划等仿真运 ...

  10. Go语言之快速排序

    package main import "fmt" func partition(array []int, i int, j int) int { //第一次调用使用数组的第一个元 ...