Code:
dim currentSettings as P dim targetDateWindow as n = 30 registry.load_settings("init",currentSettings) if .not. variable_exists("currentSettings.date.date_window") then currentSettings.date.date_window = 0 end if if currentSettings.date.date_window <> targetDateWindow then dim updateSettings as p updateSettings.date.date_window = targetDateWindow registry.save_settings("init",updateSettings) msgbox("Relaunch required","Database needs to relaunch to update settings. Relaunching NOW.",UI_ATTENTION_SYMBOL+UI_OK) relaunchDatabase(a5.Get_Name(),"",.f.,.t.) end end if
Code:
FUNCTION relaunchDatabase AS C (adbFile as c, exeOnStart as C = "",asAdmin = .f., closeNow as L = .f.,no_check as L = .f. ) 'easiest way to pass in code for exeOnStart is to surround it with %code% deliminater e.g. ' OnStart = <<%code% ' msgbox("title","this is a test")%code% ' 'This would launch a message box as soon as the user logs in (or even if the login fails) dim alphaAnywhere as C alphaAnywhere = a5.Get_Exe_Path() +"\\" + a5.Get_Exe_Name() 'CMD version: powershell -command "& {start-process -filePath """C:\Program Files (x86)\a5V12\alpha5.exe""" -verb runAs -argumentList """\\epudb1\a5_edit\a5_epu.adb"""}" dim params as C params = "-filePath " + TDQ(alphaAnywhere) if asAdmin then params = params + " -verb runAs" End if params = params + " -argumentList" '-argumentList is a powershell array, end each element with a comma dim argList as C 'surround each powershell array element with single quote, separate each element with comma argList = " @(" ' start powershell array. need a space between -argumentList and @ argList = argList + "'" + TDQ(adbFile) + "'" argList = argList + " ,'-nosplash'" if asAdmin Then argList = argList + " ,'-title=" + TDQ("Database Name (Elevated)") + "'" Else argList = argList + " ,'-title=" + TDQ("Database Name") + "'" end if IF exeOnStart <> "" then argList = argList + " ,'-command=" + stritran(alltrim(exeOnStart),"\"",chr(92) + "\"" + chr(92) + "\"" + chr(92) + "\"") + "'" 'must escape any double quote and triplicate to pass into sys_shell() end if argList = argList + ")" 'end powershell array params = params + argList dim cmdStr as C cmdStr = "-command "+ chr(92) + "\"" + "& {start-process " + params + "}" + chr(92) + "\"" dim shared cliStr as C cliStr = "powershell.exe -executionPolicy bypass " + cmdStr dim Code as C code = "sys_shell(\"" + cliStr + "\")" 'trace.WriteLn(code) on_application_exit(code) if closeNow then a5.close(no_check) end if END FUNCTION Function TDQ as C (string as c) 'just a convenient way to surround a string with escaped quotes in triplicate 'also keeps strings looking a bit cleaner and easier to read TDQ = chr(92) + "\"" + chr(92) + "\"" + chr(92) + "\"" + string + chr(92) + "\"" + chr(92) + "\"" + chr(92) + "\"" End Function
Leave a comment: