2016-12-01 77 views
0

我想自动打开Gmail并使用凭证登录到它。在浏览器中打开Gmail并自动登录

对于这一点,我已经写了其中包含下面的代码名为.ps1脚本:

set WshShell = WScript.CreateObject("WScript.Shell") 
call WshShell.Run("https://www.gmail.com", 1, false) 

WScript.Sleep 2000 
WshShell.SendKeys "prudhvi" 
WScript.Sleep 1000 
WshShell.SendKeys "{TAB}" 
WScript.Sleep 1000 
WshShell.SendKeys "prudhvi9" 
WshShell.SendKeys "{TAB}" 
WScript.Sleep 1000 
WshShell.SendKeys "{ENTER}" 
WScript.Quit() 

这引发以下错误:

At C:\Users\admin\Desktop\sample.ps1:2 char:46 
+ call WshShell.Run("https://www.gmail.com", 1, false) 
+            ~ 
Missing expression after ','. 
At C:\Users\admin\Desktop\sample.ps1:2 char:47 
+ call WshShell.Run("https://www.gmail.com", 1, false) 
+            ~~~~~ 
Unexpected token 'false' in expression or statement. 
At C:\Users\admin\Desktop\sample.ps1:2 char:46 
+ call WshShell.Run("https://www.gmail.com", 1, false) 
+            ~ 
Missing closing ')' in expression. 
At C:\Users\admin\Desktop\sample.ps1:2 char:52 
+ call WshShell.Run("https://www.gmail.com", 1, false) 
+             ~ 
Unexpected token ')' in expression or statement. 
At C:\Users\admin\Desktop\sample.ps1:13 char:14 
+ WScript.Quit() 
+    ~ 
An expression was expected after '('. 
+ CategoryInfo   : ParserError: (:) [], ParseException 
+ FullyQualifiedErrorId : MissingExpressionAfterToken 

什么可能的错误是什么?

回答

1

错误是Powershell(.ps1)和VBScript(.vbs)之间的混淆。示例中的代码是VBScript,因此必须使用cscript c:\path\to\script.vbs(文本模式)或wscript c:\path\to\script.vbs(GUI模式)脚本主机运行。

+0

谢谢。这工作 – prudhvi

+0

prudhvi9是不是你的密码,我希望;-) – SBF