Active Setup - appending line in file in Appdata
Have the following batch file:
cscript Myvb.vbs "C:\Users\%username%\AppData\LocalLow\file.ini" "Things" "Stuff"
vb script file:
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
and batch file to set 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
I have need to add a line at a certain location with a file stored in AppData for all users. If mybat is executed manually, the file is edited fine. However, the file does not change after logging in. I undid the changes to the file and cleared the active setup registry entry in my profile between my tests.
Is there a permissions issue I am missing? Is %username% coming out to be not what I expect it to?
Answers (2)
Top Answer
cscript "%~dp0Myvb.vbs" "C:\Users\%username%\AppData\LocalLow\file.ini" "Things" "Stuff"If this does not help I would suggest to modify StubPath to: CMD.EXE /K "%SYSTEMROOT%\MyBat.bat" - then you would see the error message if any occurred.
You could also consider to modify these files without ActiveSetup, for example:
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder("C:\Users")
For Each User in oFolder.Subfolders
strFilePath = "C:\Users\" &User.Name &"\AppData\LocalLow\file.ini"
If oFSO.FileExists(strFilePath) Then
....
....
Else
WriteToLog "File: " &strFilePath &" does not exist."
End If
Next
Comments:
-
...Yes. Yes I should have included the full path. Thank you. - ChrisRoy 7 years ago