/build/static/layout/Breadcrumb_cap_w.png

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

0 Comments   [ + ] Show comments

Answers (10)

Posted by: anonymous_9363 14 years ago
Red Belt
0
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.
Posted by: aogilmor 14 years ago
9th Degree Black Belt
0
don't do it, create a msi file and let windows installer take care of versioning for you
Posted by: anonymous_9363 14 years ago
Red Belt
0
Not much use if the OP wants to return to a previous, older version, though, Mr G. :)
Posted by: aogilmor 14 years ago
9th Degree Black Belt
0
Yeah, you see all kinds of crazy things in this here world...LOL!
Posted by: Thegunner 14 years ago
Second Degree Green Belt
0
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 14 years ago
Red Belt
0
LOL...That'll teach me to actually READ posts...I didn't notice you weren't using FSO!

You can't specify a path like that. It would have to be:Set colFiles = objWMIService.ExecQuery("Select * from CIM_DataFile where Path = '\\Scripts\\'" AND Drive = 'C:')
Posted by: Thegunner 14 years ago
Second Degree Green Belt
0
I was using FSO for a part, but saw someone using WMI so I tried it that way couldnt get it work due to the error. Now just gone down the road of using FSO. But if someone knows how to get it to work, I will use it for the future.

ta
Posted by: anonymous_9363 14 years ago
Red Belt
0
if someone knows how to get it to workEr, did you somehow miss the post immediately above your last?!? :)
Posted by: Thegunner 14 years ago
Second Degree Green Belt
0
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?


'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 14 years ago
Red Belt
0
Really? I don't see it there!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.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ