Copying a file from source location to system32

Hello. I need to copy an .exe from it's source location to c:\windows\system32.  For example, I have a package that contains sleep.exe, several images, and a hta. This package will be deployed through SMS and each source will be different. I tried using the below but I cannot get it to work properly. The only copying I have done is from a static source.

Any advice would be appreciated?
Const OverwriteExisting = TRUE
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "sleep.exe" , "C:\windows\system32", OverwriteExisting

Open in new window

LorrecAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobSampsonCommented:
Hi, if the VBS that you have above is in the same folder as the files you want to copy, you can obtain the VBS file's current folder, and tack the required files onto that....

Regards,

Rob.
Const OverwriteExisting = TRUE
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "Sleep.exe"
objFSO.CopyFile strFile, "C:\windows\system32", OverwriteExisting
strFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "Image1.jpg"
objFSO.CopyFile strFile, "C:\windows\system32", OverwriteExisting
strFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "MyHTA.hta"
objFSO.CopyFile strFile, "C:\windows\system32", OverwriteExisting

Open in new window

0
LorrecAuthor Commented:
Thank you for the post.

Do I leave this line as is or I am suppose to change it? I am not familiar with it.
strFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "Sleep.exe"

I found an hta that displays a notification to users. It allows users to postpone an installation. However, it uses wscript.sleep which is causing problems. The hourglass appears each time wscript.sleep runs.

I decided to create and call a .bat file inside the hta to handle sleep. The .bat file is using sleep 1 and does not produce the hourglass. The only problem is that since sleep.exe is not native to XP, I am having to copy it during the package.

So, in the hta, I have a vb script that looks like the below. Since I have not done a copy from a dynamic source, I am confused on how to get your advice to work. When I run it now,  it says wscript required. I am assuming that means I am not setting something properly.
          Dim Act   : Set Act = CreateObject("Wscript.Shell")
          Dim Fso   : Set Fso = CreateObject("Scripting.FileSystemObject")
          Dim Uname : Uname = Act.ExpandEnvironmentStrings("%UserName%")
          Dim SD    : SD = Act.ExpandEnvironmentStrings("%Temp%")
          Dim HrCnt	:	HrCnt = 0
          Dim SecCnt   : SecCnt = 1
          Dim MinCnt : MinCnt = 15
        '/-> HTA DO NOT SUPPORT THE STANDARD SLEEP THAT 
        '/-> WSCRIPT USES THESE ARE MY WORK AROUND 
        '/-> SLEEP 1 SECONDS
        Const OverwriteExisting = TRUE
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        strFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "Sleep.exe"
        objFSO.CopyFile strFile, "C:\windows\system32", OverwriteExisting
            Function Rst1()
              Dim Ts : Set Ts = Fso.OpenTextFile(SD & "\Rest1.bat", 2, True)
                Ts.WriteLine "Sleep 1" : Ts.close
                Act.run(SD & "\Rest1.bat"), 0 , True 
                If Fso.FileExists(SD & "\Rest1.bat") Then
        	        Fso.DeleteFile(SD & "\Rest1.bat")
                End If
            End Function

Open in new window

0
RobSampsonCommented:
Ah, OK, I wasn't aware that your VBS code was in a HTA.  This is why the WScript object is not supported, and also why you can't use WScript.Sleep or WScript.ScriptFullName.

So, with a HTA, the current path is returned by document.location, so we can get this value, and use that to find finds files in the current path.

I have now changed
strFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "Sleep.exe"
to
        strFile = Left(strHTAPath, InStrRev(strHTAPath, "\")) & "Sleep.exe"

after getting strHTAPath with
          If Mid(document.location, 6, 3) = "///" Then
                strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 9)
          Else
                strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 6)
          End If  

So you can try this.

Regards,

Rob.
          Dim Act   : Set Act = CreateObject("Wscript.Shell")
          Dim Fso   : Set Fso = CreateObject("Scripting.FileSystemObject")
          Dim Uname : Uname = Act.ExpandEnvironmentStrings("%UserName%")
          Dim SD    : SD = Act.ExpandEnvironmentStrings("%Temp%")
          Dim HrCnt	:	HrCnt = 0
          Dim SecCnt   : SecCnt = 1
          Dim MinCnt : MinCnt = 15
          '=== Get the path to the current HTA ===
	    If Mid(document.location, 6, 3) = "///" Then
	    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 9)
	    Else
	    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 6)
	    End If          
          '=======================================
        '/-> HTA DO NOT SUPPORT THE STANDARD SLEEP THAT 
        '/-> WSCRIPT USES THESE ARE MY WORK AROUND 
        '/-> SLEEP 1 SECONDS
        Const OverwriteExisting = TRUE
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        strFile = Left(strHTAPath, InStrRev(strHTAPath, "\")) & "Sleep.exe"
        objFSO.CopyFile strFile, "C:\windows\system32", OverwriteExisting
            Function Rst1()
              Dim Ts : Set Ts = Fso.OpenTextFile(SD & "\Rest1.bat", 2, True)
                Ts.WriteLine "Sleep 1" : Ts.close
                Act.run(SD & "\Rest1.bat"), 0 , True 
                If Fso.FileExists(SD & "\Rest1.bat") Then
        	        Fso.DeleteFile(SD & "\Rest1.bat")
                End If
            End Function

Open in new window

0
RobSampsonCommented:
However, on another note, you don't need to use any third party sleep program in a HTA.  You can trick a HTA into waiting, by using a Shell command to run
ping 127.0.0.1 -n 1

where the -n 1 is now many seconds (roughly) it will wait.

Regards,

Rob.
          Dim Act   : Set Act = CreateObject("Wscript.Shell")
          Dim Fso   : Set Fso = CreateObject("Scripting.FileSystemObject")
          Dim Uname : Uname = Act.ExpandEnvironmentStrings("%UserName%")
          Dim SD    : SD = Act.ExpandEnvironmentStrings("%Temp%")
          Dim HrCnt	:	HrCnt = 0
          Dim SecCnt   : SecCnt = 1
          Dim MinCnt : MinCnt = 15
          '=== Get the path to the current HTA ===
	    If Mid(document.location, 6, 3) = "///" Then
	    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 9)
	    Else
	    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 6)
	    End If          
          '=======================================
        '/-> HTA DO NOT SUPPORT THE STANDARD SLEEP THAT 
        '/-> WSCRIPT USES THESE ARE MY WORK AROUND 
        '/-> SLEEP 1 SECONDS
        'Const OverwriteExisting = TRUE
        'Set objFSO = CreateObject("Scripting.FileSystemObject")
        'strFile = Left(strHTAPath, InStrRev(strHTAPath, "\")) & "Sleep.exe"
        'objFSO.CopyFile strFile, "C:\windows\system32", OverwriteExisting
 
		HTASleep 3
		
            Sub HTASleep(intSeconds)
				Dim objShell : Set objShell = CreateObject("WScript.Shell")
				objShell.Run "ping 127.0.0.1 -n " & intSeconds, 0, True
            End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LorrecAuthor Commented:
I apologize for the delay in my response. I was out of town. I really appreciate your response. The sleep that you supplied worked better. Thank you very much for the assistance.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.