Invoke code failed to run VB Script in Remote desktop connection/VDI/Virtual Machine

Hello Friends,

I am running below vb script using Invoke code activity in ui path, it is running successfully in my local machine, but when i am trying same script to run in my Remote desktop connection/VDI/Virtual Machine it is giving error

Can anyone please help me here

Dim defaultPrinter As String = “Microsoft Print to PDF”
Dim printerQuery As System.Management.ManagementObjectSearcher = New System.Management.ManagementObjectSearcher(“SELECT * FROM Win32_Printer”)
For Each printer As System.Management.ManagementObject In printerQuery.Get()
If printer(“Name”).ToString().Equals(defaultPrinter) Then
printer.InvokeMethod(“SetDefaultPrinter”, Nothing)
Exit For
End If
Next

Getting below Error while running in Remote desktop connection/VDI/Virtual Machine

Hi @Pramod_Mangale ,

Could you maybe try adding the namespace in the imports section and check :

System.Management

image

Yes I added that namespaces and tried but still same issue

Hi @Pramod_Mangale

It looks like the System.Management.ManagementObject namespace is not available in the remote machine. You need to ensure that the .NET Framework version on the remote machine includes the specified namespace.

Can you try running the following command in the cmd & let us know the .Net version:

reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP" /s

Best Regards.

Giving error like system was unable to find specified registry key or value

@Pramod_Mangale

Assuming that you run the cmd with admin privileges, can you please check & confirm if .NET Framework is installed on the remote server or not.

Just to make sure, please try running the following script in the PowerShell:

Get-ChildItem ‘HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP’ -Recurse | Get-ItemProperty -Name Version -EA 0 | Where { $_.PSChildName -Match ‘^(?!S)\p{L}’} | Select PSChildName, Version

Best Regards.

It is showing as v 4.0

@Pramod_Mangale

The recommended .NET version for UiPath is 4.6.1 or later. As long as you have the necessary dependencies installed and configured properly. UiPath also supports earlier versions of .NET, including 4.0.

You can try doing one of these things:

  1. It’s better to upgrade the .Net Version.
  2. Make sure all thé configurations are in place & System.Management.ManagementObject namespace is included.

Hope this helps,
Best Regards.