WMI access denied DCOM issue ?

Mohamed Boulaghlem 0 Reputation points
2024-05-22T22:01:49.4233333+00:00

Hello World,

I have 2 computers A & B.

I am using an application named VisualCron to remote execute a batch file from computer A to computer B where the application sits.

The execution failed with error code:

"Exception in Task: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"

I use the following powershell command from Computer A to test VMI access to Computer B.

Because, it is easier for me to run 1 Powershell cammnd rather than using VisualCron.

$colSettings = Get-WmiObject Win32_OperatingSystem -ComputerName "Computer B"

The error is:

Get-WmiObject : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

Please, note this is NOT a Powershell error but a DCOM or WMI settings error.

Please, note that:

I use the following powershell command from Computer B to test VMI access to Computer A.

$colSettings = Get-WmiObject Win32_OperatingSystem -ComputerName "Computer A"

It does work !!!

Any help, is more than "Welcome"

Thanks.

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,459 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 32,326 Reputation points Microsoft Vendor
    2024-05-23T02:58:26.4133333+00:00

    Hi Mohamed Boulaghlem,

    Thank you for posting in the Q&A forum.

    Please run dcomcnfg from the start menu, then go to Component Services > Computers, right-click My Computer and select Properties. Switch to the COM Security tab and click "Edit Limits" for both Remote Launch and Remote Activation permissions. Make sure all the local permissions are allowed for your user or group. Then go to My Computer > DCOM Config, find "Windows Management and Instrumentation", switch to the Security tab in the properties and ensure all the local permissions are allowed for your user or group.

    Best Regards,

    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.


  2. Plamen Peev 80 Reputation points
    2024-05-31T22:13:31.28+00:00

    Hi @Mohamed Boulaghlem ,

    I assume that you have checked the DCOM configurations on both computers and are making sure that the user you are using to connect to Computer B has admin privileges. If you don't insist on using DCOM, there is a better solution within PowerShell, that uses WinRM protocol, which is the more modern equivalent of DCOM. Get-WmiObject is also outdated command and it uses DCOM to fetch data. There are few different ways to do this, and you just have to enable PowerShell remoting. In a PowerShell terminal, run:

    Enable-PSRemoting
    

    Do this on both computers, the one you connect to and the one you connect from (you can also enable remoting via group policy for a bunch of computers). This will set your computer up to accept and make remote connections. Wait for PowerShell to complete the setup. You might encounter some sort of error, if your network connection profile is set to "Public" for some reason. If so, change it to "Domain" and run the command again. Once done, check if remoting is indeed enabled by running this command:

    Test-WSMan
    

    If the result looks something like this, you are good to go:

    wsmid           : http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd
    ProtocolVersion : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
    ProductVendor   : Microsoft Corporation
    ProductVersion  : OS: 0.0.0 SP: 0.0 Stack: 3.0
    
    

    You only need to do this once (on each computer). Now you can query information directly or run commands remotely. As mentioned, there are few different ways to do either, here is one way to query information (store it in a variable if you'd like):

    Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName "Computer B"
    
    

    Get-CimInstance is the more modern equivalent of Get-WmiObject.

    To establish remote connection, you need to open a session to "Computer B", that you can use continuously, or use Invoke-Command for one-time commands or blocks of code:

    # One-time command to run a bat file on a remote computer
    Invoke-Command -ComputerName "Computer B" -ScriptBlock {Start-Process "C:\mybat.bat"}
    

    Open a persistent session that you can send commands to:

    # Authenticate to the remote computer
    $creds = Get-Credential -UserName "yourusername"
    
    # Open remote session
    $session = New-PSSession -ComputerName "Computer B" -Credential $creds
    
    # Execute command
    Invoke-Command -Session $session {Start-Process "C:\mybat.bat"}
    

    I hope this helps. Please accept this answer if it worked for you.

    0 comments No comments