Jump to content

WMI Object not working with #RequireAdmin


Recommended Posts

Hi all,

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[0][2]
    $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][2]
            $aDrives[UBound($aDrives) - 1][0] = $objItem.DeviceID
            $aDrives[UBound($aDrives) - 1][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.

Regards,

lrstndm

Edited by lrstndm
Link to comment
Share on other sites

When using #RequireAdmin a new process with elevated permissions and a new environment is being started. This process does not inherit mapped drives from the starting process.
Search the forum. There has been some discussion on this subject lately.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

You are sure you removed or commented the "#Requiredmin" line? And then compiled the script again?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Yes I am sure. But the project I am compiling is much bigger. I read something about some features (from windows) that will ask the program for administrator permissions if you use them. Is that possible? How can I overrule it then?

Link to comment
Share on other sites

You could insert

MsgBox(0, "", "The current user has administrator privileges: " & IsAdmin())

to make sure about the used privileges.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...