VBS scripting to replace dll file
Hi all,
Just wondering if someone can point out where I have gone wrong with this, I am getting this error code. - 0x80041017
This code is restoring a dll file I replaced in another script (which works finie) but this one errors.
Dim FSO
'Copies over new warngina.dll and replaces the old one in the C:\windows\system32 folder
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("Wscript.Shell")
sd = WshShell.ExpandEnvironmentStrings("%systemdrive%")
sr = WshShell.ExpandEnvironmentStrings("%systemroot%")
strComputer = "."
Set objWMIService = GetObject _
("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from Cim_Datafile where Name = " _
& "'C:\winnt\system32\warngina.dll'")
For Each objFile in colfiles
errResult = objFile.Rename("C:\\winnt\\system32\\warngina.002" )
Wscript.Echo errResult
Next
SourceFolder = "\\<server>\migration$\WTS Update Scripts\Warngina_Update\warngina.old"
DestFolder = sr & "\system32\warngina.dll"
'Copies the file to system32 path and overwrites the existing one there.
FSO.CopyFile SourceFolder, DestFolder, True
Cheers for any help,
TG
Just wondering if someone can point out where I have gone wrong with this, I am getting this error code. - 0x80041017
This code is restoring a dll file I replaced in another script (which works finie) but this one errors.
Dim FSO
'Copies over new warngina.dll and replaces the old one in the C:\windows\system32 folder
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("Wscript.Shell")
sd = WshShell.ExpandEnvironmentStrings("%systemdrive%")
sr = WshShell.ExpandEnvironmentStrings("%systemroot%")
strComputer = "."
Set objWMIService = GetObject _
("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from Cim_Datafile where Name = " _
& "'C:\winnt\system32\warngina.dll'")
For Each objFile in colfiles
errResult = objFile.Rename("C:\\winnt\\system32\\warngina.002" )
Wscript.Echo errResult
Next
SourceFolder = "\\<server>\migration$\WTS Update Scripts\Warngina_Update\warngina.old"
DestFolder = sr & "\system32\warngina.dll"
'Copies the file to system32 path and overwrites the existing one there.
FSO.CopyFile SourceFolder, DestFolder, True
Cheers for any help,
TG
0 Comments
[ + ] Show comments
Answers (10)
Please log in to answer
Posted by:
anonymous_9363
15 years ago
You don't say at which line the error occurs. It could be the rename which fails (IMV, the most likely - see below) or the copy.
I suspect that, given that the filename includes the text 'GINA' that this is a login screen add-on/replacement of some kind? If so, it's likely that the file is open and cannot be replaced in that state: you'd have to use the usual PendingFileRenameOperation-and-reboot hack to replace it.
I suspect that, given that the filename includes the text 'GINA' that this is a login screen add-on/replacement of some kind? If so, it's likely that the file is open and cannot be replaced in that state: you'd have to use the usual PendingFileRenameOperation-and-reboot hack to replace it.
Posted by:
aogilmor
15 years ago
Posted by:
anonymous_9363
15 years ago
Posted by:
Thegunner
15 years ago
ORIGINAL: VBScab
You don't say at which line the error occurs. It could be the rename which fails (IMV, the most likely - see below) or the copy.
I suspect that, given that the filename includes the text 'GINA' that this is a login screen add-on/replacement of some kind? If so, it's likely that the file is open and cannot be replaced in that state: you'd have to use the usual PendingFileRenameOperation-and-reboot hack to replace it.
Sorry people,
Getting the error at this line
For Each objFile in colfiles
The error is saying (null) to I was thinking the colfiles or something is empty maybe.
I have got it working just using FSO instead, I couldnt spend that much more time on it as I needed it working.
Posted by:
anonymous_9363
15 years ago
Posted by:
Thegunner
15 years ago
Posted by:
anonymous_9363
15 years ago
Posted by:
Thegunner
15 years ago
Hi VBScab,
I replaced the line with the line you put and its still giving me a error on the 'For Each objFile in colFiles'
Saying value is Null.
anymore ideas?
I replaced the line with the line you put and its still giving me a error on the 'For Each objFile in colFiles'
Saying value is Null.
anymore ideas?
'On Error Resume Next
Dim FSO
'Copies over new warngina.dll and replaces the old one in the C:\windows\system32 folder
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("Wscript.Shell")
sd = WshShell.ExpandEnvironmentStrings("%systemdrive%")
sr = WshShell.ExpandEnvironmentStrings("%systemroot%")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery("Select * from CIM_DataFile where Path = 'C:\Winnt\system32\warngina.dll'")
For Each objFile in colFiles
errResult = objFile.Rename("C:\\winnt\\system32\\warngina.001" )
Wscript.Echo errResult
Next
SourceFolder = "\\<server>\migration$\WTS Update Scripts\Warngina_Update\warngina.old"
DestFolder = sr & "\system32\warngina.dll"
'Copies the file to system32 path and overwrites the existing one there.
FSO.CopyFile SourceFolder, DestFolder, True
Posted by:
anonymous_9363
15 years ago
Really? I don't see it there!
NB! In pasting this text in, I noticed that I'd left the original terminating quote mark in the wrong place. The line above should work.
Also, you wish to refer to the horse's mouth, as it were: http://www.microsoft.com/technet/scriptcenter/resources/qanda/dec04/hey1209.mspx
Set colFiles = objWMIService.ExecQuery("Select * from CIM_DataFile where Path = 'C:\Winnt\system32\warngina.dll'")
should be
Set colFiles = objWMIService.ExecQuery("Select * from CIM_DataFile where Path = '\Winnt\system32' AND Drive = 'C:'")
NB! In pasting this text in, I noticed that I'd left the original terminating quote mark in the wrong place. The line above should work.
Also, you wish to refer to the horse's mouth, as it were: http://www.microsoft.com/technet/scriptcenter/resources/qanda/dec04/hey1209.mspx
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.