Fill text in selected field from active window - VBScript, WScript.Shell - shell

I use vbs to upload files into SAP. After clicking "add file" in sap I have the following window on the screen.
I can't control that window using SAP Object so I use WScript.Shell. My question is - how to paste text (file path) to the field "File name:"? I was using wshShell.SendKeys "{TAB}" to jump from one field to another and paste file path, but somehow it doesn't work always. How to get control over that field "File name:" directly and edit it's value?
My code here:
Set wshShell = CreateObject("WScript.Shell")
filePath = "C:\image.png"
wshShell.AppActivate("Storing Files in Documents")
WScript.sleep 200
wshShell.SendKeys "{TAB}"
WScript.sleep 200
wshShell.SendKeys filePath
WScript.sleep 200
wshShell.SendKeys "{ENTER}"
WScript.Quit
Regards

Related

notepad loop created automatically with VBScript

I've created a VBScript to open notepad and write Hello. But it is opening notepad again and again
my code is:
WScript.Sleep 1000
Set WshShell=WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad"
WScript.Sleep 100
WshShell.AppActivate "Notepad"
WScript.Sleep 500
WshShell.SendKeys "Hello"
WScript.Sleep 500
Did you name your script notepad.vbs? please change the name, or
WshShell.Run "notepad.exe"
If no full path specified, windows will try to find the program in the working directory first instead of %PATH%.

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 SAVEAS

I have the following:
set wshshell=createobject("wscript.shell")
wshshell.run """C:\ReportName.pdf"""
This opens the named PDF. What code do I need to save that opened file as, like a SaveAs.. saving it as the same filename?
Thanks
Here is sample code
set wshshell=createobject("wscript.shell")
wshshell.run """C:\ReportName.pdf"""
wscript.sleep 2000 'sleep for 2 seconds to ensure file is open
wshshell.SendKeys "%{F}{A}" 'simulate ALT+F+A to open SaveAs dialog
wscript.sleep 5000 ' sleep for 5 seconds so that the save as dialog is open
wshshell.SendKeys "+{TAB}{ENTER}" 'simulate Shit+Tab so that the tab is moved backed to Choose a diff folder option
wscript.sleep 2000
wshshell.SendKeys "C:\NewFile.PDF{ENTER}"
wscript.sleep 3000
wshshell.SendKeys "%{F}{X}"
It sounds like you want to copy the file or move/rename the file. If so, use FileSystemObject:
Set fso = CreateObject("Scripting.FileSystemObject")
Call fso.CopyFile("C:\ReportName.pdf", "C:\NewReport.pdf")
' or
Call fso.MoveFile("C:\ReportName.pdf", "C:\NewReport.pdf")

Batch File to call VBS which sends keys to application

So I am trying to make a batch file that will download your search history. In doing this I need to use the keys Ctrl+A and Ctrl+S along with typing the name of the file. I just need to find a way to have the code automatically carry out the action of selecting all the history by Ctrl+A and saving it by Ctrl+S and then naming it scarra history.
I have a folder containing 4 files:
Scarra.bat
ChromeHistoryView.exe
Sendkeys.bat
Sendkeys.vbs
Scarra.bat is as follows:
call ChromeHistoryView.exe
call sendkeys.bat
pause
Sendkeys.vbs is as follows:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "^a"
Sendkeys.bat is as follows, this is what I use to try to call the bat:
wscript "sendkeys.vbs"
Add this to Sendkeys.vbs
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "^a"
WScript.Sleep 1000
WshShell.SendKeys "^s"
WScript.Sleep 2000
WshShell.SendKeys "scarra history"
Change Sendkeys.bat to
cscript sendkeys.vbs

How Can i open an cmd prompt and set an path to open an .bat file in Vb Script..?

I need to Automate the Whole Process, So the Cmd Prompt opens and path is set there for the .bat file to open
I have tried with Window Shell Commands to do this .. they work fine .. But i need some other way to open and set the path to run the file ..can anyone help me
Thanks In Advance
Here you go
Set WshShell = wscript.CreateObject("wscript.Shell")
WshShell.Run "cmd"
WScript.Sleep 100
WshShell.AppActivate "C:\Windows\system32\cmd.exe"
WScript.Sleep 100
wshshell.sendkeys "c:\path"
wshshell.sendkeys "{ENTER}"
wshshell.sendkeys "SET PATH=%PATH%;c:\tmp"
wshshell.sendkeys "{ENTER}"
wshshell.sendkeys "batch.cmd"
wshshell.sendkeys "{ENTER}"

Resources