1

Trying to execute:

Set objWshShell = CreateObject("WScript.Shell")

Getting error:

[![PS C:\Windows\system32> Set objWshShell = WScript.CreateObject("WScript.Shell")
Set-Variable : A positional parameter cannot be found that accepts argument 
'WScript.CreateObject'.
At line:1 char:1
+ Set objWshShell = WScript.CreateObject("WScript.Shell")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) \[Set-Variable\], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetVaria 
   bleCommand][1]][1]

This however works:

$WSH = New-Object -Com WScript.Shell
$WSH.Run("explorer.exe""")

I am trying to run this which requires the shell and context of it :

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run """%PROGRAMFILES(x86)%\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe"""

WScript.Sleep 3000

WshShell.AppActivate "Cisco AnyConnect Secure Mobility Client"

WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{ENTER}"

WScript.Sleep 5000

WshShell.SendKeys "PASSWORD"
WshShell.SendKeys "{ENTER}"
LotPings
  • 1,015
  • 7
  • 12
  • 4
    Double check the [RADA's answer](https://superuser.com/a/885506/376602) linked already in your question: _Save this script as FILENAME._**vbs**. This is VBScript, not PowerShell! – JosefZ May 16 '17 at 07:53

1 Answers1

1

Looks to me like you're just running into trouble translating the VBS code into powershell. There are some subtle syntactic differences such as:

$WSH = New-Object -Com wscript.shell

$WSH.run("executable")
$WSH.AppActivate("name")
$WSH.SendKeys("key to send")

You'll use powershell's sleep though:

Start-Sleep -Seconds 5
Colyn1337
  • 2,397
  • 2
  • 23
  • 40