title: Executing VBS Code in VBA with admin rights
body: <p>how are you doing?</p>
  
  <p>I want to execute VBS code in a VBA environment, in this case I am working in the VB editor in MS Excel 2010. Sadly I have no idea how to convert the VBS code so VBA is able to execute it.</p>
  
  <p>To give an idea about what I am working on: I want to execute a VBS command prompt that needs Admin rights. This prompt will restart a process on a different PC in the network. The VBS code works perfectly fine, when executed via cmd. The reason I want to use VBA is that there are a lot PC's in the network and I want to use a loop to execute the VBS code for every PC.</p>
  
  <p>OK, here is the VBS code:</p>
  
  <pre><code>strComputer = "Computername"
  Set objShell = CreateObject("Wscript.Shell")
  Set objWMIService = GetObject("winmgmts:\\" &amp; strComputer &amp; "\root\cimv2:Win32_Process")
  intReturn = objWMIService.Create("c:\Program Files (x86)\Symantec\Symantec Endpoint  Protection\12.1.1000.157.105\Bin64\smc.exe -stop", Null, Null, intProcessID)
  Wscript.Sleep 10000
  intReturn2 = objWMIService.Create("c:\Program Files (x86)\Symantec\Symantec Endpoint Protection\12.1.1000.157.105\Bin64\smc.exe -start", Null, Null, intProcessID)
  </code></pre>
  
  <p>The question is now, how do I get this code sample in to my VBA environment? I know how to execute the VBS file itself through VBA, but that is not enough, because I need a variable. Also the admin rights are up to the question. </p>
  
  <p>OK, here is an update, I have now this code in my VBA, but I am not able to get things started, I also tried to implement the runas admin:</p>
  
  <pre><code>Sub run_vbs_script()
  Dim strComputer As String
  'Dim WshShell
  Dim objShell
  Dim objWMIService
  Dim dDate As Date
  
  strComputer = "IEDBR8D60CR"
  
  Set objShell = CreateObject("Wscript.Shell")
  
  RunasStruser = "runas /user:Username Domain\domain name"
  
  objShell.Run RunasStruser, 0
  
  objShell.SendKeys "password"
  
  Set objWMIService = GetObject("winmgmts:\\" &amp; strComputer &amp; "\root\cimv2:Win32_Process")
  
  intReturn = objWMIService.Create("c:\Program Files (x86)\Symantec\Symantec Endpoint  Protection\12.1.1000.157.105\Bin64\smc.exe -stop", Null, Null, intProcessID)
  
  dDate = DateAdd("s", 10, DateTime.Now)
  Do While dDate &gt; DateTime.Now
      DoEvents
  Loop
  
  intReturn2 = objWMIService.Create("c:\Program Files (x86)\Symantec\Symantec Endpoint Protection\12.1.1000.157.105\Bin64\smc.exe -start", Null, Null, intProcessID)
  
  Set objShell = Nothing
  Set objWMIService = Nothing
  
  End Sub
  </code></pre>