Skip to content

Commit

Permalink
Local-Client: is Admin required, Part of issue #9
Browse files Browse the repository at this point in the history
  • Loading branch information
joedf committed Jul 5, 2014
1 parent 66a78e4 commit 50702e2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
6 changes: 4 additions & 2 deletions Local-Client/Lib/Util.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ Util_TempDir(outDir="")
return tempDir
}

Util_TempFile()
Util_TempFile(d:="")
{
if ( !StrLen(d) || !FileExist(d) )
d:=A_Temp
Loop
tempName := A_Temp "\~temp" A_TickCount ".tmp"
tempName := d "\~temp" A_TickCount ".tmp"
until !FileExist(tempName)
return tempName
}
Expand Down
4 changes: 2 additions & 2 deletions Local-Client/Package_Installer.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#Include Lib\Settings.ahk
#Include Lib\Arguments.ahk

if (!A_IsAdmin)
ExitApp, % Install.Error_NonAdministrator
;if (!A_IsAdmin)
; ExitApp, % Install.Error_NonAdministrator
if (!args)
ExitApp, % Install.Error_InvalidParameters

Expand Down
40 changes: 32 additions & 8 deletions Local-Client/Package_Lister.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -652,10 +652,16 @@ Install:
; http://support.microsoft.com/kb/830473
;Assuming approximately 50 each file path, should be around 114 packages with "|" delimiters

ecode:=Admin_run("Package_Installer.ahk",Install_packs)
if (ecode=="NOT_ADMIN") {
Gui -Disabled
return
;Changing Install folder will added in the future
if (isAdminRunAs_Needed(Settings.StdLib_Folder)) {
ecode:=Admin_run("Package_Installer.ahk",Install_packs)
if (ecode=="NOT_ADMIN") {
Gui -Disabled
return
}
} else {
Runwait "Package_Installer.ahk" "%Install_packs%",,UseErrorLevel
ecode := ErrorLevel
}

;Update "Installed" list - full-blown list update
Expand Down Expand Up @@ -747,10 +753,16 @@ Remove:
; http://support.microsoft.com/kb/830473
;Assuming approximately 50 each file path, should be around 114 packages with "|" delimiters

ecode:=Admin_run("Package_Remover.ahk",Remove_packs)
if (ecode=="NOT_ADMIN") {
Gui -Disabled
return
;Changing Install folder will added in the future
if (isAdminRunAs_Needed(Settings.StdLib_Folder)) {
ecode:=Admin_run("Package_Remover.ahk",Remove_packs)
if (ecode=="NOT_ADMIN") {
Gui -Disabled
return
}
} else {
Runwait "Package_Remover.ahk" "%Remove_packs%",,UseErrorLevel
ecode := ErrorLevel
}

;full-blown list update
Expand Down Expand Up @@ -820,3 +832,15 @@ Admin_run(program, argument) {
return ErrorLevel
}

isAdminRunAs_Needed(dir) {
if A_IsAdmin
return false
else {
tmpfn := Util_TempFile(dir)
FileAppend,__ASPDM_ADMIN_TEST__,%tmpfn%
if !(e:=ErrorLevel)
FileDelete,%tmpfn%
return e
}
}

4 changes: 2 additions & 2 deletions Local-Client/Package_Remover.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#Include Lib\Settings.ahk
#Include Lib\Arguments.ahk

if (!A_IsAdmin)
ExitApp, % Install.Error_NonAdministrator
;if (!A_IsAdmin)
; ExitApp, % Install.Error_NonAdministrator
if (!args)
ExitApp, % Install.Error_InvalidParameters

Expand Down

0 comments on commit 50702e2

Please sign in to comment.