Public Const MOVEFILE_DELAY_UNTIL_REBOOT = &H4
Public Const MOVEFILE_REPLACE_EXISTING = &H1 Public Const MOVEFILE_COPY_ALLOWED = &H2 Public Declare Function MoveFileEx Lib "kernel32" _ Alias "MoveFileExA" (ByVal lpExistingFileName As String, _ ByVal lpNewFileName As String, ByVal dwFlags As Long) As Long Public Sub Main() Dim Hold As Variant, Hold2 As String, Hold3 As String, X As Long Dim Silent As Boolean Hold = Command If Hold = "" Then Goto ErrH 'No Command switches passed If UCase(Left(Hold, 2)) = "-S" Then Silent = True 'Silent install Hold = Right(Hold, (Len(Hold)) - 3) End If 'Parse the switches Hold2 = Trim(Left(Hold, InStr(Hold, " "))) Hold3 = Trim(Right(Hold, (Len(Hold)) - (InStr(Hold, " ")))) X = MoveFileEx(Hold2, Hold3, MOVEFILE_DELAY_UNTIL_REBOOT) If Silent And X = 1 Then Exit Sub If X = 1 Then Msg= "Success, File " & Hold2 & " & _ "will be renamed To " & Hold3 & " at Next reboot" _ , vbApplicationModal, "File Replacement" Else Msg = "Failure, Check syntax. Example, " & _ "-S C:\Winnt\system32\YourFile.dll{Space}" & _ "C:\Winnt\system32\YourFile.OLD" & vbCrLf & _ "-S switch used For silent installations, " & _ "dialog only raised on failure" 'Msg = MsgBox End If Exit Sub ErrH: Msg = "Failure, Check syntax. Example, -S " & _ "C:\Winnt\system32\YourFile.dll{Space}" & _ "C:\Winnt\system32\YourFile.OLD" & _ vbCrLf & "-S switch used For silent installations," & _ "dialog only raised on failure" 'Msg = MsgBox End Sub Inputs: -S for Silent installs [Optional] Sourcefile, DestFile Returns: 1 on success Assumes: typical command line where no dialog is raised would look like this to replace a system dll: Replace.exe -S C:\winnt\Src.dll C:\Winnt\Src.old Replace.exe -S C:\temp\Src.dll C:\Winnt\Src.dll Which can be run from a batch file etc.. |