中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net  论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

游客:  注册 | 登录 | 命令行 | 搜索 | 上传 | 帮助 »
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [讨论]VBS可不可读取这种INI文件
作者:
标题: [讨论]VBS可不可读取这种INI文件 上一主题 | 下一主题
81291895
初级用户





积分 42
发帖 17
注册 2005-8-28
状态 离线
『楼 主』:  [讨论]VBS可不可读取这种INI文件

[腾讯QQ] SvcDir=\\192.168.0.252\Game\NetGame\QQ DisDir=E:\NetGame\QQ RunDir=QQ.exe RegDir=QQ.Reg RunCmd=Play.bat [QQ游戏] SvcDir=\\192.168.0.252\Game\Ghost\QQGame DisDir=E:\NetGame\QQGame RunDir=QQGame.exe RegDir=QQGame.Reg RunCmd=Play.bat [456游戏] SvcDir=\\192.168.0.252\Game\Ghost\456Game DisDir=E:\NetGame\456Game RunDir=lobby.exe RegDir=456Game.reg RunCmd=Play.bat 如脚本名为abc.vbs 我可以用“abc.vbs QQ游戏”调用[QQ游戏]下的参数 P处理是可以实现的 VBS想了很久还没想到 下面的脚本只能读取INI里最后一节参数
On Error Resume Next
Set oShell = Wscript.CreateObject("Wscript.Shell")
Set objArgs = WScript.Arguments
For I = 0 to objArgs.Count - 1
   Gamename = objArgs(I)
Next
SvcDir = GetIni (Gamename,"SvcDir","Gamecfg.ini")
DisDir = GetIni (Gamename,"DisDir","Gamecfg.ini")
RunDir = GetIni (Gamename,"RunDir","Gamecfg.ini")
RegDir = GetIni (Gamename,"RegDir","Gamecfg.ini")
RunCmd = GetIni (Gamename,"RunCmd","Gamecfg.ini")
Runfile = "Xxcopy " & SvcDir & " " & DisDir & " /pb/s/k/h/bi/yy/zy"
oShell.run Runfile,0,true
oShell.run RunCmd,0,true
oShell.run "Regedit /s RegDir",0,true
oShell.run RunDir

Function GetIni(strPrimary, strSubKey, strIniFilePath) 
    Dim fso, Myfile, intCount, strState
    Set fso =  CreateObject("Scripting.FileSystemObject")
    Set Myfile = fso.OpenTextFile(strIniFilePath, 1, False, False)
    With Myfile
        Do Until .AtEndOfStream
            If intCount = 0 Then
                If .ReadLine = "[" & strPrimary & "]" Then
                    intCount = 1
                End If
            Else
                strState = .ReadLine
                If UCase(Left(strState, Len(strSubKey & "="))) = UCase(strSubKey & "=") Then
                    GetIni = Right(strState, Len(strState) - Len(strSubKey & "="))
                End If
            End If
        Loop
        .Close
    End With
    Set Myfile = Nothing
    Set fso = Nothing
End Function
[ Last edited by 81291895 on 2007-12-5 at 10:12 PM ]


2007-12-5 07:40
查看资料  发短消息  网志   编辑帖子  回复  引用回复
81291895
初级用户





积分 42
发帖 17
注册 2005-8-28
状态 离线
『第 2 楼』:  

没人会吗?


2007-12-5 21:24
查看资料  发短消息  网志   编辑帖子  回复  引用回复
zh159
金牌会员




积分 3687
发帖 1467
注册 2005-8-8
状态 离线
『第 3 楼』:  

问题是:要读取为这怎样的格式?




2007-12-5 21:31
查看资料  发短消息  网志   编辑帖子  回复  引用回复
hlowd
初级用户





积分 65
发帖 29
注册 2007-11-3
状态 离线
『第 4 楼』:  哈哈

ini建议用API 要在VBS中调用,需要封装为OCX控件,然后用VBS调用 VBS自己好像只能把它当作文本文件读取......


2007-12-5 21:38
查看资料  发短消息  网志   编辑帖子  回复  引用回复
zh159
金牌会员




积分 3687
发帖 1467
注册 2005-8-8
状态 离线
『第 5 楼』:  

只要VBS把它读取出来,通过处理也可以使用,但是不明白要处理成怎样的方式运行(很少玩游戏了-_-|||)




2007-12-5 21:58
查看资料  发短消息  网志   编辑帖子  回复  引用回复
slore
铂金会员





积分 5212
发帖 2478
注册 2007-2-8
状态 离线
『第 6 楼』:  

代码写的不错~而且很规范…… 错在你找到了却没有及时退出。。。代码给你修改了,就加了个Exit Do On Error Resume Next Set oShell = Wscript.CreateObject("Wscript.Shell") Set objArgs = WScript.Arguments For I = 0 To objArgs.Count - 1 Gamename = objArgs(I) Next SvcDir = GetIni (Gamename,"SvcDir","Gamecfg.ini") DisDir = GetIni (Gamename,"DisDir","Gamecfg.ini") RunDir = GetIni (Gamename,"RunDir","Gamecfg.ini") RegDir = GetIni (Gamename,"RegDir","Gamecfg.ini") RunCmd = GetIni (Gamename,"RunCmd","Gamecfg.ini") Runfile = "Xxcopy " & SvcDir & " " & DisDir & " /pb/s/k/h/bi/yy/zy" oShell.run Runfile,0,True oShell.run RunCmd,0,True oShell.run "Regedit /s RegDir",0,True oShell.run RunDir Function GetIni(strPrimary, strSubKey, strIniFilePath) Dim fso, Myfile, intCount, strState Set fso = CreateObject("Scripting.FileSystemObject") Set Myfile = fso.OpenTextFile(strIniFilePath, 1, False, False) With Myfile Do Until .AtEndOfStream If intCount = 0 Then If .ReadLine = "[" & strPrimary & "]" Then intCount = 1 End If Else strState = .ReadLine If UCase(Left(strState, Len(strSubKey & "="))) = UCase(strSubKey & "=") Then GetIni = Right(strState, Len(strState) - Len(strSubKey & "=")) Exit Do End If End If Loop .Close End With Set Myfile = Nothing Set fso = Nothing End Function


2007-12-7 02:36
查看资料  发短消息  网志   编辑帖子  回复  引用回复

请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: