Automating IE SaveAs Dialogue using vbscript - vbscript

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)

Related

I want to set IE as default browser in windows 10 by vb.net code or any exe. I have used below VBS script. But it is not working

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.

vbscript auto form submition failed

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

How can I make a vbs file which can press arrow keys?

I'm using a voice command software and its still in its beta but really good
The only thing that I find a big problem is navigation in folders and files
So i thought i'll make a vbs script with gets triggered to my voice.
eg: I say left the vbs file which presses left arrow gets pressed
I just need the code for the keystrokes
Once again, move the highlighted folder by pressing arrow keys it what i'm trying to do
Plz somebody help me make a code for this
Thank you
may this will help you to create script
'create shell script object which key stork and move arround the screen
set WshShell = WScript.CreateObject("WScript.Shell")
Set shell = wscript.CreateObject("Shell.Application")
shell.Open "C:\export\script"
WshShell.SpecialFolders("C:\export\script")
WshShell.specialFolders.item(0)
WshShell.SendKeys "{LEFT}"
WScript.Sleep 1000
WshShell.SendKeys "{LEFT}"
WScript.Sleep 1000
WshShell.SendKeys "{RIGHT}"
WScript.Sleep 1000
WshShell.SendKeys "{DOWN}"
WScript.Sleep 1000
WshShell.SendKeys "{DOWN}"
WScript.Sleep 1000
WshShell.SendKeys "{DOWN}"
WScript.Sleep 1000
WshShell.SendKeys "{RIGHT}"
WScript.Sleep 1000
WshShell.SendKeys "{RIGHT}"
WScript.Sleep 1000
WshShell.SendKeys "{RIGHT}"
WScript.Sleep 1000
WshShell.SendKeys "{RIGHT}"
WScript.Sleep 1000
WshShell.SendKeys "{RIGHT}"
WScript.Sleep 1000
WshShell.SendKeys "{LEFT}"
WScript.Sleep 1000
WshShell.SendKeys "{UP}"
WScript.Sleep 1000

Converting script to allow to run as scheduled task

I wrote a VBScript a while back to make a task easier. It works, however it wont run as a scheduled task since it requires a command window to interact with. How would I change the script to allow it to run as a scheduled task?
dim filesys
Set objShell = WScript.CreateObject("WScript.Shell")
set filesys=CreateObject("Scripting.FileSystemObject")
WScript.Sleep 2000
objShell.SendKeys"dsdbutil"
WScript.Sleep 2000
objShell.SendKeys("{Enter}")
WScript.Sleep 2000
objShell.SendKeys("activate instance wap")
WScript.Sleep 2000
objShell.SendKeys("{Enter}")
WScript.Sleep 2000
objShell.SendKeys("ifm")
WScript.Sleep 2000
objShell.SendKeys("{Enter}")
WScript.Sleep 2000
objShell.SendKeys("create full c:\adldsbackup")
WScript.Sleep 2000
objShell.SendKeys("{Enter}")
WScript.Sleep 30000
objShell.SendKeys("quit")
WScript.Sleep 2000
objShell.SendKeys("{Enter}")
WScript.Sleep 2000
objShell.SendKeys("quit")
WScript.Sleep 2000
objShell.SendKeys("{Enter}")
WScript.Sleep 2000
filesys.MoveFile "c:\adldsbackup\adamntds.dit", "\\vash\ibts_ts\Networking\Backups\ADLDS\adamntds_" & DatePart("m",Now()) & "_" & DatePart("d",Now()) & "_" & DatePart("YYYY",Now()) & ".dit"
objShell.SendKeys("exit")
WScript.Sleep 2000
objShell.SendKeys("{Enter}")
I have done something similar, scheduling a vbs. The solution is simple!
Create a batch file to run the vbs file and schedule this batch file. I prefer to use cscript in the batch files:
cscript.exe //nologo <ScriptNameWithFullPath>

Loop IP address substitution in prewritten code

I have code set up to telnet into a switch and tftp the startup-config to a server. This code works perfect if I hard code the IP address into the script.
What I would like to do is pass a list of IP addresses (one after the other) to the script so that I can copy all switch configs on the network. I have included some code below, this is the code I used to create the script. All I want to be able to do is replace the "telnet xx.xx.xx.xx" xx.xx.xx.xx entry with a list of IP addresses.
Thanks in advance!
Here is a copy of code I used:
Option Explicit
On Error Resume Next
Dim WshShell
set WshShell=CreateObject("WScript.Shell")
WshShell.run "cmd.exe"
WScript.Sleep 1000
'Send commands to the window as needed - IP and commands need to be customized
'Step 1 - Telnet to remote IP'
WshShell.SendKeys "telnet xx.xx.xx.xx"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
'Step 2 - Issue Commands with pauses'
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys "5"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
'Step 3 - Exit Command Window
WshShell.SendKeys "exit"
WshShell.SendKeys ("{Enter}")
WScript.Quit
Try this, mostly your code with just a few lines inserted to loop through a list of IP addresses in plain text format. Please let me know if this works for you. Doing it this way opens a new command window for each telnet host and then closes it when its done. It would probably be easy to modify to use the same command window.
Option Explicit
On Error Resume Next
Dim WshShell
Dim objFSO
Dim objInputFile
Dim strIP
set WshShell=CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile("IPFilelist.txt", 1)
Do Until objInputFile.AtEndofStream
strIP = objInputFile.ReadLine
WshShell.run "cmd.exe"
WScript.Sleep 1000
'Send commands to the window as needed - IP and commands need to be customized
'Step 1 - Telnet to remote IP'
WshShell.SendKeys "telnet " & strIP
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
'Step 2 - Issue Commands with pauses'
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys "5"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
'Step 3 - Exit Command Window
WshShell.SendKeys "exit"
WshShell.SendKeys ("{Enter}")
Loop
WScript.Quit

Resources