So it seems as though the following bit of code works with Windows XP, but does NOT work with Windows 7:
Dim objFileSys
Set objFileSys = CreateObject("Scripting.FileSystemObject")
If objShell.AppActivate("Query Express") Then
Else
objShell.run chr(34) & "I:\SQL-Queries\QueryExpress\QueryExpress.exe" & chr(34),1,False
End If
Basically, it checks to see if the window is already open. If it is NOT open, it opens it.
Pretty simple, eh? Well, this bit of code does not work as scripted in Windows 7. Can someone clue me in as to how to update it to work?
Thanks!
Related
I have been trying to learn Web Scraping using VBScript since VBA for Outlook does not work like VBA for Excel
So I am trying to display a message box to see whether or not my script is getting to specific points. I can display the first message box but not the second one. I understand that it is due to the line wscript.quit but I need that line otherwise I can't open IE.
Msgbox ("hello"),0,("title")
set Shell = createobject("wscript.shell")
Shell.Run "google.ca"
wscript.quit
DIM IE
Set IE = CreateObject("IExplorer.exe")
Msgbox ("hello"),0,("title")
All help is appreciated, Thanks.
i have a simple vbscript that perform "Ctrl 2", the sendkey work perfectly in my PC, when i try it in another PC it's not working at all.
here is the code:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "^2"
tried to add parentheses and also i changed the UAC the the lowest but till not working.
i would like to add that the other PC is in French language if that can be the problem.
thank guys
I'm having problems with the following VBScript.
I'm trying to send keystrokes to a web browser window, but nothing happens.
The first two lines in the following script works fine, but the third line with the SendKeys command, doesn't do anything.
Set objShell = CreateObject("WScript.Shell")
objShell.Run "http://someurl.com", 1
objShell.SendKeys "Some Text"
I've tried to run the script on two different Win 8.1 machines. On Win 8.1 Pro it works, but on Win 8.1 not-Pro it won't work. Is there any setting somewhere in Windows that needs to be set or anything other that can help me?
Update
New code tried (added sleep and running browser explicit), but still no luck
Set ObjShell = WScript.CreateObject("WScript.Shell")
objShell.Run """C:\Program Files\Internet Explorer\iexplore.exe""http://someurl.com/"
WScript.Sleep 5000
objShell.SendKeys "Some Text"
While its admittedly not a great programming technique, place a Sleep command after your objShell.Run line (as shown below) to give the OS some time to "catch up" and actually run the URL, activate the browser window to give it focus (you have to take note of the title in the Browser window and use that title exactly), because I have seen the browser window lose focus in some cases and then text cannot be piped into it, and finally it sends the text. Your mileage may vary, and you might even have to increase the sleep time in order to be successful. I've had to sleep up to 30 seconds, in some cases. Especially where, for whatever reason, the web page was slow to render - due to network latency, slow OS, etc.. I haven't faced this problem on Windows 8.1 because I haven't tried it on that platform. I don't think this has anything to do with the OS version; I have faced this same problem with SendKeys on other Windows OS versions where I've had to use the Sleep function like this. The SendKeys method has known limitations, and as it runs outside of the browser you have to wait for certain actions to complete before you can have it do more actions.
Set ObjShell = WScript.CreateObject("WScript.Shell")
objShell.Run "http://someurl.com", 1
WScript.Sleep 20000
objShell.appactivate("Welcome to SOMEURL.COM! - Mozilla Firefox")
WScript.Sleep 700
objShell.SendKeys "Some Text"
Also, you might try replacing line 2 in the above to the following, to see if you have better luck. In the example below, Firefox is the default web browser. Change the path accordingly to the browser of your choice:
objShell.Run("""C:\Program Files\Mozilla Firefox\firefox.exe""http://someurl.com")
I searched the web and found a vb script to tile windows on the desktop. But I want to tile specific windows or apps. For example, if I open three images in Paint and one Excel file, I only want to show Paint apps tiling on the desktop.
I changed my code as suggested by Dai, however all windows are tiling.
There is another question. In my code I filtered "Untitled -Paint". However if I opened image, there would be "filename -Paint" . How can I get them?
Here is the code so far:
Option Explicit
Dim oWS, oShell
Set oShell = CreateObject("Shell.Application")
Set oWS=CreateObject("WScript.Shell")
Dim App
App="Untitled - Paint"
If oWS.AppActivate(App) then
else
WScript.Sleep 500
oWS.SendKeys "% x"
End if
oShell.TileVertically
WScript.Quit
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.