7 posts in this topic
Morning! I've searched for a definitive answer on the forums on this but can't find one so here goes. I need admin for one of my functions so I'm using #RequireAdmin. I then noticed that regardless of that function being used or admin actually being required, the program pops up and requires admin all of the time.
Is this the way it's designed and is there a way around it so that I can launch my program as normal until admin is required, then and only then prompt the user to run the program as admin?
The only solution I could think of is to produce 2 executables and do something like:
$adminrequired = 1 If($adminrequired = 1) Then Run(Run first executable which includes #RequireAdmin) Else Run(Run second identical executable without #RequireAdmin) EndIf Obviously I'd rather keep to making a single executable rather than having 2 or 3!
After a few weeks of researching and testing, I think I have a good understanding of #RequireAdmin and IsAdmin() for an individual script. They both work in conjunction with each other and ignore whether the current user has administrator rights, or not. In other words, IsAdmin() doesn't test the user, only the declared permission level of the script it is executed in. A separate check is needed to actually confirm the user's admin level. I've included a test script that demonstrates the difference.
Here is my question: When a compiled scripts runs with administrative rights, does a script that it runs inherit those rights? Or is every script on its own? For example,
Parent Script ... (doesn't need admin rights) ... that runs:
Child Script ... that does need admin rights, and obtains them via #RequireAdmin + user's response ... and then runs:
2nd Child Script ...<< does this script execute with admin rights, or not?
If a script does not automatically inherit rights, then is there a way for a parent script that has admin rights to run a child script "with rights", so that running the child script does not result in another prompt for user permission?
Thanks in advance for any help.
;#RequireAdmin ; enable or disable this line to see the difference $AdCheck = IsAdmin() MsgBox(0, "Admin Test", "Admin is " & $AdCheck) $AdCheck = _IsAdministrator() MsgBox(0, "Admin Test", "Admin is " & $AdCheck) Exit Func _IsAdministrator($sUser = @UserName, $sCompName = ".") Local $aCall = DllCall("netapi32.dll", "long", "NetUserGetInfo", "wstr", $sCompName, "wstr", $sUser, "dword", 1, "ptr*", 0) If @error Or $aCall Then Return SetError(1, 0, False) Local $fPrivAdmin = DllStructGetData(DllStructCreate("ptr;ptr;dword;dword;ptr;ptr;dword;ptr", $aCall), 4) = 2 DllCall("netapi32.dll", "long", "NetApiBufferFree", "ptr", $aCall) Return $fPrivAdmin EndFunc
Hello! , I have a little doubt about the "root dir" parameter in FileSelectFolder, The helpfile states:
1. GUI file tree? Isn't that something like this?:
But the dialog for selecting a folder in FileSelectFolder is similar to the dialog of FileOpenDialog
2. "It limits the choice in the root folder"... "" is considered to be @DesktopDir, then why am I able to select folders outside the Desktop folder?
Thanks in Advance, TD
I have a problem with a script when I run it as admin. I am trying to get all the mapped drives from the local pc. This is the script I am using
;~ #RequireAdmin ; This switch is going wrong #include <Array.au3> If isAdmin() then MsgBox(0,"ADMIN","ADMIN") Else MsgBox(0,"NOT ADMIN","NOT ADMIN") EndIf $x = getMappedDrives() _ArrayDisplay($x) Func getMappedDrives() Dim $aDrives $objWMIService = ObjGet("winmgmts:\\" & @LogonDomain & "\root\CIMV2") $sQuery = "Select * From Win32_LogicalDisk Where DriveType = 4" $colItems = $objWMIService.ExecQuery($sQuery, "WQL", 48) If IsObj($colItems) Then For $objItem In $colItems ReDim $aDrives[UBound($aDrives) + 1] $aDrives[UBound($aDrives) - 1] = $objItem.DeviceID $aDrives[UBound($aDrives) - 1] = $objItem.ProviderName Next Return $aDrives Else SetError(-1, -1, -1) EndIf EndFunc When I run it without the '#RequireAdmin' switch it works fine. When I turn on the '#RequireAdmin' switch is gives me an empty array.
This code is part of a bigger project and my project always runs as admin. I dont know why it is doing this, because I am not using #RequireAdmin in the project.
Is there an other better way to get the mapped drives that works for me? Or am I doing something wrong?
I hope someone can help me.
My program starts by asking the user to select or create a directory to copy files to. FileSelectFolder won't let me type in a directory name and have it created. DirCreate doesn't have the GUI interface to allow the user to select a directory. Is there a method to display the File Tree and let the user either select an existing directory OR enter a directory name to add?