I’m trying to use the ExecuteWithUAC script to run Xcopy as administrator but I keep getting an Expected end of statement 800A0401 error when the script runs. I’m calling it with this:
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "Xcopy "C:\\Program Files (x86)\\Folder Name\\Subfolder Name\\thisfile.txt" "C:\\Users\\username\\Desktop\\target-folder\"", "", "", "runas", 1
I’m not well-versed in VBS so I’m not sure what’s wrong with the ExecuteWithUAC statement.
Now that Xojo has the ability to set the security level for 64 bit builds I would think this workaround has become defunct. If you don’t want the entire application to have elevated privileges simply write a console app that will request admin rights.
Soft Declare Function ShellExecute Lib “Shell32” Alias “ShellExecuteW” (hwnd As Integer, lpOperation As WString, lpFile As WString, lpParameters As WString, lpDirectory As WString, nShowCmd As Int32) As Integer
Dim ok As Integer
ok = ShellExecute(0, “RunAS”, “xcopy”, Chr(34) + file.NativePath + Chr(34) + " " + Chr(34) + folder.NativePath + Chr(34), “”, SW_SHOWNORMAL)
If ok > 32 Then
'everything worked
Else
Select Case ok
Case SE_ERR_ACCESSDENIED
system.DebugLog(“User declined elevation”)
Else
'something else went wrong
End Select
End If[/code]
[quote=390719:@Wayne Golding]Now that Xojo has the ability to set the security level for 64 bit builds I would think this workaround has become defunct. If you don’t want the entire application to have elevated privileges simply write a console app that will request admin rights.