2016-12-01 78 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