CharlieG
CharlieG

Reputation: 3

Open a pdf file on a network drive with vbscript

Hi I am trying to create a script that opens a variety of internet pages and programs through a vbscript, but I am having difficulty opening pdf files that are located on a network drive, ive tried a bunch of commands but cannot get the files to open at all so any help would be appreciated :)

Set IE = CreateObject("InternetExplorer.Application") 
set WshShell = WScript.CreateObject("WScript.Shell")  
IE.Navigate "https://websiteaddress.com
IE.Visible = True 
Wscript.Sleep 3000 
WshShell.SendKeys "text"
WshShell.SendKeys "{ENTER}"
Wscript.Sleep 3000
WshShell.SendKeys "text"
WshShell.Sendkeys "{TAB}"
WshShell.Sendkeys "{TAB}"
WshShell.Sendkeys "text"
WshShell.SendKeys "{ENTER}"
Wscript.Sleep 3000
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{ENTER}"
Wscript.Sleep 3000
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{ENTER}"
Wscript.Sleep 3000
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{ENTER}"
Wscript.Sleep 3000
WshShell.SendKeys "%{TAB}"
WshShell.SendKeys "%{F4}"
Wscript.Sleep 3000
WshShell.SendKeys "%{TAB}"
IE.Navigate "https://websiteaddress.com"
IE.Visible = True 
Wscript.Sleep 3000
WshShell.SendKeys "text"
WshShell.SendKeys "{ENTER}"
Wscript.Sleep 3000
WshShell.Run "H:\Shortcuts /k dir *.*"
WshShell.Run "Notepad.exe"
Wscript.Sleep 3000
WshShell.Run "calc.exe"

I am very new to vbscripting but I have tried the following two lines and neither work;

WshShell.Run "G:\pathtofile\thepdf.pdf"

WshShell.Run "NET USE G: \\server\share\thepdf.pdf"

Upvotes: 0

Views: 15913

Answers (1)

peter
peter

Reputation: 42192

It surprises me you are new to vbscript and yet choose that language to do such things, vbscript is not very suited for this kind of work and the days of vbscript are counted, ruby would be a better choice if you want to use a program language and if you just want to automate things you would beter use http://www.autohotkey.com/

Anyway, like this it should work in vbscript. The "" represents a single " within a string.

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run """g:\path with spaces\thepdf.pdf"""

Upvotes: 2

Related Questions