A1VBCode Forums

How to copy file with Administrator's right


http://www.a1vbcode.com/vbforums/Topic31680.aspx

By allgames71 - 10/16/2012

Hello everybody ,

When I write VB6 program , I need to copy files to C:\Windows. But always fail as I don't have Administrator's Right. I found a program on web but also fail :

Option Explicit

Private Sub Command1_Click()
    Const ssfDESKTOP = 0
    Const ssfWINDOWS = 36
    Dim OriginalFile As String
    Dim CopiedFile As String
    Dim F As Integer
   
    With CreateObject("Shell.Application")
        With .NameSpace(ssfDESKTOP).Self
            OriginalFile = .Path & "\test-orig.txt"
        End With
        With .NameSpace(ssfWINDOWS).Self
            CopiedFile = .Path & "\test-copy.txt"
        End With
    End With
    F = FreeFile(0)
    Open OriginalFile For Output As #F
    Print #F, "Testing!"
    Close #F
    DoEvents
    FileCopy OriginalFile, CopiedFile
    Kill OriginalFile
    MsgBox FileLen(CopiedFile)
End Sub

Please help me. Thanks a lot

By Mark - 10/17/2012

In newer OS, security prevents you copying to the windows directory. You can't change this in your program. You need to make sure when you run the app you run it with an adminstrator account.