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. KMP模板,注释

    #include<bits/stdc++.h> using namespace std; queue<int> KMP(string a,string b){//a是主串,b是 ...

  2. 【.Net设计模式系列】仓储(Repository)模式 ( 一 )

    开篇 2016新年伊始,望眼过去,不知不觉在博客园已经注册8个月啦,由于最近忙于工作,博客迟迟没有更新.直到最近一直研究.Net设计模式,对一些模式有所感悟,故拿出自己的心得与大家分享,在接下来的所有 ...

  3. hadoop笔记-hdfs文件读写

    概念 文件系统 磁盘进行读写的最小单位:数据块,文件系统构建于磁盘之上,文件系统的块大小是磁盘块的整数倍. 文件系统块一般为几千字节,磁盘块一般512字节. hdfs的block.pocket.chu ...

  4. RESOURCE SUMMARY

    I dont know where to start so searched the net and get a lot of free videos, my plan is to watch the ...

  5. ssh刚连接到其他服务器就闪退的问题。Connection to slave1 closed

    问题现象: 由于最近在docker上部署hadoop,最开始搭建完以后,ssh是正常的,当我重启系统以后就出现了上面的这个问题 解决: 修改配置文件:/etc/ssh/sshd_config 把Per ...

  6. Layui + 微信小程序 + PC端 + GatewayWorker + 移动端即时聊天系统

  7. Invalid Component definition:header

    主要是header不是字符串,而是变量

  8. Java类的变量初始化顺序

    大家在去参加面试的时候,经常会遇到这样的考题:给你两个类的代码,它们之间是继承的关系,每个类里只有构造器方法和一些变量,构造器里可能还有一段代码对变量值进行了某种运算,另外还有一些将变量值输出到控制台 ...

  9. 初探nodejs事件循环机制event loop

    nodejs的特点 nodejs 具有事件驱动和非阻塞I/O的特点. 事件驱动是指nodejs把每一个任务当成事件来处理. 非阻塞I/O是指nodejs遇到I/O任务时,会从线程池调度单独的线程处理I ...

  10. Dubbo的SPI是个什么鬼

    原文:https://mp.weixin.qq.com/s/bQc_tASkfsojlcd897kLtA # spi 是啥? spi,简单来说,就是 service provider interfac ...