bat script to open a PDF when a user logs in

is it possible to have a script open a PDF when a user logs in?
IT GuyAsked:
Who is Participating?
Rob WilliamsCommented:
The problem with providing the application and path is it can vary from machine to machine, 32 vs 64 bit machines, and Acrobat versions.  Though you cannot force it to open in full screen a batch file deployed within the user's profile or group policy only needs to contain:

rem Check if read
If Exist C:\Temp\Counter.txt GoTo END
Echo pdf read >C:\Temp\Counter.txt
rem Open document

(the local directory, Temp in this case, must exist or create it with the batch file.  You cannot write to the root of the drive)

You can also display messages at logon using Group Policy.  They are however limited to about 500 characters
Dan CraciunIT ConsultantCommented:
Why don't you simply put a shortcut to that PDF in the user's startup folder?

Try this route :
Windows\Start Menu\Programs\Startup\

bat file (saved in the location above)

Acrord32.exe /A "zoom=100" "filename.pdf"
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

IT GuyAuthor Commented:
its an awesome idea Dan. is it possible to get a script to create shortcuts of that PDF.

Here is what i am trying to accomplish

we are upgrading users to the new Windows 8.1 update, after they have updated and logs back into their PC we have a PDF that shows all the new features, we would like that PDF to automatically open once per user
IT GuyAuthor Commented:
looking into your solution becraig
If the Acrobat version is consistent then you can simply

create your bat file something like this:

cd %ProgramFiles%\path-to-acrobat
Acrord32.exe /A "zoom=100" "filename.pdf"

Save the above file and push it out to:
Windows\Start Menu\Programs\Startup\ on the clients in question.

If this works for you , be sure to split the points with Dan, since he seemed to be going down the same path before I commented.
IT GuyAuthor Commented:
this is what my script looks like but it does not work

Acrord32.exe /A "zoom=100" "\\myserver\Share\Win8PDF\win8.pdf"
Dan CraciunIT ConsultantCommented:
@becraig: Nope, I wasn't going down that path.

You're assuming that everyone has Adobe Reader installed. That may or may not be the case.

What I was suggesting was more low tech: create a shortcut to the UNC path of the pdf, then push that shortcut/lnk file to the startup path of the computers.

This should trigger the default pdf reader to open that pdf, without the need to check what is that and where it's installed.

Joe Winograd, Fellow&MVEDeveloperCommented:
Could be because <Acrord32.exe> is not in the path. There are numerous ways to solve this. One way is to fully qualify it in the script, such as:

"c:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" /A "zoom=100" "\\myserver\Share\Win8PDF\win8.pdf"
Joe Winograd, Fellow&MVEDeveloperCommented:
Oops...I submitted my comment before seeing Dan's post...his idea is better. But there's also an issue that no one has addressed yet. You said, "...we would like that PDF to automatically open once per user". I take that to mean you want each user to see it just once...not on every login. That means you need some logic to determine if each user has already seen it. Regards, Joe
I have a tested powershell solution that work, also deletes all the files afterwards.

Are you open to using powershell as a part of your process ?
David Johnson, CD, MVPOwnerCommented:
This only shows the item 1 time per user on a particular machine.. Most of the others will show it every logon
if ((test-path $env:localappdata\pdfviewed) -eq $false) {
    start-process \\dc01\newstuff\download.pdf
    New-Item $env:localappdata\pdfviewed -type directory

Open in new window

So here is my solution as well

5 parts
1) you create the powershell script on a central share
2) Copy a bat file to all users folder to run on startup
This copies the ps1 file locally and then runs it
3) Create a lnk to the pdf on the network then sleep (while programs continue to load.)
4) Load the pdf file
5) Delete the local ps1 and the bat file and the lnk file

So you can actually copy the bat files to the home directory of all users
bat file:
copy \\sharelocation\script.ps1 c:\temp
powershell.exe -ExecutionPolicy Bypass  -File c:\temp\crshrt.ps1

Then save the below ps script on a server share
PS Script:
$varpath = Get-Childitem env:APPDATA | %{ $_.Value }
$dirpath = $varpath + "Microsoft\Windows\Start Menu\Programs\Startup"
$batfile = $varpath + "\Microsoft\Windows\Start Menu\Programs\Startup\starter.bat"
$pdffile = "\\uncpath\pdffile.pdf"
start-sleep 40 
invoke-item $pdffile 
start-sleep 40 
Remove-Item $MyINvocation.InvocationName
Remove-Item $batfile

Open in new window

There's a runonce hive key in the Windows registry.  These are cleared once the program has run once.

If you need to set it up for each new user, you could load the HKUSERS hive from the Default User profile and add the program that you wish to run.  This will work for all new users to the system.  If you want it to work on each existing user, you'll need to load each existing user's hive.

If you only have one user per system, you could just edit the runonce entry in the HKLM hive and have it only run once per system.

IT GuyAuthor Commented:
so sorry guys i was out for an emergency.

What if we create some kind of touch file? is that possible
IT GuyAuthor Commented:
this is the script i ended up using after dropping the touch file on the PC

setlocal EnableDelayedExpansion

REM Set the installed flag location
SET FLAG=!TEMP!\win8.1u1.installed.flag.txt

REM Test if installed flag exists
) ELSE (

del /F !FLAG!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.