Hi I have the following vb script that opens a Program, then clicks an ok button on a pop up message then enters a form with server name, user name and password and then clicks submit. The script works well as i have it running as a scheduled logon script.
However if the user opens another window as this script is running then the script fails. I need o make the script a bit more intelligent by focusing on the correct window. Please help.
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("""C:\Program Files (x86)\SNS EVO ShareBrowser\Client\evo ShareBrowser.exe""")
WScript.Sleep 1000
objShell.SendKeys "{ENTER}"
WScript.Sleep 1000
objShell.SendKeys "abc"
objShell.SendKeys "{TAB}"
objShell.SendKeys "user"
objShell.SendKeys "{TAB}"
objShell.SendKeys "password"
objShell.SendKeys "{ENTER}"
wscript.Quit
Related
I am trying to create a scheduled automation in windows server using vbscript.
Following is the script i am using to automate the Save As dialogue. It is working fine when the server is connected to a display (using RDC) but failing when its scheduled to run headless. Am I missing something here.
Dim ReportPath
Dim oShell
ReportPath = WScript.Arguments(0)
if len(ReportPath) = 0 then
WScript.Quit
end if
Set oShell = CreateObject("WScript.Shell")
oShell.AppActivate("Internet Explorer")
msgbox
WScript.Sleep 2000
oShell.SendKeys "{TAB}"
WScript.Sleep 2000
oShell.SendKeys "{TAB}"
WScript.Sleep 2000
oShell.SendKeys "{Enter}"
WScript.Sleep 2000
oShell.SendKeys ReportPath
WScript.Sleep 2000
oShell.SendKeys "{Enter}"
' Return status of script execution
' WScript.StdOut.Write(returnVal)
Hey Everyone I'm trying to make a simple VBS script and I keep getting Error bject required:'WshShell'
Here is the script
CreateObject("WScript.Shell").Run "C:\DEXIS\DEXsync.exe"
WScript.Sleep 1000
WshShell.SendKeys "{ENTER}"
WScript.Quit()
I have also attached the error message. can someone please help I feel like i'm taking crazy pills
error message
You'll need to set that WshShell variable you are using to a new Wscript.Shell object. Try something like this instead:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "C:\DEXIS\DEXsync.exe"
WScript.Sleep 1000
WshShell.SendKeys "{ENTER}"
WScript.Quit()
I have tried below script but not working. If it run manually, focus is correct. But if it is run through registry it is not taking focus to desired window. U can also suggest me if there is any other way to keep focus on desired window. The window opened through this code is control panel settig window and it is not found under proccess in task magager.
So please give solution.
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "%windir%\system32\control.exe /name
Microsoft.DefaultPrograms /page pageDefaultProgram\pageAdvancedSettings?
pszAppName=Internet%20Explorer"
'Give Default Programs time to load
WScript.Sleep 500
WshShell.AppActivate "Set Program Associations"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys " "
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys " "
Msgbox "Default Browser: Internet Explorer"
WScript.Quit
function Set-IEAsDefaultBrowser {
Add-Type -AssemblyName 'System.Windows.Forms'
Start-Process $env:windir\system32\control.exe -ArgumentList '/name Microsoft.DefaultPrograms /page pageDefaultProgram\pageAdvancedSettings?pszAppName=Internet%20Explorer'
Sleep 2
[System.Windows.Forms.SendKeys]::SendWait("{TAB} {TAB}{TAB} ")
}
Set-IEAsDefaultBrowser
I tried to run this script in windows powershell for set Internet Explorer as default Browser. It's works fine.
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "%windir%\system32\control.exe /name Microsoft.DefaultPrograms /page pageDefaultProgram\pageAdvancedSettings?pszAppName=Internet%20Explorer"
WScript.Sleep 1500
WshShell.SendKeys "{TAB}"
WshShell.SendKeys " "
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys " "
Msgbox "Default Browser: Internet Explorer"
WScript.Quit
it works fine for me.
Iam using vbscripr to open network folder like
Set shell = wscript.CreateObject("Shell.Application")
shell.Open "\\xxxxxxxxxxx\c$"
I don't have access for the drive "yyyy" but i have the UN and PW. how can i use the credentials in vbscript to open the shared folder.
Thanks
The short answer is you cannot do this. The "open" method does not allow you to pass a parameter other than the directory name and the "Shell.Application" object doesn't have a method to do it either.
Source:
Open Method:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb774086(v=vs.85).aspx
List of Methods for Shell.Application:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb774094(v=vs.85).aspx
A possible workaround to this issue would be to relaunch your script via the command prompt and call something like PSEXEC. Something like this:
Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "%COMSPEC% /C psexec -u domain\user -p password -accepteula cscript.exe c:\path\yourscript.vbs"
Set oShell = Nothing
You can download PSEXEC from here:
http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
As awful as it is I use sendkeys (after a little wscript.sleep 2000)...
`...
Set objFolder = objFSO.GetFolder(strShare) 'check access
If Err.Number <> 0 Then
WScript.Sleep 2000
objShell.SendKeys "username" 'username
objShell.SendKeys "{TAB}"
objShell.SendKeys "password" 'password
objShell.SendKeys "{Tab}"
objShell.SendKeys " " 'save credentials
ObjShell.SendKeys "{Tab}"
ObjShell.SendKeys "{ENTER}"
End If
Set ObjShell = Nothing
...`
I was able to opened my gmail but tried to open next url a. Can I do that? How?
Need to fix right one ( WshShell.Exec "C:\test.bat" )
'Script starts here
Set WshShell = WScript.CreateObject("WScript.Shell")
'Wait 1 second (1000 ms)
WScript.Sleep 1000
'Open IE and go to gmail.com (your IExplore.exe file location may be different)
WshShell.Exec "C:\Program Files\Internet Explorer\IEXPLORE.EXE gmail.com"
'Allow time for IE to finish loading (about 15 secs for slow connections/machines)
WScript.Sleep 10000
'Send the login info in the login box
'login (change username to your login name
WshShell.Sendkeys "xxxxxxxxxx"
WScript.Sleep 500
'hit TAB key to move to password field
WshShell.Sendkeys "{TAB}"
WScript.Sleep 500
'Send the password info
'change your password to your login password
WshShell.Sendkeys "xxxxxxxxxxxxx"
WScript.Sleep 500
'Hit 'Enter' key to log-in
WshShell.Sendkeys "{ENTER}"
WScript.Sleep 10000
WshShell.Exec "C:\test.bat"
'Allow time for IE to finish loading (about 15 secs for slow connections/machines)
WScript.Sleep 15000
'Send the login info in the login box
'login (change username to your login name
WshShell.Sendkeys "xxxxxxxxx"
WScript.Sleep 500
'hit TAB key to move to password field
WshShell.Sendkeys "{TAB}"
WScript.Sleep 500
'Send the password info
'change your password to your login password
WshShell.Sendkeys "xxxxxxxx"
WScript.Sleep 500
'Hit 'Enter' key to log-in
WshShell.Sendkeys "{ENTER}"
EDIT: This worked for me.
test.vbs
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Exec "test.bat"
and test.bat
#echo off
start www.yahoo.com