Question : How do I add my read-only attribute back with a .vb script

Hi -

I'm trying to add a read-only attribute back to a file via vbscript, but I'm getting stumped by something that I may be overlooking and hopefully is easy. As you can see from my code snippet, I first remove the read-only setting which works fine but after I'm done with replacing the file, I try to add the re-add the read-only attribute back and it doesn't just does not work.

What am I doing wrong?

Thanks,
Jim
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
On Error Resume Next
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set WshShell = WScript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")

'Variable Declarations
ProgramFiles = WshShell.ExpandEnvironmentStrings("%ProgramFiles%")
SystemDrive = WshShell.ExpandEnvironmentStrings("%SystemDrive%")
SystemRoot = WshShell.ExpandEnvironmentStrings("%SystemRoot%")
AllUsersProfile = WshShell.ExpandEnvironmentStrings("%ALLUSERSPROFILE%")
ScriptFullName = WScript.ScriptFullName
ScriptName = WScript.ScriptName
InstallDir = Left(ScriptFullName, Len(ScriptFullName)-Len(ScriptName)-1) & "\"
WshShell.CurrentDirectory = InstallDir 
ManagedMarker=InstallDir & "\Success.txt"
CfgXML="Configuration.xml"
CfgXMLbkp="configuration1.old"
CfgXMLPath="\Application Data\Cisco\Cisco Secure Services Client\system\"

'Create Logfile
Set InstLogFile = fso.CreateTextFile(ScriptFullName & ".Log",True)
InstLogFile.WriteLine Now() & " Starting Installation of """ & ScriptFullName & """."


If fso.fileexists(AllUsersProfile & CfgXMLPath & CfgXML) Then
	'archive file
	Set objFile = FSO.GetFile(AllUsersProfile & CfgXMLPath & CfgXML)

	If objFile.Attributes AND 1 Then
	    objFile.Attributes = objFile.Attributes = 0
	End If

	InstLogFile.WriteLine Now() & " Found 'Configuration.xml' in Allusers path.  Backing it up."
	fso.CopyFile AllUsersProfile & CfgXMLPath & CfgXML, AllUsersProfile & CfgXMLPath & CfgXMLbkp
	
	'copy new file
	InstLogFile.WriteLine Now() & " Replacing/Inserting new 'Configuration.xml'."
	fso.deletefile AllUsersProfile & CfgXMLPath & cfgXML
	fso.copyfile InstallDir & cfgxml, AllUsersProfile & CfgXMLPath & cfgXML

	If objFile.Attributes AND 0 Then
	    objFile.Attributes = objFile.Attributes = 1
	End If
Else
	InstLogFile.WriteLine Now() & " 'Configuration.xml' not found.  Assuming CSSC not installed."

End If

InstLogFile.writeline now() & " Installation of """ & ScriptFullName & """ is Finished."
InstLogFile.Close()
Set InstLogFile = Nothing

Set FSO = Nothing
Set WshShell = Nothing

Answer : How do I add my read-only attribute back with a .vb script

Looks like your syntax was just off a bit.  Try this code.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
On Error Resume Next
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set WshShell = WScript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")

'Variable Declarations
ProgramFiles = WshShell.ExpandEnvironmentStrings("%ProgramFiles%")
SystemDrive = WshShell.ExpandEnvironmentStrings("%SystemDrive%")
SystemRoot = WshShell.ExpandEnvironmentStrings("%SystemRoot%")
AllUsersProfile = WshShell.ExpandEnvironmentStrings("%ALLUSERSPROFILE%")
ScriptFullName = WScript.ScriptFullName
ScriptName = WScript.ScriptName
InstallDir = Left(ScriptFullName, Len(ScriptFullName)-Len(ScriptName)-1) & "\"
WshShell.CurrentDirectory = InstallDir 
ManagedMarker=InstallDir & "\Success.txt"
CfgXML="Configuration.xml"
CfgXMLbkp="configuration1.old"
CfgXMLPath="\Application Data\Cisco\Cisco Secure Services Client\system\"

'Create Logfile
Set InstLogFile = fso.CreateTextFile(ScriptFullName & ".Log",True)
InstLogFile.WriteLine Now() & " Starting Installation of """ & ScriptFullName & """."


If fso.fileexists(AllUsersProfile & CfgXMLPath & CfgXML) Then
	'archive file
	Set objFile = FSO.GetFile(AllUsersProfile & CfgXMLPath & CfgXML)

	If objFile.Attributes AND 1 Then
	    objFile.Attributes = objFile.Attributes - 1
	End If

	InstLogFile.WriteLine Now() & " Found 'Configuration.xml' in Allusers path.  Backing it up."
	fso.CopyFile AllUsersProfile & CfgXMLPath & CfgXML, AllUsersProfile & CfgXMLPath & CfgXMLbkp
	
	'copy new file
	InstLogFile.WriteLine Now() & " Replacing/Inserting new 'Configuration.xml'."
	fso.deletefile AllUsersProfile & CfgXMLPath & cfgXML
	fso.copyfile InstallDir & cfgxml, AllUsersProfile & CfgXMLPath & cfgXML

	If not objFile.Attributes AND 1 Then
	    objFile.Attributes = objFile.Attributes + 1
	End If
Else
	InstLogFile.WriteLine Now() & " 'Configuration.xml' not found.  Assuming CSSC not installed."

End If

InstLogFile.writeline now() & " Installation of """ & ScriptFullName & """ is Finished."
InstLogFile.Close()
Set InstLogFile = Nothing

Set FSO = Nothing
Set WshShell = Nothing
Random Solutions  
 
programming4us programming4us