VBScript Control A - vbscript

I can't figure out how to press Control A (HighLight everything) using VBS, what is it?
Set objShell = WScript.CreateObject("WScript.Shell")
Set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Sleep 500
object.SendKeys "^A"
I get this
Windows Script Host
Script: C:\Users\Shane own\Desktop\A.vbs
Line: 4
Char: 1
Error: Object required: 'object'
Code: 800A01A8
Source: Microsoft VBScript runtime error
OK
Any idea ?

SendKeys is a method of the WshShell class. You created two WshShell objects (objShell and WshShell). Just use one of those objects to call the SendKeys method.
objShell.SendKeys "^A"

Related

Object required:'WshShell'

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()

Restart vb script

I'm trying to make a Vb script that restarts another vbs script the problem is I'm new to this and I don't know how to do this, someone suggested using WshShell I have tried a few websites on how to use it but nothing. Here is what I've got,
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("Test_To_Block.vbs")
Do
If NOT WshShell.Status = 1 then
WScript.Exec("Test_To_Block.vbs")
End If
WScript.Sleep(100)
Loop
Thanks,
Regards,
A Viper
Yes, you can use Exec method to run another VB Script, but you are likely to get a console window flash.
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Exec("CMD /C Test_To_Block.vbs")
Refer to SS64 site to learn about VB Script basics.

invalid window handle with error code : 80070578

I have written below vb script to find an window and bring it to focus
Dim oShell
Set oShell = CreateObject("WScript.Shell")
'bring the window to front
'title must be exactly what you see in the titlebar of the window
oShell.AppActivate WScript.Arguments(0)
I am calling this vb script from java code :
Runtime.getRuntime().exec("cmd.exe /c activeWindow.vbs mywindowname");
Now sometimes it is throwing this below exception :
This is happening randomly.
Syntax for AppActivate :
objShell.AppActivate strApplicationTitle
Below code is working directly by passing title name
Dim oShell
Set oShell = CreateObject("WScript.Shell")
oShell.AppActivate "Calculator"
Or Passing as argument "WScript.Arguments(0)". Save this code in VBS file
Dim oShell
Set oShell = CreateObject("WScript.Shell")
oShell.AppActivate WScript.Arguments(0)
WScript.Quit 0
from cmd type wscript Sample.vbs Calculator
Code is working smoothly and Calculator screen is activating .

How to get keyboard input of "CTRL L" command in VBScript

Is this the correct way of taking input from the keyboard (CTRL+L)?
dim WshShell
set WshShell = CreateObject("WScript.Shell")
wait(2)
WshShell.SendKeys("^108")
wait(2)
or
dim WshShell
set WshShell = CreateObject("WScript.Shell")
wait(2)
WshShell.SendKeys("^l")
wait(2)
The correct way to send a CTRL-L using SendKeys is like this:-
WshShell.SendKeys("^l")
Here is the MSDN reference for the SendKeys method to get more information:
https://msdn.microsoft.com/en-us/library/8c6yea83(v=vs.84).aspx

Open shared folder with different credentials in vbscript

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
...`

Categories

Resources