Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. System Admin
  4. Programmatically using WMI to remotely run apps which access locally mapped drives relative to the remote machine.

Programmatically using WMI to remotely run apps which access locally mapped drives relative to the remote machine.

Scheduled Pinned Locked Moved System Admin
toolstutorialcomsysadminhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NullStream
    wrote on last edited by
    #1

    The following code in theory should pop up a CMD window and show me the contents of a mapped drive mapped locally on a remote machine called "remote_workstation_a". I'm running this script from my workstation and when I do the CMD window pop's up and tells me access denied. I tried logging in on the local machine as the domain administrator then run this script again with no luck. I can't seem to figure out programmatically how to connect to a remote machine with a specific username and password yet still access the Win32_Process WMI object. strComputer = "remote_workstation_a" Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2:Win32_Process") Error = objWMIService.Create("cmd.exe /K dir w:\", null, null, intProcessID) If Error = 0 Then Wscript.Echo "was started with a process ID of " _ & intProcessID & "." Else Wscript.Echo " could not be started due to error " & _ Error & "." End If I know this is possible because there are tools that already exist (psexec and beyondexec naming two) that can do this. As an example with PSEXEC (from sysinternals.com): psexec \\remote_workstation_a -u MY_PDC_DOMAIN\Adminstrator -p PASSWORD -i cmd.exe /K dir w:\ This works so I know for certain this is possible I can't can't find anything clear in the WMI docs on MSDN to show me how to do this. Based on this I just need to encode the username and password of the account I would like to impersonate on the remote machine somehow (through the 'GetObject("winmgmts:" ...' call?). The obvious answer is to just use PSEXEC but I need to run this a whole lot of times (which would open up MANY MANY processes) and PSEXEC's source is not exactly available. Any hints or suggestions would be greatly appriciated. The whole point of me attempting this is to make the tech guy's life a bit easier when pushing updates to the compute farm. And while I'm at it why is all the WMI documentation so vague on almost everything? I'm eventually going to need to map a printer to each machine on the network and I'd love to do it though WMI but it's going to be a BIG BIG chore without some insight. Thanks, Sean

    V 1 Reply Last reply
    0
    • N NullStream

      The following code in theory should pop up a CMD window and show me the contents of a mapped drive mapped locally on a remote machine called "remote_workstation_a". I'm running this script from my workstation and when I do the CMD window pop's up and tells me access denied. I tried logging in on the local machine as the domain administrator then run this script again with no luck. I can't seem to figure out programmatically how to connect to a remote machine with a specific username and password yet still access the Win32_Process WMI object. strComputer = "remote_workstation_a" Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2:Win32_Process") Error = objWMIService.Create("cmd.exe /K dir w:\", null, null, intProcessID) If Error = 0 Then Wscript.Echo "was started with a process ID of " _ & intProcessID & "." Else Wscript.Echo " could not be started due to error " & _ Error & "." End If I know this is possible because there are tools that already exist (psexec and beyondexec naming two) that can do this. As an example with PSEXEC (from sysinternals.com): psexec \\remote_workstation_a -u MY_PDC_DOMAIN\Adminstrator -p PASSWORD -i cmd.exe /K dir w:\ This works so I know for certain this is possible I can't can't find anything clear in the WMI docs on MSDN to show me how to do this. Based on this I just need to encode the username and password of the account I would like to impersonate on the remote machine somehow (through the 'GetObject("winmgmts:" ...' call?). The obvious answer is to just use PSEXEC but I need to run this a whole lot of times (which would open up MANY MANY processes) and PSEXEC's source is not exactly available. Any hints or suggestions would be greatly appriciated. The whole point of me attempting this is to make the tech guy's life a bit easier when pushing updates to the compute farm. And while I'm at it why is all the WMI documentation so vague on almost everything? I'm eventually going to need to map a printer to each machine on the network and I'd love to do it though WMI but it's going to be a BIG BIG chore without some insight. Thanks, Sean

      V Offline
      V Offline
      Venet
      wrote on last edited by
      #2

      How about this: Set objLocator = CreateObject("WbemScripting.SWbemLocator") Set objWMIService = objLocator.ConnectServer(strComputer, "root\cimv2", Uname, Pwd) :) Regards, Venet. Donec eris felix, multos numerabis amicos.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups