Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script will not continue - Please Help!!!

Status
Not open for further replies.

haleswd

IS-IT--Management
Jun 9, 2007
1
US
What I want to happen it to open the Adobe Reader, print a PDF, then continue on my merry way. What happened is that the reader would not close after the file printed. I looked on the net and found that this is a common problem with AcroRd32.exe. So, I thought I would try to kill the process after the file printed. The code to kill the process works, but I cant get that far. Once the PDF opens, the script waits and will not continue until Adobe closes. Once I manually close Adobe my "OK" message comes up and the code continues. I can't figure out how to make this work. Can someone please help. This is the code that I am using.

Function printPDF ( exportName )

set wshShell = CreateObject( "WScript.Shell" )

cmdLine = """" & "AcroRd32.exe" & """" & " /t " &_
"""" & exportName & """" & " " &_
"""" & "Kyocera Mita KM-4035" & """" & " " &_
"""" & "Kyocera Mita KM-4035" & """" & " " &_
"""" & "IP_XXX.XX.X.XX" & """"
'msgbox cmdLine
ok = wshShell.Run( cmdLine, 1, true )
set wshShell = Nothing

msgbox "OK"
'kills the adobe process
Dim objWMIService, objProcess, colProcess, strComputer,
strProcessKill
strComputer = "."
strProcessKill = "'AcroRd32.exe'"
Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("Select * from
Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
objProcess.Terminate()
Next

End Function
 
give this a try

ok = wshShell.Run( cmdLine, 1, false )

If that does not do it then try using the Exec method.

Code:
Function printPDF ( exportName )
Dim WshShell, oExec

Set WshShell = CreateObject("WScript.Shell")
        cmdLine = """" & "AcroRd32.exe" & """" & " /t " &_
                        """" & exportName & """" & " " &_
                        """" & "Kyocera Mita KM-4035" & """" & " " &_
                        """" & "Kyocera Mita KM-4035" & """" & " " &_
                        """" & "IP_XXX.XX.X.XX" & """"

Set oExec = WshShell.Exec(cmdLine)
Do While oExec.Status = 0
     WScript.Sleep 100
Loop
 'kills the adobe process
        Dim objWMIService, objProcess, colProcess, strComputer,
strProcessKill
        strComputer = "."
        strProcessKill = "'AcroRd32.exe'"
        Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        Set colProcess = objWMIService.ExecQuery ("Select * from
Win32_Process Where Name = " & strProcessKill )
        For Each objProcess in colProcess
                objProcess.Terminate()
        Next

End Function

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top