拥有以下批处理文件:
cscript Myvb.vbs "C:\Users\%username%\AppData\LocalLow\file.ini" "Things" "Stuff"
vb脚本文件:
Const ForReading = 1
Const ForWriting = 2
strFileName = WScript.Arguments(0)
strFindText = WScript.Arguments(1)
strNewText = WScript.Arguments(1) & vbCrLf & WScript.Arguments(2)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, strFindText, stfFindText&strNewText)
Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)
objFile.Write strNewText
objFile.Close
Set objFile = Nothing
和批处理文件来设置ActiveSetup:
@echo off
REM copy batch file
xcopy Mybat.bat* %SYSTEMROOT%\
xcopy Myvb.vbs* %SYSTEMROOT%\
REM create active setup component to run batch file
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\MySetup" /v "Version" /t REG_SZ /d "1" /f
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\MySetup" /v "StubPath" /t REG_SZ /d "%SYSTEMROOT%\Mybat.bat" /f
如果手动执行mybat,则文件编辑正常。但是,登录后文件不会更改。我取消了对文件的更改,并在我的测试中清除了我的配置文件中的活动安装程序注册表项。
我是否缺少权限问题? %username%是不是我期望的那样?
答案 0 :(得分:0)
通过指示bat文件中vbs的完整路径
来完成此工作cscript "%~dp0Myvb.vbs" "C:\Users\%username%\AppData\LocalLow\file.ini" "Things" "Stuff"