tags:

views:

535

answers:

2

I have the following line of code to create object to access to a remote server before I associate it with user name, password and process:

$process = [WMIClass]"\\remoteServer\ROOT\cimv2:Win32_Process"

I tried this on two PCs, one is OK without any errors, but another one I am going to run has an exception:

Cannot convert value "\\remoteServer\ROOT\cimv2:Win32_Process" to type "System.Manage
  ment.ManagementClass". Error: "Access is denied. (Exception from HRESULT: 0x800
  70005 (E_ACCESSDENIED))"

The remoteServer is the same one. Not sure what I have to set on local PC or remote PC to make this work? On both client PCs, the user names are all member of Administrators.

+2  A: 

Is there some reason you don't want to use psexec?

http://technet.microsoft.com/en-us/sysinternals/bb545027.aspx

No Refunds No Returns
I tried PSExec. It woks for running bat on remote PC. However, it does not let me run PS scripts on remote PC. PS is hanging on remote process but not script exec.
David.Chu.ca
+1  A: 

Have you considered looking into PowerShell remoting? If your running PowerShell 2.0 I'd recommend that you take a look at it. Once you have set up remoting you'll be able to execute commands on the remote server using the Invoke-Command:

Invoke-Command -ComputerName {serverName} –ScriptBlock { commands }

The ScriptBlock can contain any powershell commands so you will be able to start processes on the remote machine with this mechanism. To enable remoting you'll need to use the Enable-PSRemoting cmdlet and you can get details of this at http://blogs.msdn.com/powershell/archive/2009/04/30/enable-psremoting.aspx and http://technet.microsoft.com/en-us/library/dd819498.aspx

Alan
Unfortunately, I cannot install PS 2.0 since it requires SP 3 which is not available through out network permission.
David.Chu.ca
Have you seen this http://forums.asp.net/p/1225290/2198163.aspx
Alan