Need a startup script in windows to send ALT+F11 keys? - windows

We are using a shared desktop on thin clients. By default it comes with windowed screen, but by pressing the Alt + F11 keys it will restore to full screen. So, we want a script to execute at Windows log-on with some delay.

Hopefully a login vbscript will work for you. Either append this to an existing login script or save it as a ".vbs" file. Microsoft has some good tutorials if you are unfamiliar with login scripts.
Set WshShell = CreateObject("Wscript.Shell") 'Create wshell object
WScript.Sleep(5000) 'Lets wait 5 seconds
WshShell.AppActivate "EXACT TITLE OF THE WINDOW YOU WANT" 'EDIT THIS LINE!
'The line above selects the window so we make sure the keystrokes are sent to it
WshShell.SendKeys "%{F11}" 'Send ALT+F11
Wscript.Quit 'Quit the script

Related

Using VBS script SendKeys to activate hotkeys through Task Scheduler

I have Open Broadcaster Software installed and I want to use it to automatically record the desktop at scheduled times. In OBS, I've set up a "start record" hotkey (in this cast ALT 1) and a "stop record" hotkey (ALT 2).
OBS starts with Windows and opens minimized to the task bar.
Pressing the hotkeys keys successfully starts and stops screen recordings regardless of what program is open or focused on.
I want to be able to use Task Scheduler to schedule recordings at specific times throughout the week. Task Scheduler cannot schedule key strokes so I created a start.vbs file and a stop.vbs file. Here's where my problem is, I can't figure out how to get the 'ALT 1' or 'ALT 2' keys to be recognized by OBS.
Here's what I have for my start.vbs:
'Start Recording
Option Explicit
Dim WSHShell, strDesktop
Set WSHShell = WScript.CreateObject("WScript.Shell")
strDesktop = WSHShell.SpecialFolders("Desktop")
WSHShell.AppActivate strDesktop
WSHShell.SendKeys "%1"
WScript.Quit
It seems to run fine, but the keystrokes don't register. Am I doing something wrong, or is there a better way to go about this?
Thanks

How can I automatically cancel the Enter Network Password prompt in Outlook?

I have an unattended PC which does a very simple task : read emails from a POP server and run various tasks based the content of those emails... 24/7/365
The problem is that at least once a week "something" glitches and the processing stalls because Outlook is waiting for a user to confirm their password with the dreaded Enter Network Password dialog.
I have read so many articles in the past 6 months in an attempt to fix the root cause and nothing has worked. There's no WiFi involved and the email server is Google so it should be extremely reliable so I can only suspect that the broadband connection to my ISP is the culprit as I've read that "certain network conditions" can trigger the password prompt.
Yesterday, I gave up on the root cause approach and looked for an automated tool to cancel the annoying dialogue box when it appears. To my surprise, Windows can do this out-of-the-box via Windows Script Host. Here's how:
A. Open your preferred text editor.
B. Copy paste the following VB Script (you can also use JScript if you prefer but I'm not including the syntax here).
Set WshShell = WScript.CreateObject("WScript.Shell")
' Move focus to the network password dialog if it exists (if not, script continues)
If WshShell.AppActivate ("Enter Network Password") = True Then
' Suspend the script for 1/10th second to make sure the dialogue is in focus
WScript.Sleep 100
WshShell.SendKeys "{ESC}"
' Optionally save this event to a log file
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, file
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile("C:\Temp", ForAppending, tristateFalse)
file.Write vbCrLf & Date & " " & Time
file.Close
End If
Set WshShell = Nothing
C. Save the file with a .vbs extension e.g. EscapePrompt.vbs
D. Next, open the Windows Task Scheduler (Click the Windows Start button and type "Task" and you should see Task Schedule appear at the top of the search result list, or just type "Task" from the Windows 8 tile view).
Create a new task that runs the script file above, every day, repeating every 5 minutes, indefinitely:
General tab : give the task a name and then check Run with highest privileges
New Trigger tab : click New and select Daily and then in the Advanced Settings, check Repeat task every: and choose 5 minutes. set the for a duration of: to Indefinitely. Check Enabled
Actions Tab : click New and then Browse to choose the script file you created above.
Conditions tab : Set any conditions as required by your environment.
Settings tab : I don't change anything here but you may want to.
Now, when the Enter Network Password prompt appears, there is a maximum delay of 5 minutes before it is automatically cancelled.
For more information on WScript and in particular, the SendKeys method, check out MSDN :
http://msdn.microsoft.com/en-us/library/8c6yea83(v=vs.84).aspx
You may also be interested in our free VBA examples at:
http://youpresent.biz/category/blog/vba/
Microsoft outlook keeps prompting network password if there registry value and network password mismatches. If you change the password for your account in ISP or Control Panel.Then, configure and login outlook with the new password.Then ,it will not prompt for outlook password again and again.

How to make this WSH script work? (details in message)

This script is supposed to open both Windows shell Status and Properties dialogs of the first found network connection which is enabled or connected. However, only the Properties dialog is opened. The verb for the Status dialog is already correct, which is "Stat&us". The script was tested and will be used under Windows XP Pro SP3 32-Bit. It was tested with a connected 3G dialup and a LAN Loopback. Both have the same problem.
dim a,b,c
set a=createobject("shell.application")
set b=a.namespace(0).parsename("::{7007ACC7-3202-11D1-AAD2-00805FC1270E}").getfolder
for i=0 to (b.items.count-1)
set c=b.items.item(i)
for j=0 to (c.verbs.count-1)
'only process connected/enabled
if (lcase(c.verbs.item(j)) = "disc&onnect") or (lcase(c.verbs.item(j)) = "disa&ble") then
'open status and properties dialogs
c.invokeverb("Stat&us") 'this doesn't work
c.invokeverb("P&roperties") 'this one works
msgbox "Press OK to close all and exit"
wscript.quit
end if
next
next
In Windows XP there is a bug whose effect requires the Status verb to be invoked from within the Explorer process. Since WScript/CScript is not a child of the Explorer process, any attempt to invoke the status verb with prove futile despite the lack of any apparent errors. This bug appears to have been fixed in later versions as the script below is tested and working in Vista x64.
Set objShell = CreateObject("Shell.Application")
Set objShellFolder = objShell.Namespace(0).ParseName("::{7007ACC7-3202-11D1-AAD2-00805FC1270E}").GetFolder
For Each objShellFolderItem in objShellFolder.Items
Set colShellFolderItemVerbs = objShellFolderItem.Verbs
For Each objShellFolderItemVerb in colShellFolderItemVerbs
strVerb = objShellFolderItemVerb.Name
If (strVerb = "C&onnect / Disconnect") Then
objShellFolderItem.InvokeVerb("Properties")
objShellFolderItem.InvokeVerb("Status")
MsgBox "Press OK to close and exit"
WScript.Quit(0)
End If
Next
Next
Option 1
Does that mean that you're out of luck? Not entirely. I have two different suggestions for you. The first uses a little trickery. Status is the default action for any network connection while it is in a connected state. Open up your network connections, right-click the connection your wish to monitor and choose Create Shortcut. You can place the shortcut anywhere you like. By default it will be named something like "Wireless Network Connection - Shortcut.lnk" on your Desktop. Typing that on the command line or via the Run or Exec methods in your script will do exactly what you need. I tried playing around with doing this all via scripting but ran into issues tryint to automate the Create Shortcut verb.
Option 2
A second option is also a bit of a workaround but may work if your 3G connection uses the dialup networking. The command line rundll32.exe rnaui.dll,RnaDial {name of connection to establish} will open the dialog to connect, however, if already connected, it opens the Status dialog for the connection. You could then try a script like this:
Set objShell = CreateObject("Shell.Application")
Set objShellFolder = objShell.Namespace(0).ParseName("::{7007ACC7-3202-11D1-AAD2-00805FC1270E}").GetFolder
For Each objShellFolderItem in objShellFolder.Items
strConnection = objShellFolderItem.Name
strCommandLine = "rundll32.exe rnaui.dll,RnaDial " & Chr(34) & strConnection & Chr(34)
Set colShellFolderItemVerbs = objShellFolderItem.Verbs
For Each objShellFolderItemVerb in colShellFolderItemVerbs
strVerb = objShellFolderItemVerb.Name
If (strVerb = "C&onnect / Disconnect") Then
objShellFolderItem.InvokeVerb("Properties")
CreateObject("WScript.Shell").Run strCommandLine
MsgBox "Press OK to close and exit"
WScript.Quit(0)
End If
Next
Next
Option 3
A final option would be to use WMI to display the information about your network connection. This is a more traditional scripting approach.
In any case, I hope this helps out. Don't forget to change the verbs as required. They do change from one version of Windows to the next.

refresh firefox from .bat file/ command

I am attempting to refresh Firefox whenever a bat file is called. I Dont want an extension. I need to know if there is a command that can be used from within a .bat file to reload the current browser or tab.
I know you can use
start firefox as a command but this simply opens a new firefox instance. I need to refresh the current instance.
I was just messing around and came up with this half-working solution that might help a little. Create a file called something like refresh.vbs and paste this in:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate("Google Chrome")
WScript.Sleep 500
WshShell.SendKeys "{TAB}"
WScript.Sleep 100
WshShell.SendKeys "{F5}"
I could only test it with Chrome. The script activates Chrome, sends a tab, and then sends F5 to refresh. It works when I have Chrome up showing one web page, but not when there are multiple web tabs open (because AppActivate activates the Window, but does not give focus to anything).
Maybe it works better with Firefox. There's probably some way to enumerate the tabs in a browser and activate it in vbs, but I don't know it.
If you spawn the browser within the vbs (see WshShell.Run, and the example in the SendKeys documentation), you can get the process number and send messages directly to that Window instead of relying on the app title.
You can invoke the .vbs from within a batch file if you need to:
#echo off
refresh.vbs
On Error Resume Next
Set objExplorer = CreateObject("InternetExplorer.Application")
objExplorer.Navigate "http://www.microsoft.com/technet/scriptcenter"
objExplorer.Visible = 1
Wscript.Sleep 5000
Set objDoc = objExplorer.Document
Do While True
Wscript.Sleep 30000
objDoc.Location.Reload(True)
If Err <> 0 Then
Wscript.Quit
End If
Loop

How to set focus on file dialog opened in Vbscript

Our Team is automating tests/test data preparation in QTP and we do the scripting in VBScript.
In several tests the tester who runs the script need to supply an MS-Excel file with the indata. We use UserAccounts.CommonDialog for this and it works great. Except for one litle problem, when we run this from QTP the file dialog does not get focus. It's opened in the background and it's easy for the tester that runs the script to miss it and waste time waiting for the dialog.
How do we give the file dialog focus?
Code Example:
Set ObjFSO = CreateObject("UserAccounts.CommonDialog")
ObjFSO.Filter = "MS-Excel Spreadsheets|*.xls|All Files|*.*"
while ObjFSO.ShowOpen = false
msgbox "Script Error: Please select a file!"
wend
msgbox "You selected the file: " & ObjFSO.FileName
My guess is that since the dialog is modal, the ShowOpen method doesn't return the execution control back to the script until the dialog is closed. So there's no way to interact with the dialog as part of your test script.
As a workaround, you could spawn a parallel script that would wait for the dialog and activate it. But I guess QTP cannot run two scripts in parallel, so you'll probably need an external shell script (written in VBScript / JScript / PowerShell / etc).
Edit: Try the following:
Create an external VBScript file (.vbs) with the following contents:
Set oShell = CreateObject("WScript.Shell")
While Not oShell.AppActivate("Open")
WScript.Sleep 500
Wend
This script calls WshShell.AppActivate to activate a window whose title contains Open (replace it with the actual dialog title). If there's no such widnow at the monent, it retries the attempt after 0.5 sec (you can increase the delay if you wish).
Launch this script from your QTP test before opening the dialog. (Use SystemUtil.Run or something like this.)
I'm not sure, but I think this should do the trick.
Did you try recording a click on the dialog - so that QTP will click on it to set focus before proceeding?

Resources