Using VBS Within Xojo

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:

ExecuteWithUAC("Xcopy " + Chr(34) + file.NativePath + Chr(34) + " " + Chr(34) +folder.NativePath + Chr(34),"")

The script itself looks like 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.

Usually means syntax error. Check your .ShellExecute line. I think I see some of the " character where it may not should be.

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.

http://developer.xojo.com/video-windows-build-settings.

This should do the same thing as the script:

[code]'Declares created using https://forum.xojo.com/47389-xojo-ide-reformat-code-script or https://blog./2017/01/22/windows-to-xojo-data-type-conversion/

'See https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153(v=vs.85).aspx for more error messages and flags

'error messages
Const SE_ERR_FNF = 2 'file not found
Const SE_ERR_PNF = 3 'path not found
Const SE_ERR_ACCESSDENIED = 5 'access denied
Const SE_ERR_OOM = 8 'out of memory
Const SE_ERR_SHARE = 26
Const SE_ERR_ASSOCINCOMPLETE = 27
Const SE_ERR_DDETIMEOUT = 28
Const SE_ERR_DDEFAIL = 29
Const SE_ERR_DDEBUSY = 30
Const SE_ERR_NOASSOC = 31
'flags
Const SW_HIDE = 0
Const SW_SHOWNORMAL = 1

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.

http://developer.xojo.com/video-windows-build-settings.[/quote]
I completely missed that one. I’ll have to read the release notes more carefully in the future.